-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMales Field Condensed List.js
261 lines (227 loc) Β· 12.4 KB
/
Males Field Condensed List.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
/**
* Last updated: April 4, 2024
*/
function runAllMalesFieldCondensedLists() {
let isMaleFieldcondensedListsDocumentCleared = false;
/**
* @function This is a helper function to open or reopen the template GDoc for each
* of the functions that follow. This was a fix for saving the lists while the functions
* run so an error isn't created regarding too much being generated to create the file.
*/
function openMaleTemplateDoc() {
const templateDoc = DocumentApp.openById(maleFieldCondensedListTemplateFile.getId());
const body = templateDoc.getBody();
/** Checks if the document has been cleared, and clears it only once */
if (!isMaleFieldcondensedListsDocumentCleared) {
body.clear();
isMaleFieldcondensedListsDocumentCleared = true;
}
return { templateDoc, body };
}
/*************************************************************************
* Day 1 Lists *
*************************************************************************/
const day1MBeanbagThrow = [1, 'M', 'BEAN BAG THROW']
const day1MTennisBallThrow = [1, 'M', 'TENNIS BALL THROW']
const day1MSoftball = [1, 'M', 'SOFTBALL']
const day1MRunningLJ = [1, 'M', 'RUNNING LJ']
const day1MFoamTurboJav = [1, 'M', 'FOAM TURBOJAV']
const day1MTurboJav = [1, 'M', 'TURBO JAV']
async function runAllMaleDay1Functions() {
SpreadsheetApp.getActiveSpreadsheet().toast("ππ½ββοΈ Putting together the Males Field Condensed List. ππ½ββοΈ Give the script a minute or two to run π’");
await createTables(...day1MTurboJav);
await createTables(...day1MFoamTurboJav);
await createTables(...day1MRunningLJ);
await createTables(...day1MSoftball);
await createTables(...day1MTennisBallThrow);
await createTables(...day1MBeanbagThrow);
await runAllMaleDay2Functions();
}
/*************************************************************************
* Day 2 Lists *
*************************************************************************/
const day2MBeanbagThrow = [2, 'M', 'BEAN BAG THROW']
const day2MTennisBallThrow = [2, 'M', 'TENNIS BALL THROW']
const day2MSoftball = [2, 'M', 'SOFTBALL']
const day2MRunningLJ = [2, 'M', 'RUNNING LJ']
const day2MFoamTurboJav = [2, 'M', 'FOAM TURBOJAV']
const day2MTurboJav = [2, 'M', 'TURBO JAV']
async function runAllMaleDay2Functions() {
SpreadsheetApp.getActiveSpreadsheet().toast("ππ½ββοΈ Finished Day 1 working on Days 2-6 now. ππ½ββοΈ Give the script a minute or two to run π’");
await createTables(...day2MTurboJav);
await createTables(...day2MFoamTurboJav);
await createTables(...day2MRunningLJ);
await createTables(...day2MSoftball);
await createTables(...day2MTennisBallThrow);
await createTables(...day2MBeanbagThrow);
await runAllMaleDay3Functions();
}
/*************************************************************************
* Day 3 Lists *
*************************************************************************/
const day3MBeanbagThrow = [3, 'M', 'BEAN BAG THROW']
const day3MTennisBallThrow = [3, 'M', 'TENNIS BALL THROW']
const day3MSoftball = [3, 'M', 'SOFTBALL']
const day3MRunningLJ = [3, 'M', 'RUNNING LJ']
const day3MFoamTurboJav = [3, 'M', 'FOAM TURBOJAV']
const day3MTurboJav = [3, 'M', 'TURBO JAV']
async function runAllMaleDay3Functions() {
SpreadsheetApp.getActiveSpreadsheet().toast("ππ½ββοΈ Finished Days 1 & 2 working on Days 3-6 now. ππ½ββοΈ Give the script a minute or two to run π’");
await createTables(...day3MTurboJav);
await createTables(...day3MFoamTurboJav);
await createTables(...day3MRunningLJ);
await createTables(...day3MSoftball);
await createTables(...day3MTennisBallThrow);
await createTables(...day3MBeanbagThrow);
await runAllMaleDay4Functions();
}
/*************************************************************************
* Day 4 Lists *
*************************************************************************/
const day4MBeanbagThrow = [4, 'M', 'BEAN BAG THROW']
const day4MTennisBallThrow = [4, 'M', 'TENNIS BALL THROW']
const day4MSoftball = [4, 'M', 'SOFTBALL']
const day4MRunningLJ = [4, 'M', 'RUNNING LJ']
const day4MFoamTurboJav = [4, 'M', 'FOAM TURBOJAV']
const day4MTurboJav = [4, 'M', 'TURBO JAV']
async function runAllMaleDay4Functions() {
SpreadsheetApp.getActiveSpreadsheet().toast("ππ½ββοΈ Finished Days 1-3 working on Days 4-6 now. ππ½ββοΈ Give the script a minute or two to run π’");
await createTables(...day4MTurboJav);
await createTables(...day4MFoamTurboJav);
await createTables(...day4MRunningLJ);
await createTables(...day4MSoftball);
await createTables(...day4MTennisBallThrow);
await createTables(...day4MBeanbagThrow);
await runAllMaleDay5Functions();
}
/*************************************************************************
* Day 5 Lists *
*************************************************************************/
const day5MBeanbagThrow = [5, 'M', 'BEAN BAG THROW']
const day5MTennisBallThrow = [5, 'M', 'TENNIS BALL THROW']
const day5MSoftball = [5, 'M', 'SOFTBALL']
const day5MRunningLJ = [5, 'M', 'RUNNING LJ']
const day5MFoamTurboJav = [5, 'M', 'FOAM TURBOJAV']
const day5MTurboJav = [5, 'M', 'TURBO JAV']
async function runAllMaleDay5Functions() {
SpreadsheetApp.getActiveSpreadsheet().toast("ππ½ββοΈ Finished Days 1-4 working on Days 5 & 6 now. ππ½ββοΈ Give the script a minute or two to run π’");
await createTables(...day5MTurboJav);
await createTables(...day5MFoamTurboJav);
await createTables(...day5MRunningLJ);
await createTables(...day5MSoftball);
await createTables(...day5MTennisBallThrow);
await createTables(...day5MBeanbagThrow);
await runAllMaleDay6Functions();
}
/*************************************************************************
* Day 6 Lists *
*************************************************************************/
const day6MBeanbagThrow = [6, 'M', 'BEAN BAG THROW']
const day6MTennisBallThrow = [6, 'M', 'TENNIS BALL THROW']
const day6MSoftball = [6, 'M', 'SOFTBALL']
const day6MRunningLJ = [6, 'M', 'RUNNING LJ']
const day6MFoamTurboJav = [6, 'M', 'FOAM TURBOJAV']
const day6MTurboJav = [6, 'M', 'TURBO JAV']
async function runAllMaleDay6Functions() {
SpreadsheetApp.getActiveSpreadsheet().toast("ππ½ββοΈ Finished Days 1-5 working on Day 6 now. ππ½ββοΈ Give the script a minute or two to run π’");
await createTables(...day6MTurboJav);
await createTables(...day6MFoamTurboJav);
await createTables(...day6MRunningLJ);
await createTables(...day6MSoftball);
await createTables(...day6MTennisBallThrow);
await createTables(...day6MBeanbagThrow);
await openMalesFieldCondensedListGoogleDoc();
}
/** Function that creates the tables for the lists */
function createTables(tAndFEventDay, athGender, fieldEvent) {
const { templateDoc, body } = openMaleTemplateDoc();
let filteredData = [];
for (let i = 1; i < data.length; i++) {
let row = data[i];
if (row[0] === tAndFEventDay && row[3] === athGender && row[8] === true && row[16] === fieldEvent) {
filteredData.push(row);
}
}
/** Check if filteredData is empty, jump to next list if empty */
if (filteredData.length === 0) {
templateDoc.saveAndClose();
} else {
/** Sort filteredData array by row[19] and then by row[20] in ascending order */
filteredData.sort((a, b) => {
if (a[19] === b[19]) {
return a[20] - b[20];
}
return a[19] - b[19];
});
const previousText = body.getText();
const shouldAddPageBreak = previousText.trim() !== '';
if (shouldAddPageBreak) {
body.appendPageBreak();
}
let headerText5 = `FIELD EVENTS CONDENSED LIST DAY: ${tAndFEventDay}`;
body.insertParagraph(body.getNumChildren(), headerText5).setAttributes(style);
/** Create an object to store tables for each value in row[19] */
const tables = {};
/** Adds the filtered data to the respective tables */
for (let i = 0; i < filteredData.length; i++) {
let row = filteredData[i];
let value = String(row[19]).padStart(2, '0'); // Assuming row[19] contains the value for table separation
/** Check if a table already exists for the value */
if (!tables[value]) {
/** Create a new table if it doesn't exist */
tables[value] = {
table: body.appendTable(),
headerText: `${fieldEvent} HEAT: ${value}`
};
/** Adds table headers for each table */
let headersRow = tables[value].table.appendTableRow();
headersRow.appendTableCell('Pos.').setWidth(39).getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('First Name').getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('Last Name').getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('Gender').setWidth(60).getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('Campus').getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('M').setWidth(30).getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('cm').setWidth(30).getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('Score').setWidth(50).getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('Score').setWidth(50).getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
headersRow.appendTableCell('Place').setWidth(50).getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.CENTER).setAttributes(style2);
}
/** Create a new row in the respective table */
let tableRow = tables[value].table.appendTableRow();
tableRow.appendTableCell(typeof row[20] === 'number' ? row[20].toFixed(0) : '');
tableRow.appendTableCell(row[2]);
tableRow.appendTableCell(row[1]);
tableRow.appendTableCell(row[3]);
tableRow.appendTableCell(row[10]);
tableRow.appendTableCell(typeof row[17] === 'number' ? row[17].toFixed(0) : '');
tableRow.appendTableCell(typeof row[18] === 'number' ? row[18].toFixed(0) : '');
tableRow.appendTableCell('');
tableRow.appendTableCell('');
tableRow.appendTableCell('');
}
/** Add header text before each table */
Object.keys(tables)
.forEach((value, index) => {
body.insertParagraph(body.getChildIndex(tables[value].table), tables[value].headerText).setAttributes(style);
});
templateDoc.saveAndClose();
}
}
/** The function below creates a dialog box for the user in the SE Olympics sheet
* letting them know that the list is ready to be viwed and gives them the hyperlink
* to open the doc.
* @todo change the docId with the ID from the actual doc once this project goes live.
*/
function openMalesFieldCondensedListGoogleDoc() {
let doc = DocumentApp.openById(maleFieldCondensedListTemplateFile.getId());
let url = doc.getUrl();
let htmlContent = '<p>π Thanks for your patience! π
<br><br>The Males Field Consolidated List has been updated.</p>';
htmlContent += '<p>Click <a href="' + url + '" target="_blank">here</a> to open it up.</p>';
let htmlOutput = HtmlService.createHtmlOutput(htmlContent)
.setWidth(400)
.setHeight(200);
/** Displays the custom dialog box */
SpreadsheetApp.getUi().showModalDialog(htmlOutput, 'Google Doc Updated');
}
runAllMaleDay1Functions()
}