-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgradesWorksheet.gs
More file actions
1869 lines (1514 loc) · 71.9 KB
/
gradesWorksheet.gs
File metadata and controls
1869 lines (1514 loc) · 71.9 KB
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File: graded_worksheet.gas
// Description:
// This file contains the class to hold the grades worksheet.
// TODO_AJR - Try and get all of the type decisions on the same level. Things like
// gws type and autogradeon.
// TODO_AJR - Get all of the ScriptProperties into an object to speed things up.
// Check how often they're called.
// TODO_AJR - Look for gws processing done during INIT_TYPE_GRADED_ that might
// be used.
// TODO_AJR - Questions and percentages not coloured yellow first grading.
// TODO_AJR - Nested functions are acheiving the data hiding, but I'm not
// sure if it's "class" JS or not. Google for "nested class javascript"
// TODO_AJR_BUG - in original code in processGradesSheet() use of question_vals
// as gws property (worked somehow). Fixed but needs passing to DaveA. Showed up
// when I ran sendEmails with no Grades sheet - should assert on that.
// TODO_AJR_BUG - No frozen row in grades sheet first time graded.
// TODO_AJR - Test for answer key not at row 2 in subm sheet.
// A global flag used to communicate between the submission processing
// and the later stages of the grading that the present submission
// is from a student that has already submitted one. This works as the
// autograding in a single execution context.
gbl_repeat_subm = false;
// gbl_invalid_grades_sheet_error: Stores a string that describes the issue
// with the grades sheet that gwsGradesSheetIsValid determined makes it invalidl
gbl_invalid_grades_sheet_error = "";
// GradesWorksheet class:
// The GradesWorksheet class represents the "Grades" worksheet that will record
// all of the grades. This object obfuscates how that information is written out
// and accessed, making it easier to work with the data in that sheet (both
// during grading, and afterwards). There is only ever a single instance of this
// object.
// Constructor takes as arguments:
// spreadsheet: Reference to the entire spreadsheet
// init_type: Specifies how GradesWorksheet is being initialized:
// - INIT_TYPE_SUBM: Init from the Student Submissions sheet, during grading.
// - INIT_TYPE_GRADED_*: Init from the 'Grades' sheet, such as when emailing grades
// num_graded_submissions_to_read: Only used for INIT_TYPE_GRADED_ONLY_LATEST. Otherwise pass -1.
// Specifies how many graded submissions to read in (from the bottom).
function GradesWorksheet(spreadsheet, init_type, num_graded_submissions_to_read)
{
this.initGWSVars(spreadsheet, init_type, num_graded_submissions_to_read);
if (init_type == INIT_TYPE_SUBM)
{
Debug.info("GradesWorksheet: INIT_TYPE_SUBM");
this.prepNewGradesSheet(); // possibly remove depending on how autograde progresses.
this.processSubmissionsSheet();
}
else if (init_type == INIT_TYPE_SUBM_ONLY_LATEST)
{
Debug.info("GradesWorksheet: INIT_TYPE_SUBM_ONLY_LATEST. num_graded_submissions_to_read = " + num_graded_submissions_to_read);
this.processSubmissionsSheet();
}
else // INIT_TYPE_GRADED_*
{
Debug.info("GradesWorksheet: INIT_TYPE_GRADED*");
if (this.grades_sheet && (this.grades_sheet.getLastRow() > 2))
{
this.processGradesSheet();
}
}
Debug.writeToFieldLogSheet();
}
GradesWorksheet.prototype.initGWSVars = function(spreadsheet, init_type, num_graded_submissions_to_read)
{
Debug.info("initGWSVars: entering. init_type=" + init_type);
this.init_type = init_type;
this.num_graded_submissions_to_read = num_graded_submissions_to_read;
this.spreadsheet = spreadsheet;
this.submissions_sheet = getSheetWithSubmissions(this.spreadsheet);
this.grades_sheet = getSheetWithGrades(this.spreadsheet);
// TODO_AJR - Better to use an object rather than an associative array.
// Associative array of all graded submissions in the grades sheet.
// indexed by fingerprint.
this.graded_submissions = new Array();
// A read-only list of all fingerprints stored in
// this.graded_submissions.
this.fingerprint_list = null;
this.fingerprint_list_iterator = 0;
// A subset of this.fingerprint_list, containing only fingerprints of
// submissions that won't / don't have an 'x' in the "Already Emailed?"
// column in the Grades sheet.
this.not_already_emailed_fingerprints = new Object();
this.points_possible = 0;
this.num_student_identifiers = 0;
this.num_gradeable_questions = 0;
this.has_manually_graded_question = false;
this.question_hash = null;
var dp = PropertiesService.getDocumentProperties();
this.answer_key_row_num = Number(dp.getProperty(DOC_PROP_ANSWER_KEY_ROW_NUM));
// data pulled from the summary at the top of the Grades sheet.
this.avg_subm_score = 0;
this.num_low = 0;
// 'true' if one of the answer key values is actually a '%=' formula.
this.has_formula_anskey = false;
Debug.info("initGWSVars: leaving");
}
GradesWorksheet.prototype.getPointsPossible = function()
{
return this.points_possible;
}
GradesWorksheet.prototype.getAverageScore = function()
{
return this.avg_subm_score;
}
GradesWorksheet.prototype.getNumStudentIdentifiers= function()
{
return this.num_student_identifiers;
}
// getNumGradedSubmissions:
// Returns the number of graded submissions in the Grades worksheet.
// Note that this is the total number in the sheet itself, and not
// the number actually graded in the gws object (which could be less if
// we're using Autograde and grading just the most recent submissions).
//
// TODO_AJR - Would be nice to just be switching on init_type
// rather than assuming the fp has been set up, which it is when the
// submission sheet is processed.
GradesWorksheet.prototype.getNumGradedSubmissions = function()
{
var num;
var use_fp_list = false;
if (this.fingerprint_list != null && (this.fingerprint_list.length > 0)
&& this.init_type != INIT_TYPE_SUBM_ONLY_LATEST)
{
// fp list is populated with all the (unique) submissions.
use_fp_list = true;
}
if (use_fp_list)
{
// Whenever possible use the total number of unique
// fingerprints.
num = this.fingerprint_list.length;
}
else
{
// TODO DAA: replace this wrapper class with direct set/get of the Script Property.
num = NumGradedSubm.get();
}
return num;
}
// getNumGradedSubmissions:
// For use with Autograde when grading only most recent submissions (vs whole
// Student Submissions sheet). Returns just the number of submissions that
// were most recently graded (vs total # in the Grades sheet).
GradesWorksheet.prototype.getNumRecentGradedSubmissions = function()
{
if (this.fingerprint_list != null && (this.fingerprint_list.length > 0))
{
return this.fingerprint_list.length;
}
return 0;
}
// addGradedSubmission: Adds a new graded submission. If already exists (same fingerprint), replaces
// the existing one.
GradesWorksheet.prototype.addGradedSubmission = function(fingerprint, gs)
{
this.graded_submissions[fingerprint] = gs;
}
GradesWorksheet.prototype.checkForGradedSubmission = function(fingerprint)
{
return (fingerprint in this.graded_submissions) ? true : false;
}
GradesWorksheet.prototype.countGradedSubmissions = function()
{
var counted_subm_in_gws = Object.keys(this.graded_submissions).length;
Debug.info("countGradedSubmissions() - counted_subm_in_gws: " + counted_subm_in_gws);
return counted_subm_in_gws;
}
GradesWorksheet.prototype.getGradedSubmissionByFingerprint = function(fingerprint)
{
if (fingerprint in this.graded_submissions)
{
return this.graded_submissions[fingerprint];
}
else
{
return null;
}
}
// getFirstGradedSubmission:
// To make sure we write only the final grades (e.g. counting multiple
// submissions) we walk through the array of unique student
// fingerprints.
GradesWorksheet.prototype.getFirstGradedSubmission = function()
{
// Put each of the graded submissions into the fingerprint array.
this.fingerprint_list = new Array();
this.fingerprint_list_iterator = 0;
for (var key in this.graded_submissions)
{
this.fingerprint_list.push(key);
}
Debug.info("GradesWorksheet.getFirstGradedSubmission() - Initialised fp list");
Debug.info("GradesWorksheet.getFirstGradedSubmission() - fp list length: " +
this.fingerprint_list.length);
// Return the first submission in the array (extract the first entry
// from the array of fingerprints and use this as the key in the
// associative array of graded submissions).
return this.graded_submissions[this.fingerprint_list[0]];
}
GradesWorksheet.prototype.getNextGradedSubmission = function()
{
this.fingerprint_list_iterator++;
if (this.fingerprint_list_iterator < this.fingerprint_list.length)
{
return this.graded_submissions[this.fingerprint_list[this.fingerprint_list_iterator]];
}
else
{
return null;
}
}
GradesWorksheet.prototype.addNotAlreadyEmailedFingerprint = function(fingerprint)
{
this.not_already_emailed_fingerprints[fingerprint] = 1;
}
GradesWorksheet.prototype.getNotAlreadyEmailedFingerprintsList = function()
{
var fingerprints_array = [];
for (var fp in this.not_already_emailed_fingerprints)
{
if (this.not_already_emailed_fingerprints.hasOwnProperty(fp))
{
fingerprints_array.push(fp);
}
}
return fingerprints_array;
}
// processSubmissionsSheet:
// Performs the grading of all rows compared to the answer key.
GradesWorksheet.prototype.processSubmissionsSheet = function()
{
var dp = PropertiesService.getDocumentProperties();
var func_name = "GradesWorksheet.processSubmissionsSheet() - ";
Debug.info(func_name + "entering");
var grade_opt_str = dp.getProperty(DOC_PROP_UI_GRADING_OPT);
var category_names_str = dp.getProperty(DOC_PROP_UI_CATEGORY_NAMES);
Debug.info(func_name + "grade_opt_str:" + grade_opt_str);
Debug.assert(grade_opt_str !== null, func_name + "grading options not set");
this.grading_options = grade_opt_str.split(",");
if (category_names_str)
{
this.category_names = category_names_str.split(FLB_GENERIC_DELIMETER);
}
else
{
this.category_names = [];
}
// Get the questions
// -----------------
// Read in the questions asked from the first row and mark the first
// value as the timestamp.
var question_vals = getQuestionValsFromSubmissions(this.submissions_sheet);
// TODO: We only use the question_hash for manually graded questions, so
// perhaps only store the questions for questions with that grading option.
// Requires some good testing, which I don't have time for now. DA 7/22/15.
// question_hash: stores at what location each question resides.
this.question_hash = new Object();
for (var i=0; i < question_vals.length; i++)
{
var full_ques_text = question_vals[i];
this.question_hash[full_ques_text] = i;
}
Debug.info(func_name + "got question vals from submissions sheet");
// Read in the grading options.
this.processGradingOptions();
// Get the answer key values
// -------------------------
// Collect the answers from the Answer Key row. Make all lowercase so we're
// case insentive when comparing to text submissions.
Debug.info(func_name + "getting answer key values...");
var answer_key_vals;
if (!Autograde.isOn())
{
// Read in the answer key values from the row specified by the user.
// the user will have just specified this row number a moment ago when choosing
// grading options (Step 2).
Debug.info(func_name + "reading answer key row from submissions sheet...");
answer_key_vals = singleRowToArray(this.submissions_sheet,
this.answer_key_row_num,
getNumQuestionsFromSubmissions(this.submissions_sheet),
false);
}
else
{
// For autograde, we take the answer key values that were stored when Autograde
// was setup. This is to handle the case when the answer key row may actually shift
// to another row due to the way google form submits work sometimes.
Debug.info(func_name + "autograde on, so reading answer key row from document property...");
answer_key_vals = getAutogradeAnswerKeyValues(this.submissions_sheet, this.answer_key_row_num);
}
// Create a copy of the answer key array, not a reference to it.
var answer_key_vals_lc = answer_key_vals.slice(0);
for (var i = 0; i < answer_key_vals_lc.length; i++)
{
if (typeof answer_key_vals_lc[i] == 'string')
{
answer_key_vals_lc[i] = strTrim(answer_key_vals_lc[i].toLowerCase());
}
}
this.has_formula_anskey = gwsAnswerKeyHasFormula(answer_key_vals);
// TODO_AJR - If, reading in the answer key values, one isn't a string is that
// a problem?
// Get the help tips
// -----------------
// Collect the help tips if any are present. These will always be in the second
// row of the form (case insensitive when comparing to text submissions).
var help_tips_vals = getTipsRow(this.submissions_sheet);
var help_tips_present = (help_tips_vals !== null) ? true : false;
Debug.info(func_name + "help_tips_present: " + help_tips_present);
// Get the student's submissions
// -----------------------------
//
// Convert the row data from the submissions sheet into a 'graded submission' object
// and link it to the preset 'graded worksheet' object in the 'fingerprint' array.
var start_subm_row = 2; // one past header row
var numb_rows = this.submissions_sheet.getLastRow();
// only process latest submitted rows?
if (this.init_type == INIT_TYPE_SUBM_ONLY_LATEST)
{
var last_processed_subm_row = dp.getProperty(DOC_PROP_LAST_GRADED_ROW_COUNT);
if (last_processed_subm_row != null)
{
start_subm_row = Number(last_processed_subm_row) + 1;
}
}
Debug.info(func_name + " - will start processing submissions at row: " + start_subm_row);
// record how many rows we're about to grade. used by autograde logic.
dp.setProperty(DOC_PROP_LAST_GRADED_ROW_COUNT, numb_rows);
// Skip over the first row with questions in (row_num = 2).
for (var subm_row_num = start_subm_row; subm_row_num <= numb_rows; subm_row_num++)
{
Debug.info(func_name + "processing row: " + subm_row_num);
if (subm_row_num === this.answer_key_row_num)
{
// No need to include the answer key in the
// grades so skip it.
Debug.info(func_name + "skip answer key");
continue;
}
if (subm_row_num === 2 && help_tips_present)
{
// Skip over the help tips in the second row.
Debug.info(func_name + "skip help tips");
continue;
}
// Create a new GradedSubmission from this submission.
var new_graded_subm = new GradedSubmission(this,
this.submissions_sheet,
this.grades_sheet,
question_vals,
help_tips_present,
help_tips_vals,
this.grading_options,
this.category_names,
this.points_possible,
answer_key_vals,
answer_key_vals_lc,
this.num_student_identifiers,
this.num_gradeable_questions,
subm_row_num,
null, // grades sheet row (written to) will be set later
INIT_TYPE_SUBM);
// Create a fingerprint to uniquely identify this student and
// then check if we have already seen a submission from them in this
// spreadsheet (the graded submissions are stored in an associative
// array in the graded worksheet object, where a unique "fingerprint"
// for each student is used as the key).
var fingerprint = new_graded_subm.getSubmFingerprint();
if (fingerprint == "")
{
Debug.info("processSubmissionsSheet() - blank fingerprint. skipping this submission.");
continue;
}
var existing_graded_subm = this.getGradedSubmissionByFingerprint(fingerprint);
if (existing_graded_subm != null)
{
// This is a second (or third, ...) submission from a student.
// If this submission is newer than the last one seen, replace it.
var existing_timestamp = new Date(existing_graded_subm.getTimestamp());
var new_timestamp = new Date(new_graded_subm.getTimestamp());
var existing_times_submitted = existing_graded_subm.getTimesSubmitted();
if (new_timestamp > existing_timestamp)
{
// record how many times until now this particular student submitted.
new_graded_subm.setTimesSubmitted(existing_times_submitted);
this.addGradedSubmission(fingerprint, new_graded_subm);
}
// whether we replaced an entry or not, we still want to increment
// the number of submissions.
existing_graded_subm = this.getGradedSubmissionByFingerprint(fingerprint);
existing_graded_subm.setTimesSubmitted(existing_times_submitted + 1);
this.addGradedSubmission(fingerprint, existing_graded_subm);
}
else
{
// This is the first time we've seen a submission from this student.
// There's no need to compare submission timestamp.
this.addGradedSubmission(fingerprint, new_graded_subm);
}
}
Debug.info(func_name + "leaving");
} // GradesWorksheet.processSubmissionsSheet()
// processGradesSheet:
// Reads in all information in an existing 'Grades' sheet.
GradesWorksheet.prototype.processGradesSheet = function()
{
Debug.info("GradesWorksheet.processGradesSheet()");
Debug.assert(this.grades_sheet !== null,
"GradesWorksheet.processGradesSheet() - " +
"no grades sheet");
var numb_graded_submissions = this.getNumGradedSubmissions();
var dp = PropertiesService.getDocumentProperties();
// 8/21/15: for debugging purposes, log information about number of submissions perceived.
var single_cell = this.grades_sheet.getRange(GRADES_SUMMARY_COUNTED_SUBM_ROW_NUM, 2, 1, 1);
var grades_sheet_num_graded_subm = single_cell.getValue();
var prop_num_graded_subm = dp.getProperty(DOC_PROP_NUM_GRADED_SUBM);
Debug.info("num graded subm: " + numb_graded_submissions + "," + prop_num_graded_subm + "," + grades_sheet_num_graded_subm);
// Read in the hidden row containing the grading_options.
this.grading_options = this.getHiddenRow(GRADES_HIDDEN_ROW_TYPE_GRADING_OPT,
"",
numb_graded_submissions);
// Read in any category names for the questions (will often be blank if no categories being used)
if (getSheetWithCategories(this.spreadsheet))
{
this.category_names = singleRowToArray(this.grades_sheet, GRADES_CATEGORY_NAMES_ROW_NUM, -1, false);
}
else
{
this.category_names = [];
}
Debug.assert(this.grading_options[0] !== "",
"GradesWorksheet.processGradesSheet() - Can't find grading options");
// Read in the hidden row containing the questions asked.
var question_vals = this.getHiddenRow(GRADES_HIDDEN_ROW_TYPE_QUESTIONS_FULL,
"",
numb_graded_submissions);
// question_hash: stores at what location each question resides.
// TODO: We only use the question_hash for manually graded questions, so
// perhaps only store the questions for questions with that grading option.
// Requires some good testing, which I don't have time for now. DA 7/22/15.
this.question_hash = new Object();
for (var i=0; i < question_vals.length; i++)
{
var full_ques_text = question_vals[i];
this.question_hash[full_ques_text] = i;
}
// Read through the grading options to initialize variables like:
// points_possible, num_student_identifiers, and num_gradeable_questions
this.processGradingOptions();
// Pull in some info from the summary table at the top.
var summary_range = this.grades_sheet.getRange(GRADES_SUMMARY_PTS_POSSIBLE_ROW_NUM, 2, gbl_num_summary_rows, 1);
var summary_col = summary_range.getValues();
this.avg_subm_score = Number(summary_col[1]);
this.num_low = Number(summary_col[3]);
Debug.info("processGradesSheet() - reading answer key row from hidden row in Grades sheet...");
var answer_key_vals = this.getHiddenRow(GRADES_HIDDEN_ROW_TYPE_ANSWER_KEY,
"",
numb_graded_submissions);
var help_tips_vals = this.getHiddenRow(GRADES_HIDDEN_ROW_TYPE_HELP_TIPS,
"",
numb_graded_submissions);
this.has_formula_anskey = gwsAnswerKeyHasFormula(answer_key_vals);
// Check if any help tips are present. They will be if there's at least one
// non-empty cell in this row. otherwise the row will be entirely blank.
var help_tips_present = false;
var i;
for (i = 0; i < help_tips_vals.length; i++)
{
if (help_tips_vals[i] != "")
{
help_tips_present = true;
break;
}
}
Debug.info("GradesWorksheet.processGradesSheet() - init_type: " + this.init_type);
var max_submissions_to_read = 0;
// TODO_AJR - add else.
// Read in and process graded submissions in the Grades sheet.
var write_start_row = gbl_grades_start_row_num + 1;
if (this.init_type == INIT_TYPE_GRADED_META)
{
// Just process a single submission so we can use it later to
// grab grading options, etc, but without needing to read and
// process *all* of the submissions. Used to construct the UI
// for emailing grades.
max_submissions_to_read = 1;
}
else if (this.init_type == INIT_TYPE_GRADED_ONLY_LATEST)
{
// we want to read only the last few rows that were (just) written.
// this is for emailing grades when autograde is in use, but a '%=' is in the answer key.
max_submissions_to_read = this.num_graded_submissions_to_read;
var last_written_graded_subm_row = gbl_grades_start_row_num + 1 + this.getNumGradedSubmissions() - 1;
write_start_row = last_written_graded_subm_row - max_submissions_to_read + 1;
Debug.info("GradesWorksheet.processGradesSheet() - init_type == INIT_TYPE_GRADED_ONLY_LATEST.");
Debug.info("GradesWorksheet.processGradesSheet() - max_submissions_to_read = " + max_submissions_to_read);
Debug.info("GradesWorksheet.processGradesSheet() - last_written_graded_subm_row = " + last_written_graded_subm_row);
Debug.info("GradesWorksheet.processGradesSheet() - first row to read in Grades: " + write_start_row);
}
else // INIT_TYPE_GRADED_FULL or INIT_TYPE_GRADED_PARTIAL
{
// Read in all graded submissions.
max_submissions_to_read = this.getNumGradedSubmissions();
}
Debug.info("GradesWorksheet.processGradesSheet() - max submissions: " +
max_submissions_to_read);
for (i = 0; i < max_submissions_to_read; i++)
{
// Create a new GradedSubmission from this graded submission.
var new_graded_subm = new GradedSubmission(this,
this.submissions_sheet,
this.grades_sheet,
question_vals,
help_tips_present,
help_tips_vals,
this.grading_options,
this.category_names,
this.points_possible,
answer_key_vals,
answer_key_vals,
this.num_student_identifiers,
this.num_gradeable_questions,
null, // SS row not known here
write_start_row + i,
this.init_type);
// Create a fingerprint to uniquely identify this student and store their submission.
var fingerprint = new_graded_subm.getSubmFingerprint();
this.addGradedSubmission(fingerprint, new_graded_subm);
if (new_graded_subm.getAlreadyEmailed() == "")
{
this.addNotAlreadyEmailedFingerprint(fingerprint);
}
Debug.info("GradesWorksheet.processGradesSheet() - new grade submission just added " + i);
} // For each submission.
} // GradesWorksheet.processGradesSheet
// processGradingOptions()
// Processes this.grading_options to record how many student identifiers there are, as well as
// how many points possible. Records these in this.points_possible and this.num_student_identifiers.
GradesWorksheet.prototype.processGradingOptions = function()
{
Debug.info("GradesWorksheet.processGradingOptions()");
Debug.info("this.grading_options: " + this.grading_options);
for (var q_index=0; q_index < this.grading_options.length; q_index++)
{
var gopt = this.grading_options[q_index];
if (gopt === "")
{
continue; // blank entry from hidden row in Grades sheet
}
if (gopt === GRADING_OPT_STUD_ID)
{
this.num_student_identifiers++;
}
else
{
this.num_gradeable_questions++;
if (isWorthPoints(gopt) && !isBonusQuestion(gopt))
{
this.points_possible += getPointsWorth(gopt);
}
if (isManuallyGraded(gopt))
{
this.has_manually_graded_question = true;
}
}
}
this.num_gradeable_questions--; // discount "Timestamp" question, which is always skipped.
}
GradesWorksheet.prototype.prepNewGradesSheet = function()
{
Debug.info("GradesWorksheet.prepNewGradesSheet()");
var dp = PropertiesService.getDocumentProperties();
var clear_experiment = dp.getProperty(DOC_PROP_CLEAR_VS_DELETE_GRADES_SHEET);
// Start by creating the 'Grades' sheet. If it already exists, then
// delete it (instructor was already warned before in Step 1).
if (this.grades_sheet)
{
// Present, so delete it.
this.spreadsheet.setActiveSheet(this.grades_sheet);
if (clear_experiment)
{
// To be tested by Joe. Sept 2016. Made the default if it all checks out.'
unHideAllRowsAndColumns(this.grades_sheet);
this.grades_sheet.setFrozenColumns(0);
this.grades_sheet.setFrozenRows(0);
this.grades_sheet.getDataRange().clear();
}
else
{
this.spreadsheet.deleteActiveSheet();
}
// To avoid a bug in which 'Grades' get deleted, but appears to
// stick around, switch to another sheet after deleting it.
// TODO_AJR: bug still exists sometimes.
var switch_to_sheet = getSheetWithSubmissions(this.spreadsheet);
this.spreadsheet.setActiveSheet(switch_to_sheet);
}
if (!clear_experiment)
{
// Next, create a blank sheet for the grades.
this.grades_sheet = this.spreadsheet.insertSheet(langstr("FLB_STR_SHEETNAME_GRADES"));
// Enter enough blank rows into the new Grades sheet. It
// starts with 100, but we may need more. Not having enough
// causes an error when trying to write to non-existent rows.
var num_blank_rows_needed = gbl_grades_start_row_num + 1
+ (3 * this.submissions_sheet.getLastRow()) // grades, copies of submissions, and question comments
+ gbl_num_space_before_hidden
+ gbl_num_hidden_rows
+ 10; // extra 10 for good measure
if (num_blank_rows_needed > 100)
{
this.grades_sheet.insertRows(1, num_blank_rows_needed - 100);
}
}
// Write a simple message to the top-left cell, so users know
// grades are being calculated.
this.grades_sheet.getRange(2, 1, 1, 1)
.setValue(langstr("FLB_STR_GRADING_CELL_MESSAGE"))
.setFontWeight("bold");
this.grades_sheet.getRange("A2").activate();
} // GradesWorksheet.prepNewGradesSheet()
// writeGradesSheet:
// Write the graded submissions into the grades sheet. For the purposes
// of performing the write the sheet is seperated into three areas:
//
// header - submissions summary
// body - the submissions
// footer - internal data, usually hidden
//
// gws_existing: Points to (optional) gradesWorksheet object initialized
// from previously existing Grades sheet (with INIT_TYPE_GRADED_PARTIAL).
// Used to maintain information like "already emailed" column, and others,
// when re-generating the Grades sheet.
// This argument is passed as null if no prev Grades sheet exists.
//
// grades_sheet_update_type:
// Either GRADES_SHEET_UPDATE_TYPE_REGEN: Whole Grades sheet is regenerated
// or GRADES_SHEET_UPDATE_TYPE_INSERT: New graded submission rows are inserted
// into existing Grades sheet (less common case).
//
GradesWorksheet.prototype.writeGradesSheet = function(gws_existing,
grades_sheet_update_type)
{
// "Private" variables used in multiple functions nested in 'writeGradesSheet'.
var first_graded_subm;
var submissions_start_row;
var next_footer_row;
var last_row_written;
var total_subm_score = 0;
var num_graded_subm_written = 0;
var already_emailed_info = null;
var student_feedback_info = null;
var status = STATUS_OK;
Debug.info("GradesWorksheet.writeGradesSheet() - grades_sheet_update_type= " + grades_sheet_update_type);
/* doesn't help b/c new Grades sheet already written by this point. revisit, if worth it. */
if (this.countGradedSubmissions() == 0)
{
// no grades to write. should be a rare case.
// possibly due to a single subm with all blanks for student identifiers.
Debug.info("GradesWorksheet.writeGradesSheet() - no submissions to write. returning.");
return STATUS_CANNOT_CONTINUE;
}
if (gws_existing)
{
already_emailed_info = gws_existing.getAlreadyEmailedInfo();
student_feedback_info = gws_existing.getStudentFeedbackInfo();
}
var dp = PropertiesService.getDocumentProperties();
// Store "this" object for use in the nested functions.
var self = this;
// Write the contents of the grade sheet.
initializeWriting();
if (grades_sheet_update_type == GRADES_SHEET_UPDATE_TYPE_REGEN)
{
// Write the Header and Footer for the new Grades sheet
writeHeader();
writeFooter();
}
writeBody();
finalizeWriting();
// if all succeeded with writing/recording grades, log active usage
logDailyPing();
return status;
// Private functions.
function initializeWriting()
{
Debug.assert(self.grades_sheet !== null,
"GradesWorksheet.writeGradesSheet.initializeWriting() - " +
"no grades sheet");
// Get the first graded submission from the sumissions sheet. This
// also initiaises the process of reading the submissions later on.
first_graded_subm = self.getFirstGradedSubmission();
Debug.info("initializeWriting() - first_graded_subm = " + first_graded_subm);
// Add 1 to allow for the header.
submissions_start_row = gbl_grades_start_row_num + 1;
// Calculate where the footer rows will start
next_footer_row = submissions_start_row +
self.getNumGradedSubmissions() +
1 +
gbl_num_space_before_hidden;
Debug.info("GradesWorksheet.writeGradesSheet.initializeWriting() - " +
"next_footer_row: " +
next_footer_row);
if (grades_sheet_update_type != GRADES_SHEET_UPDATE_TYPE_REGEN)
{
Debug.info("GradesWorksheet.writeGradesSheet.initializeWriting() - " +
"Updating num_graded_subm_written and next_footer_row for insert case");
// We are inserting new entries, rather than regenerating the whole Grades sheet.
// So update/ffwd 'num_graded_subm_written' to the value it would have been
// had we actually just written the graded rows already present.
num_graded_subm_written = self.getNumGradedSubmissions();
// Also pretend that we've inserted all the footer rows already present
next_footer_row += gbl_num_hidden_rows + num_graded_subm_written;
// don't continue unless regenerating the entire Grades sheet
return;
}
// Hide the columns containing student feedback and the offset of this
// question stored in the footer.
var metric_start_col = self.num_student_identifiers + 2;
var feedback_col_num = metric_start_col + METRIC_STUDENT_FEEDBACK;
self.grades_sheet.hideColumns(feedback_col_num);
var subm_copy_row_index_col_num = metric_start_col + METRIC_SUBM_COPY_ROW_INDEX;
self.grades_sheet.hideColumns(subm_copy_row_index_col_num);
dp.setProperty(DOC_PROP_STUDENT_FEEDBACK_HIDDEN, "true");
} // GradesWorksheet.writeGradesSheet.initializeWriting()
// Nested function to write the grade sheet header.
function writeHeader()
{
// Create an area at the top of this sheet where the grades
// summary will go after grading is done.
setCellValue(self.grades_sheet, 2, 1, langstr("FLB_STR_GRADE_SUMMARY_TEXT_SUMMARY") + ":");
self.grades_sheet.getRange(2, 1, 1, 1).setFontWeight("bold");
setCellValue(self.grades_sheet, GRADES_SUMMARY_PTS_POSSIBLE_ROW_NUM, 1, langstr("FLB_STR_GRADE_SUMMARY_TEXT_POINTS_POSSIBLE"));
setCellValue(self.grades_sheet, GRADES_SUMMARY_AVG_PTS_ROW_NUM, 1, langstr("FLB_STR_GRADE_SUMMARY_TEXT_AVERAGE_POINTS"));
setCellValue(self.grades_sheet, GRADES_SUMMARY_COUNTED_SUBM_ROW_NUM, 1, langstr("FLB_STR_GRADE_SUMMARY_TEXT_COUNTED_SUBMISSIONS"));
setCellValue(self.grades_sheet, GRADES_SUMMARY_LOW_SCORE_ROW_NUM, 1, langstr("FLB_STR_GRADE_SUMMARY_TEXT_NUM_LOW_SCORING"));
// Add a formula in cell A1 that determines where the hidden rows start.
// This is needed to locate the hidden rows, and is better than a static calculation
// which would break if the user deleted some rows in the Grades sheet (which happens often).
gwsInsertHiddenRowLocatorFormula(self.grades_sheet, self.num_student_identifiers);
if (first_graded_subm.hasCategories())
{
var categories_row = first_graded_subm.createRowForGradesSheet(GRADES_OUTPUT_ROW_TYPE_CATEGORY_NAMES,
GRADES_CATEGORY_NAMES_ROW_NUM);
writeArrayToRow(self.grades_sheet, GRADES_CATEGORY_NAMES_ROW_NUM, 1, categories_row, "italic", "");
}
Debug.info("writeHeader - creating questions header. first_graded_subm = " + first_graded_subm);
var headers = first_graded_subm.createRowForGradesSheet(GRADES_OUTPUT_ROW_TYPE_QUESTIONS_HEADER,
gbl_grades_start_row_num);
var col_num;
var col_ltr;
var col_range;
var rg;
var cols_to_format = gwsCheckForFormattedCellsInRow(headers);
Debug.info(cols_to_format);
writeArrayToRow(self.grades_sheet, gbl_grades_start_row_num, 1, headers, "bold", "");
// apply special formatting to any columns in 'cols_to_format'
for (var c=0; c < cols_to_format.length; c++)
{
col_num = cols_to_format[c].col_num;
var col_format = cols_to_format[c].col_format;
col_ltr = convertColNumToColLetter(col_num);
col_range = col_ltr + gbl_grades_start_row_num + ":" + col_ltr;
rg = self.grades_sheet.getRange(col_range);
if (col_format == FLB_COLFORMAT_GREY_ITALIC_TEXT)
{
rg.setFontColor("#999999");
rg.setFontStyle("italic");
}
else if (col_format == FLB_COLFORMAT_HIDDEN)
{
self.grades_sheet.hideColumns(col_num);
}
else if (col_format == FLB_COLFORMAT_WRAP_TEXT)
{
rg.setWrap(true);
}
}
// turn on word wrap on the header rows.
var wr = self.grades_sheet.getRange(1, 1, gbl_grades_start_row_num, headers.length);
wr.setWrap(true);
// format the entire percent column to show 0.00%
col_num = 1 + self.num_student_identifiers + 1 + 1;
col_ltr = convertColNumToColLetter(col_num);
col_range = col_ltr + ":" + col_ltr;
rg = self.grades_sheet.getRange(col_range);
rg.setNumberFormat("0.00%");
// format the entire timestamp column to show date + time (starting at row 2)
col_ltr = "A";
col_range = col_ltr + "2:" + col_ltr;
rg = self.grades_sheet.getRange(col_range);
rg.setNumberFormat("MM/d/yyyy H:mm:ss");
Debug.info("writeHeader - done creating questions header.");
} // GradesWorksheet.writeGradesSheet.writeHeader()
// Nested function to write the grade sheet footer.
function writeFooter()
{
// Write out some rows at the bottom of the grades sheet for internal
// data processing. These include information like the grading options
// and the answer key values. This information is referenced later when
// doing things like emailing grades, creating reports, etc. It will
// usually be hidden from the user.
Debug.info("writeFooter - creating footer.");
Debug.info("writeFooter - creating footer for GRADES_OUTPUT_ROW_TYPE_GRADING_OPT.");
writeArrayToRow(self.grades_sheet,
next_footer_row,
1,
first_graded_subm.createRowForGradesSheet(GRADES_OUTPUT_ROW_TYPE_GRADING_OPT, next_footer_row++),
"",