forked from ArturoAmaya/ExploratoryCurricularAnalytics
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsummarize_metrics.ts
230 lines (215 loc) · 6.1 KB
/
summarize_metrics.ts
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
// deno run -A summarize_metrics.ts './files/CA_MetricsforMap_FINAL(Metrics).csv'
// -> files/protected/summarize_dfw.json
// files/protected/summarize_dfw_by_major.json
// files/protected/summarize_waitlist.json
import { parse } from 'https://deno.land/[email protected]/csv/parse.ts'
const table = parse(await Deno.readTextFile(Deno.args[0])).slice(1)
const majorByDepartment = Object.groupBy(
parse(await Deno.readTextFile('files/isis_major_code_list.csv'), {
skipFirstRow: true
}).map(({ 'ISIS Major Code': isMajorCode, Department: department }) => ({
majorCode:
typeof isMajorCode === 'string'
? isMajorCode
: expect('ISIS Major Code should be string'),
department:
typeof department === 'string'
? department
: expect('Department should be string')
})),
({ department }) => department
)
const majorSubjByDeptEntries = Object.entries(majorByDepartment).map(
([dept, majors]): [string, string[]] => [
dept,
Array.from(new Set(majors?.map(major => major.majorCode.slice(0, 2))))
]
)
const majorSubjByDept = Object.fromEntries(majorSubjByDeptEntries)
for (const [dept, majorCodes] of majorSubjByDeptEntries) {
for (const [dept2, majorCodes2] of majorSubjByDeptEntries) {
if (dept === dept2) {
continue
}
const dupe = majorCodes.find(code => majorCodes2.includes(code))
if (dupe) {
console.warn('dept', dept, 'major', dupe, 'also in dept', dept2)
}
}
}
function expect (message: string): never {
throw new TypeError(message)
}
function check<T> (value: T, check: (value: T) => string | null): T {
const message = check(value)
if (message !== null) {
throw new TypeError(message)
}
return value
}
type Row = {
// Course ID
/** No space, e.g. `AIP197DC` */
courseCode: string
// Dept Cd
/** Seems to represent the major of the student. Can be `No major` */
departmentCode: string
disproportionate: {
// Major Disproportionate Impact
major: boolean
// URM Disproportionate Impact
urm: boolean
// First Gen Disproportionate Impact
firstGen: boolean
// Gender Disproportionate Impact
gender: boolean
}
// N
studentCount: number
// N Qtrs w/Enrollment
/**
* Number of quarters the course was offered / there was data for. Often seems
* to be around 8.
*/
quarterCount: number
// Count of DFW Grades
dfwCount: number
// % DFW
/** Between 0 and 1 */
dfwPercent: number
// Avg. End Waitlist Count/Qtr
/** At end of quarter */
averageWaitlist: number
// Avg. N Students Affected/Offering
/** Per offering of the course */
averageStudentsAffected: number
// Ignored:
// N Courses Blocked
// Max. Complexity
// Impact Index
}
const rows = table.map(
([
courseCode,
departmentCode,
impactMajor,
impactUrm,
impactFirstGen,
impactGender,
studentCount,
quarterCount,
dfwCount,
dfwPercent,
averageWaitlist,
averageStudentsAffected
]): Row => ({
courseCode,
departmentCode,
disproportionate: {
major:
impactMajor === 'Y'
? true
: impactMajor === ''
? false
: expect('expected impactMajor to be either Y or empty'),
urm:
impactUrm === 'Y'
? true
: impactUrm === ''
? false
: expect('expected impactUrm to be either Y or empty'),
firstGen:
impactFirstGen === 'Y'
? true
: impactFirstGen === ''
? false
: expect('expected impactFirstGen to be either Y or empty'),
gender:
impactGender === 'Y'
? true
: impactGender === ''
? false
: expect('expected impactGender to be either Y or empty')
},
studentCount: +studentCount,
quarterCount: +quarterCount,
dfwCount: +dfwCount,
dfwPercent: +dfwPercent.replace('%', '') / 100,
averageWaitlist: +averageWaitlist,
averageStudentsAffected: +averageStudentsAffected
})
)
// console.log(rows)
const byCourse = Map.groupBy(rows, ({ courseCode }) => courseCode)
Deno.writeTextFile(
'files/protected/summarize_dfw.json',
JSON.stringify(
Object.fromEntries(
Array.from(byCourse, ([courseCode, rows]) => [
courseCode,
rows.reduce((cum, curr) => cum + curr.dfwCount, 0) /
rows.reduce((cum, curr) => cum + curr.studentCount, 0)
])
),
null,
2
) + '\n'
)
console.log('wrote files/protected/summarize_dfw.json')
Deno.writeTextFile(
'files/protected/summarize_dfw_by_major.json',
JSON.stringify(
Object.fromEntries(
Array.from(byCourse, ([courseCode, rows]) => [
courseCode,
{
...Object.fromEntries(
rows.flatMap(
({ departmentCode, dfwCount, studentCount, dfwPercent }) =>
majorSubjByDept[departmentCode]?.map(majorCode => [
majorCode,
check(dfwCount / studentCount, percent =>
Math.round(percent * 100) / 100 === dfwPercent
? null
: `${courseCode} ${departmentCode}: ${
dfwCount / studentCount
} =/= ${dfwPercent}`
)
]) ?? []
)
),
allMajors:
rows.reduce((cum, curr) => cum + curr.dfwCount, 0) /
rows.reduce((cum, curr) => cum + curr.studentCount, 0)
}
])
),
null,
2
) + '\n'
)
console.log('wrote files/protected/summarize_dfw_by_major.json')
Deno.writeTextFile(
'files/protected/summarize_waitlist.json',
JSON.stringify(
Object.fromEntries(
Array.from(byCourse, ([courseCode, rows]) => [
courseCode,
check(
rows.map(({ averageWaitlist }) => averageWaitlist),
counts =>
counts.every(count => count === counts[0])
? null
: `waitlist counts differ ${courseCode}`
)[0]
])
),
null,
2
) + '\n'
)
console.log('wrote files/protected/summarize_waitlist.json')
console.log(
'all departments',
Array.from(new Set(rows.map(({ departmentCode }) => departmentCode))).sort()
)