-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.gs
240 lines (221 loc) · 6.52 KB
/
global.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
//general functions and parameters.
/////////////////////////VARIABLES/////////////////////////
/**
* [global] The version number.
* @type {string}
*/
const VERSION = 'v0.2.1' //all version info's displayed reference this string
try{
/**
* [global] The handle for the current ui (independent to spreadsheet or sheet, etc.)
* @type {Ui}
*/
var ui = SpreadsheetApp.getUi();
}catch (error) {
Logger.log('Exception in Fetching UI: \n' + error);
}
/**
* [global] The time of excecution summarized as "yyyy-MM-dd-HH:mm"
* @type {String}
*/
var now = getNow();
/**
* [global] "one digit strings", used for clean printing
* @type {String[]}
*/
var digits = ['0','1','2','3','4','5','6','7','8','9','10']
/**
* [global] Common color designations map to hex values
* @type {Object.<string, string>}
*/
var color = {
black:"#000000",
dark_grey_4:"#434343",
dark_grey_3:"#666666",
dark_grey_2:"#999999",
dark_grey_1:"#b7b7b7",
grey:"#cccccc",
light_grey_1:"#d9d9d9",
light_grey_2:"#efefef",
light_grey_3:"#f3f3f3",
white:"#ffffff",
red_berry:"#980000",
red:"#ff0000",
orange:"#ff9900",
yellow:"#ffff00",
green:"#00ff00",
cyan:"#00ffff",
cornflower_blue:"#4a86e8",
blue:"#0000ff",
purple:"#9900ff",
magenta:"#ff00ff",
light_red_berry_3:"#e6b8af",
light_red_3:"#f4cccc",
light_orange_3:"#fce5cd",
light_yellow_3:"#fff2cc",
light_green_3:"#d9ead3",
light_cyan_3:"#d0e0e3",
light_cornflower_blue_3:"#c9daf8",
light_blue_3:"#cfe2f3",
light_purple_3:"#d9d2e9",
light_magenta_3:"#ead1dc",
light_red_berry_2:"#dd7e6b",
light_red_2:"#ea9999",
light_orange_2:"#f9cb9c",
light_yellow_2:"#ffe599",
light_green_2:"#b6d7a8",
light_cyan_2:"#a2c4c9",
light_cornflower_blue_2:"#a4c2f4",
light_blue_2:"#9fc5e8",
light_purple_2:"#b4a7d6",
light_magenta_2:"#d5a6bd",
light_red_berry_1:"#cc4125",
light_red_1:"#e06666",
light_orange_1:"#f6b26b",
light_yellow_1:"#ffd966",
light_green_1:"#93c47d",
light_cyan_1:"#76a5af",
light_cornflower_blue_1:"#6d9eeb",
light_blue_1:"#6fa8dc",
light_purple_1:"#8e7cc3",
light_magenta_1:"#c27ba0",
dark_red_berry_1:"#a61c00",
dark_red_1:"#cc0000",
dark_orange_1:"#e69138",
dark_yellow_1:"#f1c232",
dark_green_1:"#6aa84f",
dark_cyan_1:"#45818e",
dark_cornflower_blue_1:"#3c78d8",
dark_blue_1:"#3d85c6",
dark_purple_1:"#674ea7",
dark_magenta_1:"#a64d79",
dark_red_berry_2:"#85200c",
dark_red_2:"#990000",
dark_orange_2:"#b45f06",
dark_yellow_2:"#bf9000",
dark_green_2:"#38761d",
dark_cyan_2:"#134f5c",
dark_cornflower_blue_2:"#1155cc",
dark_blue_2:"#0b5394",
dark_purple_2:"#351c75",
dark_magenta_2:"#741b47",
dark_red_berry_3:"#5b0f00",
dark_red_3:"#660000",
dark_orange_3:"#783f04",
dark_yellow_3:"#7f6000",
dark_green_3:"#274e13",
dark_cyan_3:"#0c343d",
dark_cornflower_blue_3:"#1c4587",
dark_blue_3:"#073763",
dark_purple_3:"#20124d",
dark_magenta_3:"#4c1130"
};
/**
* [global] color palette for chatbot
* @type {Object.<string, string>}
*/
var cb_color = {
"cmd":"darkmagenta",
"chal":"blue",
"rela":"deeppink",
"rej":"red",
"acc":"forestgreen",
"undo":"brown"
}
/**
* [global] regulation parameters tuned for different tournanments.
*
* @type{{max_rejects:number,remove_th:number}}
* @max_rejects maximum number of rejects for a single team throughout tournament (IYPT:8,KYPT:7)
* @remove_th minimum number below which rules have to be removed (IYPT:5,KYPT:5)
*/
var regulation = {
'max_rejects':7,
'remove_th':5,
}
/////////////////////////FUNCTIONS/////////////////////////
/**
* [global] retrieves the scoring system spreadsheet
* @return {SpreadsheetApp.Spreadsheet} the spreadsheet
*/
function getSsSpreadsheet(){return SpreadsheetApp.getActive();}
/**
* [global] retrieves the scores master spreadsheet
* @return {SpreadsheetApp.Spreadsheet} the spreadsheet
*/
function getMtSpreadsheet(){return SpreadsheetApp.openByUrl(PropertiesService.getDocumentProperties().getProperty('mtUrl'));}
/**
* [global] The time of excecution summarized as "yyyy-MM-dd-HH:mm"
* @return {String} the time
*/
function getNow() {
// timezone = "GMT+" + new Date().getTimezoneOffset()/60
timezone = SpreadsheetApp.getActive().getSpreadsheetTimeZone()
var date = Utilities.formatDate(new Date(), timezone, "yyyy-MM-dd-HH:mm");
return date;
}
/**
* [global] Retrieves the google ID of the user (ex: user is [email protected] -> returns iamchoking247)
* @return {String} the ID
*/
function getUserID(){
return Session.getActiveUser().getEmail().split("@")[0];
}
// function getName() {
// return SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Draw').getRange("I26").getValue();
// }
/**
* [global] Checks if the current session is in the SOURCE
* @return {boolean} true if SOURCE
*/
function isSource() {return (PropertiesService.getDocumentProperties().getProperty('status') == 'SOURCE');}
/**
* [global] Gets the full name of this instance (KYPT-2022, etc.), returns "SOURCE" if document is SOURCE
* @return {string}
*/
function getFullName() {
if(PropertiesService.getDocumentProperties().getProperty('status') == 'SOURCE'){return "SOURCE"}
return SpreadsheetApp.getActiveSpreadsheet().getRange("Draw!D26").getValue() + '-'+ SpreadsheetApp.getActiveSpreadsheet().getRange("Draw!I26").getValue();
}
function getFullName_Bracket() {
return '['+getFullName()+']';
}
/**
* [global] resize a google doc to a specified size and orientation
* @param {DocumentApp.Document} doc the docuement to format
* @param {string} paperSize the "name" of the paper format
* @param {boolean} portrait orientation
*
* @return {null}
*/
function paper_size(doc, paperSize, portrait = true) {
//Dictionary of Paper sizes by width and height in portrait.
var paper = {
letter_size:[612.283,790.866],
tabloid_size:[790.866,1224.57],
legal_size:[612.283,1009.13],
statement_size:[396.85,612.283],
executive_size:[521.575,756.85],
folio_size:[612.283,935.433],
a3_size:[841.89,1190.55],
a4_size:[595.276,841.89],
a5_size:[419.528,595.276],
b4_size:[708.661,1000.63],
b5_size:[498.898,708.661]};
if(portrait===true){
doc.getBody().setPageWidth(paper[paperSize][0]).setPageHeight(paper[paperSize][1]);
}else {
doc.getBody().setPageHeight(paper[paperSize][0]).setPageWidth(paper[paperSize][1]);
};
};
/**
* [global] function for pretty printing
*/
function oneDigit(num){
if(typeof(num) == "number"){if( num >= 0 && num <= 10 ){return digits[num];}}
return num
}
function num_to_str(num = 1.0){
var str = num.toString();
return str
}