-
Notifications
You must be signed in to change notification settings - Fork 0
/
TSRs.gs
122 lines (105 loc) · 3.21 KB
/
TSRs.gs
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
const TSRS_SHEET = 'TSRs';
const TSRS_RANGE_WITHOUT_EXTRA_START = 'B2:E';
const TSRS_RANGE_START = 'B2:G';
const TSR_HEADER = [['Name', 'Ldap', 'Site', 'Shard', 'Specialization', 'Reviewer assign']];
const TSR_HEADER_RANGE = 'B1:G1';
const TSR_SCHEMA = ['name', 'ldap', 'site', 'shard', 'specialization', 'reviewer'];
const TSR_SPECIALIZATION_RANGE = 'F2:F';
const TSR_REVIEWER_RANGE = 'G2:G';
function generateTSRs() {
exportTSRs_();
generateTSRHeaderAndRules_();
}
function exportTSRs_() {
let {preMap, externalList} = cachePreTSRSetting_();
Logger.log(preMap);
Logger.log(externalList);
Utils.clear(TSRS_SHEET, Utils.makeRangeWithoutLastRow(TSRS_SHEET, TSRS_RANGE_START));
tsrs = SchedulesProvider.getTSRs(SITE, SHARD);
raws = [];
tsrs.forEach(
tsr => {
raw = [];
raw.push(tsr.name);
raw.push(tsr.ldap);
raw.push(tsr.site);
raw.push(tsr.shard);
raw.push(getTSRSpecialization_(tsr, preMap));
raw.push(getTSRReviewer_(tsr, preMap));
raws.push(raw);
}
);
addExternalList_(raws, externalList);
Logger.log(raws);
Utils.exportRawDataToSheet(TSRS_SHEET, TSRS_RANGE_START + (raws.length + 1), raws);
}
function generateTSRHeaderAndRules_() {
generateTSRHeader_();
if (SpreadsheetApp.getActiveSpreadsheet().getSheetByName(TSRS_SHEET).getLastRow() > 0) {
generateTSRSpecializationRules_();
generateReviewerRules_(SITE, SHARD, TSRS_SHEET, TSR_REVIEWER_RANGE + SpreadsheetApp.getActiveSpreadsheet().getSheetByName(TSRS_SHEET).getLastRow());
}
}
function getTSRSpecialization_(tsr, preMap) {
if (preMap.has(tsr.ldap)) {
return preMap.get(tsr.ldap).specialization;
} else {
return '';
}
}
function getTSRReviewer_(tsr, preMap) {
if (preMap.has(tsr.ldap)) {
return preMap.get(tsr.ldap).reviewer;
} else {
return '';
}
}
function generateTSRHeader_() {
Utils.exportRawDataToSheet(TSRS_SHEET, TSR_HEADER_RANGE, TSR_HEADER);
}
function generateTSRSpecializationRules_() {
Utils.generateRules(TSRS_SHEET, TSR_SPECIALIZATION_RANGE + SpreadsheetApp.getActiveSpreadsheet().getSheetByName(TSRS_SHEET).getLastRow(), SPECIALIZATION_LIST);
}
function generateReviewerRules_(site, shard, sheet, range) {
smes = SchedulesProvider.getSMEs(site, shard);
ldap = [];
smes.forEach(
sme => {
ldap.push(sme.ldap);
}
);
Utils.generateRules(sheet, range, ldap);
}
function addExternalList_(raws, externalList) {
externalList.forEach(
raw => {
raws.push(raw);
}
);
}
function cachePreTSRSetting_() {
let preraws = [];
try {
preraws = Utils.getValues(TSRS_SHEET, Utils.makeRangeWithoutLastRow(TSRS_SHEET, TSRS_RANGE_START));
} catch (e) {
Logger.log('cachePreTSRSetting_:' + e);
}
let preMap = new Map();
let externalList = [];
preraws.forEach(
raw => {
// Logger.log(raw[1] + " " + raw[3] + " " + raw[4]);
preMap.set(raw[1], {
specialization: raw[4],
reviewer: raw[5]
});
if (!Utils.compareStrIgnoreCases(raw[2], SITE)) {
externalList.push(raw);
}
}
);
return {preMap, externalList};
}
function getTSRs_() {
return Utils.convertRawsToJsons(Utils.getValues(TSRS_SHEET, Utils.makeRangeWithoutLastRow(TSRS_SHEET, TSRS_RANGE_START)), TSR_SCHEMA);
}