-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm01math_grade1_create_or_refresh_bq_datasource.sql
304 lines (227 loc) · 6.41 KB
/
m01math_grade1_create_or_refresh_bq_datasource.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
-----------------------------------------------------------------------------
--run this combined script to refresh the Math Grade 1 BigQuery Datasource---
-----------------------------------------------------------------------------
--[step 01.1] import data from classroom trackers
--import grade 1 math unit 1 data
SELECT *
FROM `harlemlinksy2122.trackers.math_grade1_unit1`;
--import grade 1 math unit 2 data
SELECT *
FROM `harlemlinksy2122.trackers.math_grade1_unit2`;
--import grade 1 math unit 3 data
SELECT *
FROM `harlemlinksy2122.trackers.math_grade1_unit3`;
--import grade 1 math unit 4 data
SELECT *
FROM `harlemlinksy2122.trackers.math_grade1_unit4`;
--add a data pull for the next unit below
--[step 01.2] import data from the math level 3 question bank
SELECT *
FROM `harlemlinksy2122.questions.math` ;
--[step 01.3] import data from the students (subgroups and demographics) table
SELECT *
FROM `harlemlinksy2122.demographics.students` ;
--[step 01.4] unpivot classroom trackers
--add a new code block below for each new unit
--unpivot math grade 1 unit 1 data
CREATE OR REPLACE TABLE
`harlemlinksy2122.unpivots.math_grade1_unit1` AS
SELECT
osis,
question_id,
points_earned
FROM
`harlemlinksy2122.trackers.math_grade1_unit1` UNPIVOT(points_earned FOR question_id IN (math_grade1_unit1_q01,
math_grade1_unit1_q02,
math_grade1_unit1_q03,
math_grade1_unit1_q04,
math_grade1_unit1_q05,
math_grade1_unit1_q06
)) ;
--unpivot math grade 1 unit 2 data
CREATE OR REPLACE TABLE
`harlemlinksy2122.unpivots.math_grade1_unit2` AS
SELECT
osis,
question_id,
points_earned
FROM
`harlemlinksy2122.trackers.math_grade1_unit2` UNPIVOT(points_earned FOR question_id IN (math_grade1_unit2_q01,
math_grade1_unit2_q02,
math_grade1_unit2_q03,
math_grade1_unit2_q04,
math_grade1_unit2_q05,
math_grade1_unit2_q06,
math_grade1_unit2_q07,
math_grade1_unit2_q08,
math_grade1_unit2_q09,
math_grade1_unit2_q10
)) ;
--unpivot math grade 1 unit 3 data
CREATE OR REPLACE TABLE
`harlemlinksy2122.unpivots.math_grade1_unit3` AS
SELECT
osis,
question_id,
points_earned
FROM
`harlemlinksy2122.trackers.math_grade1_unit3` UNPIVOT(points_earned FOR question_id IN (
math_grade1_unit3_q01,
math_grade1_unit3_q02,
math_grade1_unit3_q03,
math_grade1_unit3_q04,
math_grade1_unit3_q05,
math_grade1_unit3_q06,
math_grade1_unit3_q07,
math_grade1_unit3_q08,
math_grade1_unit3_q09,
math_grade1_unit3_q10,
math_grade1_unit3_q11,
math_grade1_unit3_q12,
math_grade1_unit3_q13,
math_grade1_unit3_q14,
math_grade1_unit3_q15
)) ;
--unpivot math grade 1 unit 4 data
CREATE OR REPLACE TABLE
`harlemlinksy2122.unpivots.math_grade1_unit4` AS
SELECT
osis,
question_id,
points_earned
FROM
`harlemlinksy2122.trackers.math_grade1_unit4` UNPIVOT(points_earned FOR question_id IN (
math_grade1_unit4_q01,
math_grade1_unit4_q02,
math_grade1_unit4_q03,
math_grade1_unit4_q04,
math_grade1_unit4_q05,
math_grade1_unit4_q06,
math_grade1_unit4_q07,
math_grade1_unit4_q08,
math_grade1_unit4_q09,
math_grade1_unit4_q10,
math_grade1_unit4_q11
)) ;
--add unpivots for new units below
--[step 01.5] combines all unpivoted trackers into a single table
--add a new code block below for each new unit
CREATE OR REPLACE TABLE
`harlemlinksy2122.unions.math_grade1` AS
--pull unpivoted data from math grade 1 unit 1
SELECT
osis,
question_id,
points_earned,
FROM
`harlemlinksy2122.unpivots.math_grade1_unit1`
--pull unpivoted data from math grade 1 unit 2
UNION ALL
SELECT
osis,
question_id,
points_earned,
FROM
`harlemlinksy2122.unpivots.math_grade1_unit2`
--pull unpivoted data from math grade 1 unit 3
UNION ALL
SELECT
osis,
question_id,
points_earned,
FROM
`harlemlinksy2122.unpivots.math_grade1_unit3`
--pull unpivoted data from math grade 1 unit 4
UNION ALL
SELECT
osis,
question_id,
points_earned,
FROM
`harlemlinksy2122.unpivots.math_grade1_unit4`
--insert UNION ALL code block here for the next unit
;
--[step 01.6] join questions table to unions table to create results table
CREATE OR REPLACE TABLE
--the results is used to calculate benchmarks grouped by students.osis and questions.unit
`harlemlinksy2122.results.math_grade1` AS
SELECT
unions.osis,
unions.question_id,
--pulls in columns for questions.points_available and questions.unit
grade_level,
unit,
ccls_standard,
standard_description,
question_text,
points_earned,
points_available
FROM
`harlemlinksy2122.unions.math_grade1` unions
LEFT JOIN
`harlemlinksy2122.questions.math` questions
ON
unions.question_id = questions.question_id
WHERE
unions.osis IS NOT NULL ;
--[step 01.7] use the results table to calculate benchmarks using CASE WHEN
CREATE OR REPLACE TABLE
`harlemlinksy2122.benchmarks.math_grade1` AS
SELECT
osis,
unit,
SUM(points_earned)/SUM(points_available) AS math_pct_points,
--used to add student-assessment-level benchmarks to tables with student-question level granularity
CASE
WHEN SUM(points_earned)/SUM(points_available) >= .75 THEN "Achieved Benchmark"
WHEN SUM(points_earned)/SUM(points_available) BETWEEN .5
AND .74999999 THEN "Approaching Benchmark"
WHEN SUM(points_earned)/SUM(points_available) < .5 THEN "Below Benchmark"
ELSE
""
END
AS math_benchmark
FROM
`harlemlinksy2122.results.math_grade1`
WHERE
osis IS NOT NULL
GROUP BY
1,
2 ;
--[step 01.8] creates or replaces table `harlemlinksy2122.datasources.math_grade1`
--this table is linked directly to Google Data Studio as a datasource
--it serves as the datasouse for the math level 3 grade 1 dashboard
CREATE OR REPLACE TABLE
`harlemlinksy2122.datasources.math_grade1` AS
SELECT
--start by pulling the osis on the combined results table
results.osis,
--pull these columns from the .demographics.students table
student,
sy_21_22_class,
sped,
enl,
hl_upk,
holdovers,
new_students,
ais,
--also pull these test-related columns from the results table
question_id,
ccls_standard,
standard_description,
question_text,
results.unit,
points_earned,
points_available,
math_pct_points,
math_benchmark
FROM
`harlemlinksy2122.results.math_grade1` results
LEFT JOIN
`harlemlinksy2122.demographics.students` students
ON results.osis = students.osis
LEFT JOIN
`harlemlinksy2122.benchmarks.math_grade1` benchmarks
ON results.osis = benchmarks.osis AND results.unit = benchmarks.unit
WHERE results.osis IS NOT NULL ;
---END----------------------------------------------------------------------------