Skip to content

Commit

Permalink
feat!: Upgrade schema to use new Ralph 4.0 event column
Browse files Browse the repository at this point in the history
Ralph 3.x had both a JSON "event" column and an
"event_str" text representation of the same data. 4.x
drops the JSON column since it is unsupported and going
to be removed from ClickHouse, and renames the text
column to "event".
  • Loading branch information
bmtcril committed Jan 17, 2024
1 parent 051ca59 commit 87c6bc7
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 27 deletions.
1 change: 0 additions & 1 deletion models/base/sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ sources:
- name: event_id
- name: emission_time
- name: event
- name: event_str

- name: event_sink
database: "{{ env_var('ASPECTS_EVENT_SINK_DATABASE', 'event_sink')}}"
Expand Down
22 changes: 11 additions & 11 deletions models/base/xapi_events_all_parsed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,34 @@

SELECT
event_id as event_id,
JSON_VALUE(event_str, '$.verb.id') as verb_id,
JSON_VALUE(event, '$.verb.id') as verb_id,
COALESCE(
NULLIF(JSON_VALUE(event_str, '$.actor.account.name'), ''),
NULLIF(JSON_VALUE(event_str, '$.actor.mbox'), ''),
JSON_VALUE(event_str, '$.actor.mbox_sha1sum')
NULLIF(JSON_VALUE(event, '$.actor.account.name'), ''),
NULLIF(JSON_VALUE(event, '$.actor.mbox'), ''),
JSON_VALUE(event, '$.actor.mbox_sha1sum')
) as actor_id,
JSON_VALUE(event_str, '$.object.id') as object_id,
JSON_VALUE(event, '$.object.id') as object_id,
-- If the contextActivities parent is a course, use that. It can be a "course"
-- type, or a "cmi.interaction" type for multiple question problem submissions.
-- Otherwise use the object id for the course id.
multiIf(
-- If the contextActivities parent is a course, use that
JSON_VALUE(
event_str,
event,
'$.context.contextActivities.parent[0].definition.type'
) = 'http://adlnet.gov/expapi/activities/course',
JSON_VALUE(event_str, '$.context.contextActivities.parent[0].id'),
JSON_VALUE(event, '$.context.contextActivities.parent[0].id'),
-- Else if the contextActivities parent is a GroupActivity, it's a multi
-- question problem and we use the grouping id
JSON_VALUE(
event_str,
event,
'$.context.contextActivities.parent[0].objectType'
) in ('Activity', 'GroupActivity'),
JSON_VALUE(event_str, '$.context.contextActivities.grouping[0].id'),
JSON_VALUE(event, '$.context.contextActivities.grouping[0].id'),
-- Otherwise use the object id
JSON_VALUE(event_str, '$.object.id')
JSON_VALUE(event, '$.object.id')
) as course_id,
coalesce(get_org_from_course_url(course_id), '') as org,
emission_time as emission_time,
event_str as event_str
event as event
FROM {{ source('xapi', 'xapi_events_all') }}
2 changes: 1 addition & 1 deletion models/completion/completion_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ SELECT
splitByString('/', course_id)[-1] AS course_key,
org,
verb_id,
JSON_VALUE(event_str, '$.result.extensions."https://w3id.org/xapi/cmi5/result/extensions/progress"') AS progress_percent
JSON_VALUE(event, '$.result.extensions."https://w3id.org/xapi/cmi5/result/extensions/progress"') AS progress_percent
FROM {{ ref('xapi_events_all_parsed') }}
WHERE verb_id = 'http://adlnet.gov/expapi/verbs/progressed'
2 changes: 1 addition & 1 deletion models/enrollment/enrollment_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SELECT
splitByString('/', course_id)[-1] AS course_key,
org,
verb_id,
JSON_VALUE(event_str, '$.object.definition.extensions."https://w3id.org/xapi/acrossx/extensions/type"') AS enrollment_mode
JSON_VALUE(event, '$.object.definition.extensions."https://w3id.org/xapi/acrossx/extensions/type"') AS enrollment_mode
FROM {{ ref('xapi_events_all_parsed') }}
WHERE verb_id IN (
'http://adlnet.gov/expapi/verbs/registered',
Expand Down
2 changes: 1 addition & 1 deletion models/forum/forum_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ SELECT
actor_id,
verb_id
FROM {{ ref('xapi_events_all_parsed') }}
WHERE JSON_VALUE(event_str, '$.object.definition.type') = 'http://id.tincanapi.com/activitytype/discussion'
WHERE JSON_VALUE(event, '$.object.definition.type') = 'http://id.tincanapi.com/activitytype/discussion'
2 changes: 1 addition & 1 deletion models/grading/grading_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ SELECT
splitByString('/', course_id)[-1] AS course_key,
org,
verb_id,
JSONExtractFloat(event_str, 'result', 'score', 'scaled') AS scaled_score
JSONExtractFloat(event, 'result', 'score', 'scaled') AS scaled_score
FROM {{ ref('xapi_events_all_parsed') }}
WHERE verb_id IN ('http://id.tincanapi.com/verb/earned', 'https://w3id.org/xapi/acrossx/verbs/evaluated')
6 changes: 3 additions & 3 deletions models/navigation/navigation_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SELECT
splitByString('/', course_id)[-1] AS course_key,
org,
verb_id,
JSONExtractString(event_str, 'object', 'definition', 'type') AS object_type,
JSONExtractString(event, 'object', 'definition', 'type') AS object_type,
-- clicking a link and selecting a module outline have no starting-position field
if (
object_type in (
Expand All @@ -23,12 +23,12 @@ SELECT
),
0,
JSONExtractInt(
event_str,
event,
'context', 'extensions', 'http://id.tincanapi.com/extension/starting-position'
)
) AS starting_position,
JSONExtractString(
event_str,
event,
'context', 'extensions', 'http://id.tincanapi.com/extension/ending-point'
) AS ending_point
FROM
Expand Down
10 changes: 5 additions & 5 deletions models/problems/problem_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ SELECT
splitByString('/', course_id)[-1] AS course_key,
org,
verb_id,
JSON_VALUE(event_str, '$.result.response') as responses,
JSON_VALUE(event_str, '$.result.score.scaled') as scaled_score,
JSON_VALUE(event, '$.result.response') as responses,
JSON_VALUE(event, '$.result.score.scaled') as scaled_score,
if(
verb_id = 'https://w3id.org/xapi/acrossx/verbs/evaluated',
cast(JSON_VALUE(event_str, '$.result.success') as Bool),
cast(JSON_VALUE(event, '$.result.success') as Bool),
false
) as success,
JSON_VALUE(event_str, '$.object.definition.interactionType') as interaction_type,
JSON_VALUE(event, '$.object.definition.interactionType') as interaction_type,
if(
verb_id = 'https://w3id.org/xapi/acrossx/verbs/evaluated',
cast(JSON_VALUE(event_str, '$.object.definition.extensions."http://id.tincanapi.com/extension/attempt-id"') as Int16),
cast(JSON_VALUE(event, '$.object.definition.extensions."http://id.tincanapi.com/extension/attempt-id"') as Int16),
0
) as attempts
FROM
Expand Down
2 changes: 1 addition & 1 deletion models/video/video_playback_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ SELECT
splitByString('/', course_id)[-1] AS course_key,
org,
verb_id,
ceil(CAST(coalesce(nullIf(JSON_VALUE(event_str, '$.result.extensions."https://w3id.org/xapi/video/extensions/time"'), ''), nullIf(JSON_VALUE(event_str, '$.result.extensions."https://w3id.org/xapi/video/extensions/time-from"'), ''), '0.0'), 'Decimal32(2)')) AS video_position
ceil(CAST(coalesce(nullIf(JSON_VALUE(event, '$.result.extensions."https://w3id.org/xapi/video/extensions/time"'), ''), nullIf(JSON_VALUE(event, '$.result.extensions."https://w3id.org/xapi/video/extensions/time-from"'), ''), '0.0'), 'Decimal32(2)')) AS video_position
FROM {{ ref('xapi_events_all_parsed') }}
WHERE (verb_id IN ('http://adlnet.gov/expapi/verbs/completed', 'http://adlnet.gov/expapi/verbs/initialized', 'http://adlnet.gov/expapi/verbs/terminated', 'https://w3id.org/xapi/video/verbs/paused', 'https://w3id.org/xapi/video/verbs/played', 'https://w3id.org/xapi/video/verbs/seeked')) AND (object_id LIKE '%video+block%')
4 changes: 2 additions & 2 deletions models/video/video_transcript_events.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ SELECT
splitByString('/', course_id)[-1] AS course_key,
splitByString('/xblock/', object_id)[2] as video_id,
actor_id,
JSONExtractBool(event_str, 'result','extensions','https://w3id.org/xapi/video/extensions/cc-enabled') as cc_enabled
JSONExtractBool(event, 'result','extensions','https://w3id.org/xapi/video/extensions/cc-enabled') as cc_enabled
FROM {{ ref('xapi_events_all_parsed') }}
WHERE
verb_id IN ('http://adlnet.gov/expapi/verbs/interacted')
AND JSONHas(event_str, 'result', 'extensions', 'https://w3id.org/xapi/video/extensions/cc-enabled')
AND JSONHas(event, 'result', 'extensions', 'https://w3id.org/xapi/video/extensions/cc-enabled')

0 comments on commit 87c6bc7

Please sign in to comment.