-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticipants.js
873 lines (778 loc) · 24.3 KB
/
participants.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
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
//
// Participants script.
// Provides functionality to take participants and spread them across
// spreadsheets for each tutorial group.
//
// :project: gdit_gdocs
// :author: meisterluk
// :date: 11.10.14
// :version: 1.0.0public
// :license: LGPLv3
//
//----------------------------------------------------------------------
// GLOBAL CONFIGURATION
//----------------------------------------------------------------------
SOURCE_SHEET_STUD = 'Studierende';
SOURCE_SHEET_TUTS = 'Tutoren';
SOURCE_STUD_MATRNR_COL = 2;
SOURCE_TUTS_MATRNR_COL = 8;
SOURCE_STUD_TWNAME_COL = 5;
SOURCE_TUTS_TWNAME_COL = 7;
// inputBoxes do not allow default values. This var cannot be used.
//COPY_SPREADSHEET = "[GDIT] Gruppe N";
BASENAME_GROUP_SSS = '[GDIT] Gruppe %d WSXX';
// shall I add tutors as collaborators automatically?
SET_PERMISSIONS = false;
// data structure to store students & tutors
data = {'students' : [], 'tutors' : {}, 'groups' : [], 'email' : {}};
//----------------------------------------------------------------------
// LIBRARY
//----------------------------------------------------------------------
//
// String trim function. Removes whitespace characters at beginning and
// end of string.
//
// @param string string the string to trim
// @return string the trimmed string
//
function trim(string)
{
string = string.replace(/^\s+/, '');
return string.replace(/\s+$/, '');
}
//
// Get the real content of a cell.
// Note. This function *always* returns strings.
//
// @param cell_value string the cell value to parse
// @return string the real content of the cell
//
function content(cell_value)
{
if (typeof(cell_value) !== "string")
return cell_value;
return trim(cell_value.toString());
}
//
// A bad quick & dirty (probably not perfectly working) hack to check
// whether or not object is empty.
//
// @param obj object the object to check for properties
// @return bool is object empty?
//
function isEmpty(obj)
{
for (var attr in obj) {
if (obj.hasOwnProperty(attr))
return false;
}
return true;
}
//
// Extend Array for membership testing method
// Note. Google Apps script does not allow overloading prototypes,
// therefore this is a stupid function for prefix notation.
//
// @param parameter array the array
// @param value object some element
// @return bool does value exist in parameter?
//
function contains(parameter, value)
{
// some evil test for array property
if (parameter instanceof Array)
{
for (var i=0; i<parameter.length; i++)
if (parameter[i] == value)
return true;
} else { // assumption, it's an object
for (var index in parameter)
if (index == value)
return true;
}
return false;
}
//
// Returns the corresponding letter (A1 notation) for a column index.
// Note. Currently A--ZZ is supported.
// Example:
// >>> columnId(3)
// "C"
//
// @param column_index int the column index to use
// @return string the column ID in A1 notation
//
function columnId(column_index)
{
if (column_index === 0) // column_index are one-based.
{
Logger.log("columnId(0) called. 0 is an invalid parameter");
return '!';
}
if (column_index > 0 && column_index < 27)
return String.fromCharCode(64 + column_index);
else if (column_index > 26 && column_index < 703)
{
column_index -= 26;
var first_letter = 1;
var second_letter = 0;
for (; column_index>26; column_index-=26)
first_letter += 1;
second_letter = column_index;
return String.fromCharCode(64 + first_letter)
+ String.fromCharCode(64 + second_letter);
} else
return String.fromCharCode(65);
}
//----------------------------------------------------------------------
// FUNCTIONALITY
//----------------------------------------------------------------------
//
// Remove "Copy of" label in sheet names when they get duplicated.
//
// @param sheetname string the sheet name
// @return string the sheetname without "Copy of" text
//
function getOriginalSheetname(sheetname)
{
return sheetname.replace(/^(Copy of|Kopie von)\s?/, "");
}
//
// Insert group_id into basename for Evaluation Spreadsheets.
//
// @param basename string the basename to use
// @param group_id int the group_id to use
// @return string specify spreadsheet name
//
function specifyGroup(basename, group_id)
{
return basename.toString().replace(/%d/, group_id.toString());
}
//
// Return the exercise name for a specific exercise.
// Each assignment has a special name. For example, the first one
// is called "AufgabeEins". This function maps the exercise_number
// to the name.
//
// @param exercise_number int the exercise number to get string for
// @return string the corresponding exercise name.
//
function exercise_name(exercise_number)
{
if (exercise_number < 1 || exercise_number > 10) {
Logger.log("exercise_name(" + exercise_number + ") called. " +
"Invalid parameter");
return "None";
}
title = "Aufgabe";
switch (exercise_number) {
case 1: title += "Eins"; break;
case 2: title += "Zwei"; break;
case 3: title += "Drei"; break;
case 4: title += "Vier"; break;
case 5: title += "Fünf"; break;
case 6: title += "Sechs"; break;
case 7: title += "Sieben"; break;
case 8: title += "Acht"; break;
case 9: title += "Neun"; break;
case 10: title += "Zehn"; break;
}
return title;
}
//
// Because spreadsheets are identified by ID and not name, multiple
// spreadsheets can have the same name. Therefore GDocs does not provide
// a getSpreadsheetByName function for SpreadsheetApp. However, here we
// have an evil hack to use this functionality anyway.
//
// @param name string the name to search for
// @return null|Spreadsheet null on error or Spreadsheet instance
//
function getSpreadsheetByName(name)
{
var docs = new Array();
docs = DocsList.getFilesByType("spreadsheet");
for (var doc in docs)
{
if (docs[doc].getName() === name)
{
// docs[doc] contains File instance
var id = docs[doc].getId();
// get Spreadsheet instance
return SpreadsheetApp.openById(id);
}
}
return null;
}
//
// Levenshtein distance calculation
// via phpjs
// http://phpjs.org/functions/levenshtein:463
//
// @param s1 string first string
// @param s2 string second string to calculate similarity of
// @return int
//
function levenshtein(s1, s2)
{
if (s1 == s2) {
return 0;
}
var s1_len = s1.length;
var s2_len = s2.length;
if (s1_len === 0) {
return s2_len;
}
if (s2_len === 0) {
return s1_len;
}
var split = false;
try {
split = !('0')[0];
} catch (e) {
split = true; // Earlier IE may not support access by string index
}
if (split) {
s1 = s1.split('');
s2 = s2.split('');
}
var v0 = new Array(s1_len + 1);
var v1 = new Array(s1_len + 1);
var s1_idx = 0,
s2_idx = 0,
cost = 0;
for (s1_idx = 0; s1_idx < s1_len + 1; s1_idx++) {
v0[s1_idx] = s1_idx;
}
var char_s1 = '',
char_s2 = '';
for (s2_idx = 1; s2_idx <= s2_len; s2_idx++) {
v1[0] = s2_idx;
char_s2 = s2[s2_idx - 1];
for (s1_idx = 0; s1_idx < s1_len; s1_idx++) {
char_s1 = s1[s1_idx];
cost = (char_s1 == char_s2) ? 0 : 1;
var m_min = v0[s1_idx + 1] + 1;
var b = v1[s1_idx] + 1;
var c = v0[s1_idx] + cost;
if (b < m_min) {
m_min = b;
}
if (c < m_min) {
m_min = c;
}
v1[s1_idx + 1] = m_min;
}
var v_tmp = v0;
v0 = v1;
v1 = v_tmp;
}
return v0[s1_len];
}
//
// String1 looks like string2?
//
// @param string1 string first string to compare with second
// @param string2 string second string
// @return bool shall I consider string1 to be similar to string2?
//
function stringSimilar(string1, string2)
{
var sensitivity = 3; // levensthein distance sensitivity
return levenshtein(string1, string2) < sensitivity;
}
//
// Number1 looks like number2?
// Note. levenshtein for numbers :-P
//
// @param number1 int first number to compare with second
// @param number2 int second number
// @return bool shall I consider number1 to be similar to number2?
//
function numberSimilar(number1, number2)
{
if (number1 === number2)
return true;
/*if(number1- (Math.pow(10, 4) * parseInt(number1/10000)) === number2)
return true;*/
if (number1 > 1000)
{
var num1 = String(number1);
var num2 = String(number2);
if (num1.length < num2.length)
{
var tmp = num1;
num1 = num2;
num2 = tmp;
}
for (var i=-num1.length+1; i<num1.length; i++)
{
if (i > 0)
{
if (num1.substr(0, i).length > 3 && num1.substr(0, i) === num2)
return true;
} else if (i < 0) {
if (num1.substr(i).length > 3 && num1.substr(i) === num2)
return true;
}
}
}
return false;
}
//
// Search for a student by Matriculation number
// Note. Calls an InputBox to request parameter
// Note. Points focus to search result or shows error message.
//
function searchMatrNr()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getDataRange();
var identifier = Browser.inputBox("Suche nach Matrnr: ");
var found = false;
if (identifier === "cancel")
return;
identifier = parseInt(identifier.toString().replace(/[^0-9]/g, ''));
if (identifier === "cancel") {
return true;
} else if (isNaN(identifier)) {
Browser.msgBox("Es wurde keine Zahl eingegeben");
return searchMatrNr();
} else {
var base_spreadsheet = sheet;
// for students sheet
var sheet = ss.getSheetByName(SOURCE_SHEET_STUD);
if (sheet === null)
{
Browser.msgBox("Studenten sheet konnte leider nicht gefunden "
+ "werden :-(");
return false;
}
range = sheet.getDataRange();
for (var row=5; row<=range.getLastRow(); row++)
{
var val = range.getCell(row, SOURCE_STUD_MATRNR_COL).getValue();
val = parseInt(val.toString().replace(/[^0-9]/g, ''));
if (!isNaN(val) && numberSimilar(val, identifier))
{
sheet.setActiveCell(range.getCell(row, SOURCE_STUD_MATRNR_COL));
found = true;
break;
}
}
// for tutors sheet
var sheet = ss.getSheetByName(SOURCE_SHEET_TUTS);
if (sheet === null)
{
Browser.msgBox("Tutoren sheet konnte leider nicht gefunden "
+ "werden :-(");
ss.setActiveSheet(base_spreadsheet);
return false;
}
range = sheet.getDataRange();
for (var row=5; row<=range.getLastRow(); row++)
{
var val = range.getCell(row, SOURCE_TUTS_MATRNR_COL).getValue();
val = parseInt(val.toString().replace(/[^0-9]/g, ''));
if (!isNaN(val) && numberSimilar(val, identifier))
{
sheet.setActiveCell(range.getCell(row, SOURCE_TUTS_MATRNR_COL));
found = true;
break;
}
}
}
if (!found)
{
ss.setActiveSheet(base_spreadsheet);
Browser.msgBox("Nicht gefunden! :-(");
}
}
//
// Search for a student by Matr.nr. or TwikiName
// Note. Calls an InputBox to request parameter
// Note. Points focus to search result or shows error message.
//
function searchTwikiName()
{
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var range = sheet.getDataRange();
var identifier = Browser.inputBox("Suche nach TwikiName: ");
var found = false;
if (identifier === "cancel")
return;
identifier = identifier.toString().replace(/\s+/, '').toLowerCase();
var base_spreadsheet = sheet;
// for students sheet
var sheet = ss.getSheetByName(SOURCE_SHEET_STUD);
if (sheet === null)
{
Browser.msgBox("Studierende Sheet konnte leider nicht gefunden "
+ "werden :-(");
return false;
}
range = sheet.getDataRange();
for (var row=5; row<=range.getLastRow(); row++)
{
var val = range.getCell(row, SOURCE_STUD_TWNAME_COL).getValue();
val = val.toString().replace(/\s+/,'').toLowerCase();
if (stringSimilar(val, identifier))
{
sheet.setActiveCell(range.getCell(row, SOURCE_STUD_TWNAME_COL));
found = true;
break;
}
}
// for tutors sheet
var sheet = ss.getSheetByName(SOURCE_SHEET_TUTS);
if (sheet === null)
{
Browser.msgBox("Tutoren sheet konnte leider nicht gefunden "
+ "werden :-(");
ss.setActiveSheet(base_spreadsheet);
return false;
}
range = sheet.getDataRange();
for (var row=5; row<=range.getLastRow(); row++)
{
var val = range.getCell(row, SOURCE_TUTS_TWNAME_COL).getValue();
val = val.toString().replace(/\s+/,'').toLowerCase();
if (stringSimilar(val, identifier))
{
sheet.setActiveCell(range.getCell(row, SOURCE_TUTS_TWNAME_COL));
found = true;
break;
}
}
if (!found)
Browser.msgBox("Nicht gefunden! :-(");
}
//
// Domain-specific function to create query to calculate total points.
//
// @param sheet Sheet the Sheet to read data from
// @param spec_col int the index of the column with points
// @param col int the index of the column we are creating for
// @param start int the first row to look for data
// @param end int the last row to look for data
// @param bonus int the row ID with the bonus value
// @return string the formula query to calculate total points
//
function createTpointsQuery(sheet, spec_col, col, start, end, bonus)
{
try {
// CTQ_ROWS_CACHE holds all row indizes with all points for the
// various exercises.
CTQ_ROWS_CACHE;
if (CTQ_SHEET !== sheet.getName())
throw("Is different sheet. Update cache, please.");
} catch (err) {
// if CTQ_ROWS_CACHE is undefined
CTQ_ROWS_CACHE = [];
var range = sheet.getRange(1, 1, end, spec_col);
for (var row=start; row<=end; row++)
{
if (typeof(range.getCell(row, spec_col).getValue()) === "number")
{
CTQ_ROWS_CACHE.push(row);
}
}
CTQ_SHEET = sheet.getName();
}
var rows = [];
for (var index in CTQ_ROWS_CACHE)
{
var row = CTQ_ROWS_CACHE[index];
rows.push("IF(" + columnId(col) + row + '="x",1,0)*$'
+ columnId(spec_col) + "$" + row);
}
rows.push(columnId(col) + bonus);
return '=SUM(' + rows.join(', ') + ')';
}
//----------------------------------------------------------------------
// CALLBACK
//----------------------------------------------------------------------
//
// Generate callback to invoke generation of spreadsheets per group.
function generate()
{
var base = Browser.inputBox("Name des Spreadsheets von dem das "
+ "Layout kopiert wird: ");
if (base === "cancel")
return;
var ss = getSpreadsheetByName(base);
if (ss === null)
{
Browser.msgBox("Konnte Spreadsheet nicht finden :-(");
return false;
}
readData();
generateSpreadsheets(ss);
}
//
// Read data to be used in spreadsheet generation
// Note. Modifies the global data variable.
//
function readData()
{
var group_col = 1;
var matrnr_col = 2;
var fname_col = 3;
var sname_col = 4;
var tname_col = 5;
var base_path = [3, 2];
var first_students_row = 5;
var first_tutors_row = 4;
var tut_group_col = 1;
var tut_fname_col = 7;
var tut_sname_col = 6;
var tut_mail_col = 12;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName(SOURCE_SHEET_STUD);
var range = sheet.getDataRange();
// read data[meta]
data['meta'] = [];
for (var col=2; col<5; col++)
{
var value = content(range.getCell(1, col).getValue());
if (value)
data['meta'].push(value);
}
// read data[base]
data['base'] = content(range.getCell(base_path[0], base_path[1])
.getValue());
// read students & groups
data['students'] = [];
var start = Math.min(group_col, matrnr_col, fname_col, sname_col,
tname_col);
var end = Math.max(group_col, matrnr_col, fname_col, sname_col,
tname_col);
for (var row=first_students_row; row<=range.getLastRow(); row++)
{
// skip empty lines
if (content(range.getCell(row, matrnr_col).getValue()) === "")
continue;
var student = {};
for (var col=start; col<=end; col++)
{
var value = content(range.getCell(row, col).getValue());
switch (col)
{
case group_col:
student['group'] = parseInt(value);
break;
case matrnr_col:
student['matrnr'] = parseInt(value);
break;
case fname_col:
student['name'] = value;
break;
case sname_col:
student['second_name'] = value;
break;
case tname_col:
student['twiki_name'] = value;
break;
default:
// skip it
}
}
if (!contains(data['groups'], student['group']))
data['groups'].push(student['group']);
if (!isEmpty(student))
data['students'].push(student);
}
// read tutors
var sheet_tuts = ss.getSheetByName(SOURCE_SHEET_TUTS);
var range = sheet_tuts.getDataRange();
data['tutors'] = {};
data['email'] = {};
for (var row=first_tutors_row; row<=range.getLastRow(); row++)
{
var group = content(range.getCell(row, tut_group_col).getValue());
var fname = content(range.getCell(row, tut_fname_col).getValue());
var sname = content(range.getCell(row, tut_sname_col).getValue());
var email = content(range.getCell(row, tut_mail_col).getValue());
if (group === "" || typeof(group) !== "number")
continue; // skip empty line
data['tutors'][group] = sname + " " + fname;
data['email'][group] = email;
}
// remove groups without tutor
var limit = 3; // show 3 messages at maximum.
var groups = []; // a whitelist
for (var _ in data['groups'])
{
var group = data['groups'][_];
if (data['tutors'][group] === undefined)
{
if (limit-- > 0)
Browser.msgBox("Gruppe " + group + " hat keinen Tutor. Ein "
+ "Spreadsheet für diese Gruppe wird nicht erzeugt");
Logger.log("Missing tutor for group #" + group);
} else {
groups.push(group);
}
}
data['groups'] = groups;
// Checks
if (data['groups'].length === 0)
Browser.msgBox("Ich konnte gar keine Gruppen finden?!");
if (data['students'].length === 0)
Browser.msgBox("Ich konnte keine Studenten finden :-(");
return true;
}
function generateSpreadsheets(base_ss)
{
// TODO: These fields require a better usability design
// Benotung Spreadsheet
var ben_first_student_row = 3;
var ben_group_col = 1;
var ben_matrnr_col = 2;
var ben_name_col = 3;
var ben_sname_col = 4;
var ben_tname_col = 5;
var ben_first_ex_col = 10;
var ben_last_ex_col = 12;
var ben_totalpoints_col = 14;
var ben_mark_col = 15;
// Exercise(s) Spreadsheet
var total_points = [[46, 4], [49, 4], [78, 4]]; // row numbers
var bonus = [47, 50, 79];
var write = [43, 46, 75]; // Row of total points formula
var spec_col = 3;
var first_student_col = 4;
var twiki_name_row = 1;
var matrnr_row = 2;
for (var g_index in data['groups'])
{
var group = data['groups'][g_index];
var ss_name = specifyGroup(BASENAME_GROUP_SSS, group);
var ss = SpreadsheetApp.create(ss_name);
if (SET_PERMISSIONS)
{
var rights_config = {editorAccess: true, emailInvitations: false};
ss.addCollaborators(data['email'][group], rights_config);
}
// get sheets & - names
var sheets = base_ss.getSheets();
var sheet_names = [];
for (var s_index in sheets)
sheet_names.push(sheets[s_index].getName());
for (var index in sheets)
{
var sheet = sheets[index].copyTo(ss);
sheet.setName(getOriginalSheetname(sheet.getName()));
if (content(sheet.getName()) === "Benotung")
{
// write Benotungssheet data
var range = sheet.getRange(1, 1,
data['students'].length + ben_first_student_row, 17);
var gs_counter = 0; // student in group counter
for (var s_index in data['students'])
{
if (data['students'][s_index]['group'] !== group)
continue;
var row = gs_counter + ben_first_student_row;
range.getCell(row, ben_group_col)
.setValue(data['students'][s_index]['group']);
range.getCell(row, ben_matrnr_col)
.setValue(data['students'][s_index]['matrnr']);
range.getCell(row, ben_name_col)
.setValue(data['students'][s_index]['name']);
range.getCell(row, ben_sname_col)
.setValue(data['students'][s_index]['second_name']);
range.getCell(row, ben_tname_col)
.setValue(data['students'][s_index]['twiki_name']);
for (var col=ben_first_ex_col; col<=ben_last_ex_col; col++)
{
var sheet_ref = sheet_names[col - ben_first_ex_col + 1];
var ex_ref = col - ben_first_ex_col;
var reference = "'" + sheet_ref + "'!"
+ columnId(total_points[ex_ref][1]
+ gs_counter)
+ write[ex_ref];
range.getCell(row, col).setFormula("=IF(" + reference
+ "<0,0," + reference + ")");
}
range.getCell(row, ben_totalpoints_col)
.setFormula("=SUM(" + columnId(ben_first_ex_col) + row
+ ":" + columnId(ben_last_ex_col) + row + ")");
range.getCell(row, ben_mark_col)
.setFormula("=IF(ISERR(pointsToMark("
+ columnId(ben_totalpoints_col) + col + ')), "?", '
+ 'pointsToMark(' + columnId(ben_totalpoints_col)
+ col + '))');
gs_counter++;
}
} else {
// write exercisesheet data
var range = sheet.getRange(1, 1, sheet.getLastRow(),
first_student_col + data['students'].length - 1);
var gs_counter = 0; // student in group counter
for (var s_index in data['students'])
{
if (data['students'][s_index]['group'] !== group)
continue;
var col = first_student_col + gs_counter;
var ref_t = "'Benotung'!" + columnId(ben_tname_col)
+ (ben_first_student_row + gs_counter);
var ref_m = "'Benotung'!" + columnId(ben_matrnr_col)
+ (ben_first_student_row + gs_counter);
range.getCell(twiki_name_row, col).setFormula
('=HYPERLINK(CONCATENATE("' + data['base'] + '", ' + ref_t +
', "Solo' + index + '"), ' + ref_t + ')');
range.getCell(matrnr_row, col).setFontWeight("bold");
var exercise_number = parseInt(sheet.getName().match(/\d+/)[0]);
var start = Math.max(twiki_name_row, matrnr_row);
var tpts = total_points[exercise_number-1];
var formula = createTpointsQuery(sheet, spec_col, col, start,
tpts[0], bonus[exercise_number-1]);
// <hack>
if (exercise_number >= 2) {
var value_ = '=HYPERLINK(CONCATENATE("' + data['base']
+ '", ' + ref_t + ', "Partner' + index
+ '"), ' + ref_m + ')';
range.getCell(matrnr_row, col).setFormula(value_);
} else {
// matriculation number
range.getCell(matrnr_row, col).setFormula('=' + ref_m);
}
// </hack>
range.getCell(write[exercise_number-1],
tpts[1] + gs_counter).setFormula(formula);
gs_counter++;
}
}
// delete default sheet
var default_sheet = ss.getSheetByName("Sheet1");
if (default_sheet !== null)
{
ss.setActiveSheet(default_sheet);
ss.deleteActiveSheet();
}
}
Browser.msgBox("Spreadsheet für Gruppe " + group + " erzeugt");
}
Browser.msgBox("Spreadsheets erzeugt :)");
}
//
// Trigger on document opening
//
function onOpen()
{
// Add a search menu.
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntriesGenerate = [
{name: "Generiere Bewertungsspreadsheet pro Gruppe",
functionName: "generate"}
];
var menuEntriesSearch = [
{name: "Nach Matrikelnummer", functionName: "searchMatrNr"},
{name: "Nach Twikiname", functionName: "searchTwikiName"}
];
ss.addMenu("Generieren", menuEntriesGenerate);
ss.addMenu("Suche", menuEntriesSearch);
}