@@ -21,34 +21,32 @@ def get_learning_hours_and_daily_sessions_query():
21
21
"""
22
22
23
23
@staticmethod
24
- def get_engagement_count_query ():
24
+ def get_engagement_count_query (query_filters ):
25
25
"""
26
26
Get the query to fetch the total number of engagements for an enterprise customer.
27
27
"""
28
- return """
28
+ return f """
29
29
SELECT count(*)
30
30
FROM fact_enrollment_engagement_day_admin_dash
31
- WHERE enterprise_customer_uuid=%(enterprise_customer_uuid)s AND
32
- activity_date BETWEEN %(start_date)s AND %(end_date)s;
31
+ WHERE { query_filters .to_sql ()} ;
33
32
"""
34
33
35
34
@staticmethod
36
- def get_all_engagement_query ():
35
+ def get_all_engagement_query (query_filters ):
37
36
"""
38
37
Get the query to fetch all engagement data.
39
38
"""
40
- return """
39
+ return f """
41
40
SELECT
42
41
email, course_title, course_subject, enroll_type, activity_date,
43
42
learning_time_seconds/3600 as learning_time_hours
44
43
FROM fact_enrollment_engagement_day_admin_dash
45
- WHERE enterprise_customer_uuid=%(enterprise_customer_uuid)s AND
46
- activity_date BETWEEN %(start_date)s AND %(end_date)s
44
+ WHERE { query_filters .to_sql ()}
47
45
ORDER BY activity_date DESC LIMIT %(limit)s OFFSET %(offset)s;
48
46
"""
49
47
50
48
@staticmethod
51
- def get_top_courses_by_engagement_query (record_count = 10 ):
49
+ def get_top_courses_by_engagement_query (query_filters , record_count = 10 ):
52
50
"""
53
51
Get the query to fetch the learning time in hours by courses.
54
52
@@ -69,8 +67,7 @@ def get_top_courses_by_engagement_query(record_count=10):
69
67
(learning_time_seconds / 60.0 / 60.0) AS learning_time_hours,
70
68
activity_date
71
69
FROM fact_enrollment_engagement_day_admin_dash
72
- WHERE enterprise_customer_uuid=%(enterprise_customer_uuid)s AND
73
- activity_date BETWEEN %(start_date)s AND %(end_date)s
70
+ WHERE { query_filters .to_sql ()}
74
71
),
75
72
top_10_courses AS (
76
73
SELECT
@@ -94,7 +91,7 @@ def get_top_courses_by_engagement_query(record_count=10):
94
91
"""
95
92
96
93
@staticmethod
97
- def get_top_subjects_by_engagement_query (record_count = 10 ):
94
+ def get_top_subjects_by_engagement_query (query_filters , record_count = 10 ):
98
95
"""
99
96
Get the query to fetch the learning time in hours by subjects.
100
97
@@ -114,8 +111,7 @@ def get_top_subjects_by_engagement_query(record_count=10):
114
111
(learning_time_seconds / 60.0 / 60.0) AS learning_time_hours,
115
112
activity_date
116
113
FROM fact_enrollment_engagement_day_admin_dash
117
- WHERE enterprise_customer_uuid=%(enterprise_customer_uuid)s AND
118
- activity_date BETWEEN %(start_date)s AND %(end_date)s
114
+ WHERE { query_filters .to_sql ()}
119
115
),
120
116
top_10_subjects AS (
121
117
SELECT
@@ -138,7 +134,7 @@ def get_top_subjects_by_engagement_query(record_count=10):
138
134
"""
139
135
140
136
@staticmethod
141
- def get_engagement_time_series_data_query ():
137
+ def get_engagement_time_series_data_query (query_filters ):
142
138
"""
143
139
Get the query to fetch the completion time series data.
144
140
@@ -147,11 +143,10 @@ def get_engagement_time_series_data_query():
147
143
Returns:
148
144
(str): Query to fetch the completion time series data.
149
145
"""
150
- return """
146
+ return f """
151
147
SELECT activity_date, enroll_type, SUM(learning_time_seconds)/3600 as learning_time_hours
152
148
FROM fact_enrollment_engagement_day_admin_dash
153
- WHERE enterprise_customer_uuid=%(enterprise_customer_uuid)s AND
154
- activity_date BETWEEN %(start_date)s AND %(end_date)s
149
+ WHERE { query_filters .to_sql ()}
155
150
GROUP BY activity_date, enroll_type
156
151
ORDER BY activity_date;
157
152
"""
0 commit comments