-
Notifications
You must be signed in to change notification settings - Fork 0
/
checks.gs
318 lines (280 loc) · 11.4 KB
/
checks.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
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
function paymentofevaluators(){
//🚨🚨 Il faut un backoffice pour savoir quand et combien de personnes on a payé
}
function relancequestionnaires(){
//We need to send the forms 3 times in order to maximise de probability of response
var vudbsheet = SpreadsheetApp.openById(getdbbyname("formvu")).getSheets()[0];
var sheetlastRow = vudbsheet.getLastRow();
var vuvalues = vudbsheet.getRange(2,1,sheetlastRow-1,14).getValues();
//I don't take into account if I have already sent it to a person / he has already answerd / I had sufficient persones because :
//- Those who didn't answer before will be willing to answer
//- Those who answered will know that the VU is still ongoing and that's why they haven't been payed
//- If I had insufficient persons before it doesn't mean that I still have insufficient amount of persons now
//Start Config
var configvu = [];
configvu["datedebut"] = 10;
configvu["datedefin"] = 11;
configvu["requestid"] = 12;
configvu["requestid"] = 13;
vuvalues.forEach(function(row){
if (parseInt(row[configvu["requestid"]])<2){//I check the request that are not done yet
var debut = row[configvu["datedebut"]];
var fin = row[configvu["datedefin"]];
var timeDifftotal = Math.ceil((Math.abs(fin.getTime() - debut.getTime())) / (1000 * 3600 * 24)); //We take the total amount of days allowed
var teorical = parseInt(80/100*timeDifftotal); //we take the first 80% of the time to re-send the emails. Afterwards the chances of success are low
var step = parseInt(teorical/4); //we calculate the day inverval that will allow to send 4 emails in total
var now = new Date();
var timeDiffpartial = Math.ceil((Math.abs(now.getTime() - debut.getTime())) / (1000 * 3600 * 24));
if (timeDiffpartial%step == 0){ //the day interval has been obtained
SendForms(row[configvu["requestid"]]);
};
}
});
}
function requestsdone(){
//Check if all the forms of a request have been finished and mark the request as done
var vudbsheet = SpreadsheetApp.openById(getdbbyname("formvu")).getSheets()[0];
var sheetlastRow = vudbsheet.getLastRow();
var vuvalues = vudbsheet.getRange(2,1,sheetlastRow-1,14).getValues();
//Start Config
var configvu = [];
configvu["resquestid"] = 12;
configvu["status"] = 13;
//I choose the requests that are not already done
var requests = [];
vuvalues.forEach(function(row){
if (requests.indexOf(row[configvu["resquestid"]]) === -1 && row[configvu["resquestid"]] != "2") {
requests.push(row[configvu["resquestid"]]);
}
});
//Forms Database
var fdbsheet = SpreadsheetApp.openById(getdbbyname("formdb")).getSheets()[0];
var sheetlastRow = fdbsheet.getLastRow();
var values = fdbsheet.getRange(4,1,sheetlastRow-3,15).getValues();
//Start Config
var configform = [];
configform["resquestid"] = 1;
configform["status"] = 14;
var done = [];
requests.forEach(function(request){
var add = true;
values.forEach(function(row){
if(row[configform["resquestid"]] == request && row[configform["status"]] != "3" && add == true){
add = false;
}
},request,add);
if (add){
done.push(request)
}
},values);
done.forEach(function(requestid){
enum = 2;
vuvalues.forEach(function(row){
if(row[configvu["resquestid"]] == requestid){
vudbsheet.getRange(enum,configvu["status"]+1).setValue(2);
sendtoslack("📢📢 L'évaluation d'une application est finie");
}
enum++;
},enum,requestid,vudbsheet,enum,configvu);
},vuvalues,vudbsheet,configvu);
}
function checkenoughevaluators(){
//Check that we have enough evaluators for an app
var dbid = getdbbyname("formdb"); //Forms Database
var fdbsheet = SpreadsheetApp.openById(dbid).getSheets()[0];
var sheetlastRow = fdbsheet.getLastRow();
var values = fdbsheet.getRange(4,1,sheetlastRow-3,14).getValues();
//Start Config
var configvu = [];
configvu["resquestid"] = 1;
configvu["needresponse"] = 11;
configvu["emailsent"] = 12;
//End Config
var buffer = [];
values.forEach(function(row){
if(parseInt(row[configvu["emailsent"]]) < parseInt(row[configvu["needresponse"]])){
//The emails sent < response needed (so it's likely that we will never be able to have a good evaluation
if (buffer.indexOf(row[configvu["resquestid"]]) === -1) {
//I return an array of all the resquest id's that have problematic forms
buffer.push(row[configvu["resquestid"]]);
}
}
},buffer);
if (buffer.length > 0){
sendtoslack("🚨🚨 Il n'y a pas suffisamment d'évaluateurs pour répondre à une demande de VU");
}
return buffer;
}
function checkduplicateevaluators(){
//Check the duplicates in GP evaluators based on their email
removeduplicates(getdbbyname("gpdb"),0,2,5);
//Check the duplicates in GP evaluators based on their RIB
removeduplicates(getdbbyname("gpdb"),0,2,12);
//Check the duplicates in PDS evaluators based on their email
removeduplicates(getdbbyname("pdsdb"),0,2,4);
//Check the duplicates in PDS evaluators based on their RIB
removeduplicates(getdbbyname("pdsdb"),0,2,12);
}
function suscribedevaluator(){
//When an evaluator is added to the database I change his/her statut to Actif (1) after checking that his/her email adress exists
//Start Config
var configvu = [];
configvu["status"] = 13;
configvu["emailgp"] = 4;
configvu["emailpds"] = 3;
//End Config
var pdssheet = SpreadsheetApp.openById(getdbbyname("pdsdb")).getSheets()[0]; //PDS DB
var sheetlastRow = pdssheet.getLastRow();
var values = pdssheet.getRange(2,1,sheetlastRow-1,15).getValues();
var enum=2;
values.forEach(function(row){
if(row[configvu["status"]] == ""){
//🚨🚨 Checker qu’un mail est valide avant d’envoyer pour DMD !!!!!!!!
//🚨🚨 Sinon on reçoit des messages d'erreur pendant des semaines!!!!!!!
if(checkemail(row[configvu["emailpds"]])){
pdssheet.getRange(enum,configvu["status"]+1).setValue(1);
}else{
pdssheet.getRange(enum,configvu["status"]+1).setValue(-1);
}
}
enum++;
},enum,pdssheet);
var gpsheet = SpreadsheetApp.openById(getdbbyname("gpdb")).getSheets()[0]; //GP DB
var sheetlastRow = gpsheet.getLastRow();
var values = gpsheet.getRange(2,1,sheetlastRow-1,15).getValues();
enum=2;
values.forEach(function(row){
if(row[configvu["status"]] == ""){
if(checkemail(row[configvu["emailgp"]])){
pdssheet.getRange(enum,configvu["status"]+1).setValue(1);
}else{
pdssheet.getRange(enum,configvu["status"]+1).setValue(-1);
}
}
enum++;
},enum,gpsheet);
}
function checkunsuscribed (){
//Check if users have unsuscribed
//Start Config
var configvu = [];
configvu["email"] = 1;
configvu["status"] = 4;
//End config
//Status :
//-1 - Not found
//empty - To analyze
//1 - Unsuscribed
//2 - Ignore
//End config
//Statut
//I don't ask if the person is GP or PDS for 2 reasons
//- A PDS can be a user of an app that is not related to his/her specialty
//- The UX of the person that want to leave must be good and it's better not to ask too many questions
//- Check duplicates in the inscription
var unsuscribedbsheet = SpreadsheetApp.openById(getdbbyname("unsusdb")).getSheets()[0];
var sheetlastRow = unsuscribedbsheet.getLastRow();
var values = unsuscribedbsheet.getRange(2,1,sheetlastRow-1,5).getValues();
var enum=2;
values.forEach(function(row){
var foundpds = true;
var foundgp = true;
var status = parseInt(row[configvu["status"]]) || 0;
if (status == 0){
var line = searchspreadsheet(getdbbyname("pdsdb"),row[configvu["email"]],4); //pds spreadsheet
if(line != -1){
//I update the status of the evaluators
changespreadsheetcell(getdbbyname("pdsdb"),line,14,0);
//I change the status of the unsuscribed request
unsuscribedbsheet.getRange(enum,configvu["status"]+1).setValue(1);
}
else{
foundpds = false;
}
var line = searchspreadsheet(getdbbyname("gpdb"),row[configvu["email"]],5); //gp spreadsheet
if(line != -1){
//I update the status of the evaluators
changespreadsheetcell(getdbbyname("gpdb"),line,14,0);
//I change the status of the unsuscribed request
unsuscribedbsheet.getRange(enum,configvu["status"]+1).setValue(1);
}
else{
foundgp = false;
}
}
if (!foundpds && !foundgp){//The person has not been found at all
//🚨🚨 The person has not been found in this database
unsuscribedbsheet.getRange(enum,configvu["status"]+1).setValue("-1");
}
},unsuscribedbsheet);
}
function checkenddate() {
//Check that the end-date of the evaluation has not been reached
//I open the BackOffice VU
//If a request is taking to long to be finished people are note payed⇒ In which case it would be interesting to do a parainage :)
var formss = SpreadsheetApp.openById(getdbbyname("formvu"));
var formsheet = formss.getSheets()[0];
var formlastRow = formsheet.getLastRow();
var values = formsheet.getRange(2,1,formlastRow-1,14).getValues();
//Start Config
var configvu = [];
configvu["datedefin"] = 11;
//End config
//Status :
//0 - Waiting
//1 - Created Forms
//2 - Filled forms
//End config
var enum=2;
var now = new Date();
values.forEach(function(row){
if(row[configvu["datedefin"]] < now){
sendtoslack("🚨🚨 Une demande de VU a pris plus d'un moins a être finie");
};
});
}
function checkevaluationdone() {
//I open the forms database spreadsheet
var formss = SpreadsheetApp.openById(getdbbyname("formdb"));
var formsheet = formss.getSheets()[0];
var formlastRow = formsheet.getLastRow();
var values = formsheet.getRange(4,1,formlastRow-3,15).getValues();
var enum=4;
//Start Config
var configvu = [];
configvu["formid"] = 0;
configvu["requestid"] = 1;
configvu["responseid"] = 4;
configvu["cible"] = 9;
configvu["responsemax"] = 11;
configvu["filled"] = 13;
configvu["status"] = 14;
//Status :
//0 - Disabled form
//1 - Form created but not sent
//2 - Form created and sent
//3 - Form finished and closed
//End config
/* test
var testspread = SpreadsheetApp.openById("1iiA0GXBWGTcQDM4BJdbcW0WqGlGCTGBiARPy8ZIraHs");
testspread.getSheets()[1].getRange(1,1,15,20).copyTo(testspread.getSheets()[0].getRange(2,1));
*/
values.forEach(function(row){
if(row[configvu["status"]] == "1" || row[configvu["status"]] == "2" ){
//We only look for this status to increase performance
row[configvu["filled"]] = removeduplicates(row[configvu["responseid"]],0,2,2); // I set the number of unique responses after deleting duplicates
formsheet.getRange(enum,configvu["filled"]+1).setValue(row[configvu["filled"]]);
if (parseInt(row[configvu["filled"]]) >= parseInt(row[configvu["responsemax"]])){
//I've reached the number min of responses
deactivateform(row[configvu["formid"]]);
formsheet.getRange(enum,configvu["status"]+1).setValue(3); //Evaluations are done
var emails = getfilledemails(row[configvu["responseid"]]);
for (i = 0; i < emails.length; i++) {
//I log all the persons that answered to the form that has just been done
logevent({"requestid":row[configvu["requestid"]],"type":"fill","id":emails[i][0],"category":row[configvu["cible"]]})
}
}
}
enum++;
},enum,formsheet);
}