|
5 | 5 | // and it wouldn’t reflect when the data was actually dumped from canvas.
|
6 | 6 | // More info on UDP's batch-ingest DAG process can be found here: https://resources.unizin.org/display/UDP/Batch-ingest+application
|
7 | 7 | '''
|
8 |
| - select 'canvasdatadate' as pkey, min(dag_run) as pvalue from report.publish_info pi2 |
| 8 | + SELECT * FROM EXTERNAL_QUERY("us.context_store", "select 'canvasdatadate' as pkey, min(dag_run) as pvalue from report.publish_info pi2"); |
9 | 9 | ''',
|
10 | 10 | "user" :
|
11 | 11 | '''
|
12 | 12 | select
|
13 | 13 | (
|
14 |
| - cast(%(canvas_data_id_increment)s as bigint) |
| 14 | + cast(@canvas_data_id_increment as bigint) |
15 | 15 | +
|
16 | 16 | cast(p2.lms_ext_id as bigint)
|
17 | 17 | ) as user_id,
|
18 | 18 | case
|
19 |
| - when pe.email_address is not null then lower(split_part(pe.email_address , '@', 1)) |
| 19 | + WHEN pe.email_address IS NOT NULL THEN LOWER(REGEXP_EXTRACT(pe.email_address, r'^([^@]+)')) |
20 | 20 | else p2.sis_ext_id end as sis_name,
|
21 | 21 | cast(co.lms_int_id as bigint) as course_id,
|
22 | 22 | cg.le_current_score as current_grade,
|
|
27 | 27 | when cse.role = 'Teacher' then 'TeacherEnrollment'
|
28 | 28 | else '' end
|
29 | 29 | as enrollment_type
|
30 |
| - from entity.course_section_enrollment cse |
31 |
| - left join entity.course_section cs |
| 30 | + from context_store_entity.course_section_enrollment cse |
| 31 | + left join context_store_entity.course_section cs |
32 | 32 | on cse.course_section_id = cs.course_section_id
|
33 |
| - left join keymap.course_offering co |
| 33 | + left join context_store_keymap.course_offering co |
34 | 34 | on cs.le_current_course_offering_id = co.id
|
35 |
| - left join entity.person p |
| 35 | + left join context_store_entity.person p |
36 | 36 | on cse.person_id = p.person_id
|
37 |
| - left join keymap.person p2 |
| 37 | + left join context_store_keymap.person p2 |
38 | 38 | on p.person_id = p2.id
|
39 |
| - left join entity.person_email pe |
| 39 | + left join context_store_entity.person_email pe |
40 | 40 | on p.person_id = pe.person_id
|
41 |
| - left join entity.course_grade cg |
| 41 | + left join context_store_entity.course_grade cg |
42 | 42 | on cse.course_section_id = cg.course_section_id and cse.person_id = cg.person_id
|
43 | 43 | where
|
44 |
| - co.lms_int_id = ANY(%(course_ids)s) |
45 |
| - and cse.role = ANY(ARRAY['Student', 'Teacher', 'TeachingAssistant']::text[]) |
| 44 | + co.lms_int_id IN UNNEST(@course_ids) |
| 45 | + and cse.role IN UNNEST(ARRAY['Student', 'Teacher', 'TeachingAssistant']) |
46 | 46 | and cse.role_status = 'Enrolled'
|
47 | 47 | and cse.enrollment_status = 'Active'
|
48 | 48 | order by user_id
|
|
51 | 51 | '''
|
52 | 52 | with assignment_details as (
|
53 | 53 | select la.due_date, title, la.course_offering_id, la.learner_activity_id, la.points_possible, la.learner_activity_group_id
|
54 |
| - from entity.learner_activity la, keymap.course_offering co |
| 54 | + from context_store_entity.learner_activity la, context_store_keymap.course_offering co |
55 | 55 | where
|
56 | 56 | la.visibility = 'everyone'
|
57 | 57 | and la.status = 'published'
|
58 | 58 | and la.course_offering_id = co.id
|
59 |
| - and co.lms_int_id = ANY(%(course_ids)s) |
| 59 | + and co.lms_int_id IN UNNEST(@course_ids) |
60 | 60 | ), assignment_grp as (
|
61 | 61 | select lg.*
|
62 |
| - from entity.learner_activity_group lg, keymap.course_offering co |
| 62 | + from context_store_entity.learner_activity_group lg, context_store_keymap.course_offering co |
63 | 63 | where
|
64 | 64 | lg.status = 'available'
|
65 | 65 | and lg.course_offering_id = co.id
|
66 |
| - and co.lms_int_id = ANY(%(course_ids)s) |
| 66 | + and co.lms_int_id IN UNNEST(@course_ids) |
67 | 67 | ), assign_more as (
|
68 | 68 | select distinct(a.learner_activity_group_id), da.group_points
|
69 | 69 | from assignment_details a
|
70 |
| - join ( |
71 |
| - select learner_activity_group_id, sum(points_possible) as group_points |
72 |
| - from assignment_details |
73 |
| - group by learner_activity_group_id |
74 |
| - ) as da |
75 |
| - on a.learner_activity_group_id = da.learner_activity_group_id |
| 70 | + JOIN UNNEST(( |
| 71 | + SELECT ARRAY_AGG(STRUCT(learner_activity_group_id, group_points)) |
| 72 | + FROM ( |
| 73 | + select learner_activity_group_id, sum(points_possible) as group_points |
| 74 | + from assignment_details |
| 75 | + group by learner_activity_group_id |
| 76 | + ) |
| 77 | + )) as da |
| 78 | + on a.learner_activity_group_id = da.learner_activity_group_id |
76 | 79 | ), grp_full as (
|
77 | 80 | select a.group_points, b.learner_activity_group_id
|
78 | 81 | from assign_more a
|
|
81 | 84 | ), assign_rules as (
|
82 | 85 | select distinct ad.learner_activity_group_id, agr.drop_lowest_amount as drop_lowest, agr.drop_highest_amount as drop_highest
|
83 | 86 | from grp_full ad
|
84 |
| - join entity.learner_activity_group agr |
| 87 | + join context_store_entity.learner_activity_group agr |
85 | 88 | on ad.learner_activity_group_id = agr.learner_activity_group_id
|
86 | 89 | ), assignment_grp_points as (
|
87 | 90 | select ag.*, am.group_points AS group_points, ar.drop_lowest as drop_lowest, ar.drop_highest as drop_highest
|
|
90 | 93 | join assign_rules ar on ag.learner_activity_group_id = ar.learner_activity_group_id
|
91 | 94 | )
|
92 | 95 | select
|
93 |
| - cast(lag_km.lms_int_id as BIGINT) as id, |
94 |
| - cast(co_km.lms_int_id as BIGINT) as course_id, |
95 |
| - cast(agp.group_weight as float) as weight, |
| 96 | + cast(lag_km.lms_int_id as INT64) as id, |
| 97 | + cast(co_km.lms_int_id as INT64) as course_id, |
| 98 | + cast(agp.group_weight as FLOAT64) as weight, |
96 | 99 | agp.name as name,
|
97 | 100 | agp.group_points as group_points,
|
98 | 101 | agp.drop_lowest as drop_lowest,
|
99 | 102 | agp.drop_highest as drop_highest
|
100 | 103 | from assignment_grp_points agp,
|
101 |
| - keymap.course_offering co_km, |
102 |
| - keymap.learner_activity_group lag_km |
| 104 | + context_store_keymap.course_offering co_km, |
| 105 | + context_store_keymap.learner_activity_group lag_km |
103 | 106 | where agp.course_offering_id = co_km.id
|
104 | 107 | and agp.learner_activity_group_id = lag_km.id
|
105 | 108 | order by id
|
|
109 | 112 | with assignment_info as
|
110 | 113 | (
|
111 | 114 | select
|
112 |
| - la.due_date AT TIME ZONE 'UTC' as due_date, |
| 115 | + la.due_date as due_date, |
113 | 116 | la.title as name,
|
114 |
| - cast(co.lms_int_id as BIGINT) as course_id, |
115 |
| - cast(la_km.lms_int_id as BIGINT) as id, |
| 117 | + cast(co.lms_int_id as INT64) as course_id, |
| 118 | + cast(la_km.lms_int_id as INT64) as id, |
116 | 119 | la.points_possible as points_possible,
|
117 |
| - cast(lag_km.lms_int_id as BIGINT) as assignment_group_id |
| 120 | + cast(lag_km.lms_int_id as INT64) as assignment_group_id |
118 | 121 | from
|
119 |
| - entity.learner_activity la, |
120 |
| - keymap.course_offering co, |
121 |
| - keymap.learner_activity la_km, |
122 |
| - keymap.learner_activity_group lag_km |
| 122 | + context_store_entity.learner_activity la, |
| 123 | + context_store_keymap.course_offering co, |
| 124 | + context_store_keymap.learner_activity la_km, |
| 125 | + context_store_keymap.learner_activity_group lag_km |
123 | 126 | where
|
124 | 127 | la.visibility = 'everyone'
|
125 | 128 | and la.status = 'published'
|
126 | 129 | and la.course_offering_id = co.id
|
127 |
| - and co.lms_int_id = ANY(%(course_ids)s) |
| 130 | + and co.lms_int_id IN UNNEST(@course_ids) |
128 | 131 | and la.learner_activity_id = la_km.id
|
129 | 132 | and la.learner_activity_group_id = lag_km.id
|
130 | 133 | )
|
|
142 | 145 | cast(0 as boolean)
|
143 | 146 | end as consider_weight
|
144 | 147 | from
|
145 |
| - entity.learner_activity_group lag, |
146 |
| - keymap.course_offering co_km |
| 148 | + context_store_entity.learner_activity_group lag, |
| 149 | + context_store_keymap.course_offering co_km |
147 | 150 | where
|
148 | 151 | lag.course_offering_id = co_km.id
|
149 |
| - and co_km.lms_int_id = ANY(%(course_ids)s) |
| 152 | + and co_km.lms_int_id IN UNNEST(@course_ids) |
150 | 153 | group by co_km.lms_int_id
|
151 | 154 | ''',
|
152 | 155 | "term":
|
153 | 156 | '''
|
154 | 157 | select
|
155 |
| - cast(ka.lms_int_id as BIGINT) as id, |
156 |
| - cast(ka.lms_ext_id as BIGINT) as canvas_id, |
| 158 | + cast(ka.lms_int_id as INT64) as id, |
| 159 | + cast(ka.lms_ext_id as INT64) as canvas_id, |
157 | 160 | a.name as name,
|
158 |
| - a.le_term_begin_date::timestamp without time zone as date_start, |
159 |
| - a.le_term_end_date::timestamp without time zone as date_end |
| 161 | + a.le_term_begin_date as date_start, |
| 162 | + a.le_term_end_date as date_end |
160 | 163 | from
|
161 |
| - entity.academic_term as a |
162 |
| - left join keymap.academic_term as ka on ka.id = a.academic_term_id |
| 164 | + context_store_entity.academic_term as a |
| 165 | + left join context_store_keymap.academic_term as ka on ka.id = a.academic_term_id |
163 | 166 | where
|
164 | 167 | ka.lms_ext_id is not null
|
165 | 168 | order by id
|
|
170 | 173 | "course":
|
171 | 174 | '''
|
172 | 175 | SELECT
|
173 |
| - cast(co2.lms_int_id as BIGINT) as id, |
174 |
| - cast(co2.lms_ext_id as BIGINT) as canvas_id, |
175 |
| - cast(at2.lms_int_id as BIGINT) as enrollment_term_id, |
| 176 | + cast(co2.lms_int_id as INT64) as id, |
| 177 | + cast(co2.lms_ext_id as INT64) as canvas_id, |
| 178 | + cast(at2.lms_int_id as INT64) as enrollment_term_id, |
176 | 179 | co.le_code as name,
|
177 |
| - co.le_start_date::timestamp without time zone as start_at, |
178 |
| - co.le_end_date::timestamp without time zone as conclude_at |
| 180 | + TIMESTAMP(co.le_start_date) as start_at, |
| 181 | + TIMESTAMP(co.le_end_date) as conclude_at |
179 | 182 | FROM
|
180 |
| - entity.course_offering co |
181 |
| - LEFT OUTER JOIN entity.academic_term at1 on (co.academic_term_id = at1.academic_term_id), |
182 |
| - keymap.course_offering co2, |
183 |
| - keymap.academic_term at2 |
184 |
| - WHERE co2.lms_int_id = ANY(%(course_ids)s) |
| 183 | + context_store_entity.course_offering co |
| 184 | + LEFT OUTER JOIN context_store_entity.academic_term at1 on (co.academic_term_id = at1.academic_term_id), |
| 185 | + context_store_keymap.course_offering co2, |
| 186 | + context_store_keymap.academic_term at2 |
| 187 | + WHERE co2.lms_int_id IN UNNEST(@course_ids) |
185 | 188 | and co.course_offering_id = co2.id
|
186 | 189 | and at1.academic_term_id = at2.id
|
187 | 190 | ''',
|
|
191 | 194 | cast(f_km.lms_int_id as BIGINT) as id,
|
192 | 195 | f.status as file_state,
|
193 | 196 | f.display_name as display_name
|
194 |
| - from entity.file f, keymap.file f_km, keymap.course_offering co_km |
| 197 | + from context_store_entity.file f, context_store_keymap.file f_km, context_store_keymap.course_offering co_km |
195 | 198 | where
|
196 | 199 | f.course_offering_id = co_km.id
|
197 | 200 | and f.file_id = f_km.id
|
198 |
| - and co_km.lms_int_id = ANY(%(course_ids)s) |
| 201 | + and co_km.lms_int_id IN UNNEST(@course_ids) |
199 | 202 | order by id
|
200 | 203 | ''',
|
201 | 204 | "submission":
|
202 | 205 | '''
|
203 |
| - create temporary table all_assign_sub as ( |
204 | 206 | with enrollment as
|
205 | 207 | (
|
206 | 208 | select
|
207 | 209 | distinct cse.person_id as user_id
|
208 |
| - from entity.course_section_enrollment cse |
209 |
| - left join entity.course_section cs |
| 210 | + from context_store_entity.course_section_enrollment cse |
| 211 | + left join context_store_entity.course_section cs |
210 | 212 | on cse.course_section_id = cs.course_section_id
|
211 |
| - left join keymap.course_offering co |
| 213 | + left join context_store_keymap.course_offering co |
212 | 214 | on cs.le_current_course_offering_id = co.id
|
213 | 215 | where
|
214 |
| - co.lms_int_id = ANY(:course_ids) |
| 216 | + co.lms_int_id in UNNEST(@course_ids) |
215 | 217 | and cse.role_status ='Enrolled'
|
216 |
| - and cse."role" = 'Student' |
| 218 | + and cse.role = 'Student' |
217 | 219 | and cse.enrollment_status = 'Active'
|
218 | 220 | ),
|
219 | 221 | submission as
|
|
222 | 224 | la.status,
|
223 | 225 | la.visibility,
|
224 | 226 | la2.lms_int_id as assignment_id,
|
225 |
| - cast(co.lms_int_id as BIGINT) as course_id, |
| 227 | + co.lms_int_id as course_id, |
226 | 228 | la.title as assignment_title,
|
227 | 229 | lar.published_score as published_score,
|
228 | 230 | lar.response_date as submitted_at,
|
|
232 | 234 | la.title as title,
|
233 | 235 | lar.learner_activity_result_id as learner_activity_result_id,
|
234 | 236 | lar.person_id as short_user_id,
|
235 |
| - cast(lar2.lms_int_id as BIGINT) as submission_id, |
236 |
| - (cast(:canvas_data_id_increment as bigint) + cast(p.lms_ext_id as bigint)) as canvas_user_id |
237 |
| - from entity.learner_activity_result lar |
| 237 | + lar2.lms_int_id as submission_id, |
| 238 | + CAST(@canvas_data_id_increment AS INT64) + CAST(p.lms_ext_id AS INT64) as canvas_user_id |
| 239 | + from context_store_entity.learner_activity_result lar |
238 | 240 | join enrollment on lar.person_id= enrollment.user_id
|
239 | 241 | join enrollment e on lar.person_id = e.user_id
|
240 |
| - join keymap.learner_activity_result lar2 on lar.learner_activity_result_id = lar2.id |
241 |
| - left join entity.learner_activity la on lar.learner_activity_id = la.learner_activity_id |
242 |
| - left join keymap.learner_activity la2 on la.learner_activity_id = la2.id |
243 |
| - left join keymap.course_offering co on co.id = la.course_offering_id |
244 |
| - join keymap.person p on p.id = lar.person_id |
| 242 | + join context_store_keymap.learner_activity_result lar2 on lar.learner_activity_result_id = lar2.id |
| 243 | + left join context_store_entity.learner_activity la on lar.learner_activity_id = la.learner_activity_id |
| 244 | + left join context_store_keymap.learner_activity la2 on la.learner_activity_id = la2.id |
| 245 | + left join context_store_keymap.course_offering co on co.id = la.course_offering_id |
| 246 | + join context_store_keymap.person p on p.id = lar.person_id |
245 | 247 | where
|
246 |
| - co.lms_int_id = ANY(:course_ids) |
| 248 | + co.lms_int_id in UNNEST(@course_ids) |
247 | 249 | and la.status = 'published'
|
248 |
| - ) |
| 250 | + ), |
| 251 | + all_assign_sub as |
| 252 | + ( |
249 | 253 | select
|
250 |
| - cast(submission_id as BIGINT) AS id, |
| 254 | + submission_id AS id, |
251 | 255 | assignment_id AS assignment_id,
|
252 | 256 | course_id,
|
253 | 257 | canvas_user_id,
|
|
264 | 268 | submitted_at AS submitted_at,
|
265 | 269 | graded_at AS graded_date,
|
266 | 270 | grade_posted
|
267 |
| - from |
268 |
| - submission |
| 271 | + from |
| 272 | + submission |
| 273 | + order by assignment_id |
269 | 274 | )
|
270 |
| - ''', |
271 |
| - "submission_with_avg_score": |
272 |
| - ''' |
273 | 275 | select
|
274 |
| - f.id::bigint, |
275 |
| - f.assignment_id::bigint assignment_id, |
| 276 | + f.id, |
| 277 | + CAST(f.assignment_id AS INT64) AS assignment_id, |
276 | 278 | f.course_id,
|
277 |
| - f.canvas_user_id::bigint as user_id, |
278 |
| - f.score::float, |
| 279 | + CAST(f.canvas_user_id AS INT64) AS user_id, |
| 280 | + CAST(f.score AS FLOAT64) AS score, |
279 | 281 | f.submitted_at,
|
280 | 282 | f.graded_date,
|
281 | 283 | f.grade_posted,
|
282 |
| - cast(f1.avg_score as float) as avg_score |
| 284 | + CAST(f1.avg_score AS FLOAT64) AS avg_score |
283 | 285 | from
|
284 | 286 | all_assign_sub f join
|
285 | 287 | (
|
|
0 commit comments