-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaggregate.js
412 lines (363 loc) · 9.99 KB
/
aggregate.js
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
var now_showing = 1;
var now_offering = 1;
var now_coloring = 0;
var now_clustering = 8;
var demo1;
var demo2;
var data1;
var data2;
var cluster1_1;
var cluster1_2;
var cluster1_4;
var cluster1_8;
var cluster2_1;
var cluster2_2;
var cluster2_4;
var cluster2_8;
d3.csv("data/demographics_offering1.csv", function(error, data){
data.forEach(function(d) {
d.studentid = +d.studentid;
});
demo1 = data;
});
d3.csv("data/demographics_offering2.csv", function(error, data){
data.forEach(function(d) {
d.studentid = +d.studentid;
});
demo2 = data;
});
//give non-submissions timestamps too
function defaulttimestamps(hw, off){
if (off == 1 ){
switch (hw) {
case 5: return 1358895453;
case 6: return 1359640173;
case 11: return 1360529471;
case 13: return 1361748191;
case 15: return 1362428898;
case 17: return 1362882328;}
}
else {
switch (hw) {
case 5: return 1381054271;
case 6: return 1382423851;
case 11: return 1382807403;
case 13: return 1383402021;
case 15: return 1384777587;
case 17: return 1384587218;}
}
}
function filltime(timestamp,hw, off){
if (timestamp == 0){
return defaulttimestamps(hw, off);
}
else{
return timestamp;
}
}
d3.csv("data/aggregate_grades_offering1.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 1);
});
data1 = alldata;
});
d3.csv("data/aggregate_grades_offering2.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 2);
});
data2 = alldata;
});
d3.csv("data/cluster_1_offering1.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 1);
});
cluster1_1 = alldata;
});
d3.csv("data/cluster_2_offering1.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 1);
});
cluster1_2 = alldata;
});
d3.csv("data/cluster_4_offering1.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 1);
});
cluster1_4 = alldata;
});
d3.csv("data/cluster_8_offering1.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 1);
});
cluster1_8 = alldata;
});
d3.csv("data/cluster_1_offering2.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 2);
});
cluster2_1 = alldata;
});
d3.csv("data/cluster_2_offering2.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 2);
});
cluster2_2 = alldata;
});
d3.csv("data/cluster_4_offering2.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 2);
});
cluster2_4 = alldata;
});
d3.csv("data/cluster_8_offering2.csv", function(error, alldata) {
alldata.forEach(function(d) {
d.ROWID = +d.ROWID;
d.HW = +d.HW;
d.STUDENTID= +d.STUDENTID;
d.TIMESTAMP= +d.TIMESTAMP;
d.SUBMISSION= +d.SUBMISSION;
d.SCORE = +d.SCORE;
d.TIMESTAMP = filltime(d.TIMESTAMP, d.HW, 2);
});
cluster2_8 = alldata;
});
function switchassign(foo){
now_showing = foo;
window[currentView](false);
}
function switchclusters(foo){
now_clustering = foo;
console.log(foo);
console.log(now_clustering);
window[currentView](false);
}
function switchoffer(foo){
now_offering = foo;
window[currentView](false);
}
function switchcolor(foo){
now_coloring = foo;
window[currentView](false);
}
function hw_id_to_num(hw){
switch (hw) {
case 5: return 1;
case 6: return 2;
case 11: return 3;
case 13: return 5;
case 15: return 6;
case 17: return 7;}
}
function aggregate(change_bar) //grade timeline
{
currentView = 'aggregate';
show_loading();
if(change_bar){
document.getElementById("sidebar").innerHTML = document.getElementById("allgrades").innerHTML;
document.getElementById("sidebar2").innerHTML = document.getElementById("emptybar").innerHTML;
fill_instruction("clustered_instruction");
}
var margin = {top: 20, right: 80, bottom: 30, left: 50},
width = 900 - margin.left - margin.right,
height = 600 - margin.top - margin.bottom;
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
//change based on coloring schema
var color = d3.scale.category10();
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var lineview = d3.svg.line()
.x(function(d) {return x(hw_id_to_num(d.HW)); })
.y(function(d) {return y(d.SCORE); });
var svg = d3.select("#canvas").append("svg")
.attr("class", "view4")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
if(now_offering == 1){
demodata = demo1;
if( now_clustering == 0)
data = data1;
if( now_clustering == 1)
data = cluster1_1;
if( now_clustering == 2)
data = cluster1_2;
if( now_clustering == 4)
data = cluster1_4;
if( now_clustering == 8)
data = cluster1_8;
} else{
demodata = demo2;
if( now_clustering == 0)
data = data2;
if( now_clustering == 1)
data = cluster2_1;
if( now_clustering == 2)
data = cluster2_2;
if( now_clustering == 4)
data = cluster2_4;
if( now_clustering == 8)
data = cluster2_8;
}
x.domain([0,8]);
y.domain([0,110]); //Cap at reasonable height, ignore massive extra credit
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.append("text")
.attr("class", "label")
.attr("x", width)
.attr("y", -6)
.style("text-anchor", "end")
.text("Assignment");
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("class", "label")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Score");
var stripped_data = data.filter(function(d){
var sub2 = d.SUBMISSION==1;
switch (d.HW) {
case 5: return sub2 && box1;
case 6: return sub2 && box2;
case 11: return sub2 && box3;
case 13: return sub2 && box4;
case 15: return sub2 && box5;
case 17: return sub2 && box6;
}});
function id_to_category(id){
var d_entry = (demodata.filter(function(d){
return d.studentid == id; }))[0];
if(now_clustering != 0){
return id;
}
switch (now_coloring){
case 0: return 0; //no category
case 1: return d_entry.gender;
case 2: return d_entry.agegroup;
case 3: return d_entry.background;
case 4: return d_entry.continent;
}
}
//six entries per student, and in sorted order. Take advantage of that
var num_assign = 0;
if (box1)
num_assign++;
if (box2)
num_assign++;
if (box3)
num_assign++;
if (box4)
num_assign++;
if (box5)
num_assign++;
if (box6)
num_assign++;
var student_count = (stripped_data.length/num_assign);
var pointer = 0;
var student = 0;
for (student = 0; student < student_count; student++){
pointer = student*num_assign;
var student_array = [];
for (var i = 0; i < num_assign; i++){
student_array.push(stripped_data[pointer+i]);
}
svg.append("path")
.attr("class", "line")
.attr("d", lineview(student_array))
.style("stroke", function(d) {return color (id_to_category(student));});
}
svg.selectAll(".dot")
.data(stripped_data)
.enter()
.append("circle")
.attr("class", "dot")
.attr("r", 5.5)
.attr("cx", function(d) { return x(hw_id_to_num(d.HW)); })
.attr("cy", function(d) { return y(d.SCORE); })
.style("fill", function(d) {return color (id_to_category(d.STUDENTID)); } );
var legend = svg.selectAll(".legend")
.data(color.domain())
.enter().append("g")
.attr("class", "legend")
.attr("transform", function(d, i) { return "translate(0," + i * 20 + ")"; });
legend.append("rect")
.attr("x", width - 18)
.attr("width", 18)
.attr("height", 18)
.style("fill", color);
legend.append("text")
.attr("x", width - 24)
.attr("y", 9)
.attr("dy", ".35em")
.style("text-anchor", "end")
.text(function(d) { return d; });
hide_loading();
}