Skip to content

Commit a463025

Browse files
authored
add chatbot data to org reporting table (#1748)
* add chatbot data to org reporting table
1 parent 9bbb7fe commit a463025

File tree

2 files changed

+79
-13
lines changed

2 files changed

+79
-13
lines changed

src/ol_dbt/models/reporting/_reporting__models.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,15 @@ models:
354354
- name: courserun_readable_id
355355
description: string, unique string to identify a course run on the corresponding
356356
platform.
357-
- name: certificate_created_date
358-
description: date, date that the course run certificate was created
359-
- name: certificate_count
360-
description: int, will be 1 if a certificate was created otherwise it will be
361-
0
357+
- name: user_email
358+
description: string, user email that user registered on the corresponding platform
362359
- name: organization
363360
description: str, organization that lists the course. e.g. MITx, MITxT, null
361+
- name: activity_date
362+
description: date, date the user engaged in an activity
363+
- name: chatbot_used_count
364+
description: int, a count of 1 if the user used a chatbot during the course run
365+
otherwise 0
366+
- name: certificate_count
367+
description: int, a count of 1 if the user earned a certificate that day otherwise
368+
0

src/ol_dbt/models/reporting/organization_administration_report.sql

Lines changed: 69 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ with enrollment_detail as (
66
select * from {{ ref('int__combined__user_course_roles') }}
77
)
88

9+
, chatbot_events as (
10+
select * from {{ ref('tfact_chatbot_events') }}
11+
)
12+
13+
, user as (
14+
select * from {{ ref('dim_user') }}
15+
)
16+
917
, org_field as (
1018
select
1119
distinct courserun_readable_id
@@ -23,14 +31,67 @@ with enrollment_detail as (
2331
from enrollment_detail
2432
)
2533

34+
, enroll_data as (
35+
select
36+
distinct platform
37+
, course_title
38+
, courserun_readable_id
39+
, user_email
40+
from enrollment_detail
41+
)
42+
43+
, chatbot_data as (
44+
select
45+
distinct user.email as user_email
46+
, cast(chatbot_events.event_timestamp as date) as activity_date
47+
, chatbot_events.courserun_readable_id
48+
, 1 as chatbot_used_count
49+
, 0 as certificate_count
50+
from chatbot_events
51+
inner join user
52+
on chatbot_events.user_fk = user.user_pk
53+
54+
union
55+
56+
select
57+
distinct user_email
58+
, certificate_created_date as activity_date
59+
, courserun_readable_id
60+
, 0 as chatbot_used_count
61+
, 1 as certificate_count
62+
from certificate_org_data
63+
where certificate_created_date is not null
64+
65+
)
66+
67+
, activity_day_data as (
68+
select
69+
user_email
70+
, activity_date
71+
, courserun_readable_id
72+
, max(chatbot_used_count) as chatbot_used_count
73+
, max(certificate_count) as certificate_count
74+
from chatbot_data
75+
group by
76+
user_email
77+
, activity_date
78+
, courserun_readable_id
79+
)
80+
81+
2682
select
27-
certificate_org_data.platform
28-
, certificate_org_data.course_title
29-
, certificate_org_data.courserun_readable_id
30-
, certificate_org_data.certificate_created_date
31-
, certificate_org_data.user_email
32-
, case when certificate_org_data.certificate_created_date is not null then 1 else 0 end as certificate_count
83+
enroll_data.platform
84+
, enroll_data.course_title
85+
, enroll_data.courserun_readable_id
86+
, enroll_data.user_email
3387
, org_field.organization
34-
from certificate_org_data
88+
, activity_day_data.activity_date
89+
, activity_day_data.chatbot_used_count
90+
, activity_day_data.certificate_count
91+
from enroll_data
3592
left join org_field
36-
on certificate_org_data.courserun_readable_id = org_field.courserun_readable_id
93+
on enroll_data.courserun_readable_id = org_field.courserun_readable_id
94+
left join activity_day_data
95+
on
96+
enroll_data.user_email = activity_day_data.user_email
97+
and enroll_data.courserun_readable_id = activity_day_data.courserun_readable_id

0 commit comments

Comments
 (0)