This repository has been archived by the owner on Mar 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkGen.js
145 lines (121 loc) · 3.94 KB
/
linkGen.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
// Generates spreadsheet object for Sheets from raw data
function generateLinkSpreadsheet(reportData, tgtDate) {
var matrix = dataToMatrix(reportData);
var dict = getLinksFromMatrix(matrix, tgtDate);
var sheetData = generateArrayFromDict(dict);
return createLinkSheetUploadObject(sheetData, tgtDate);
}
// Returns the location name for the form
function mapLoc(location) {
// <shiftboard venue> -> <google form venue>
// ACC -> ACC
// Courtyard Marriott Downtown -> Courtyard
// Fairmont Hotel -> Fairmont
// Hilton Downtown -> Hilton
// Westin -> Westin
// * Four Seasons -> Four Seasons
// * JW Marriott -> JW Marriott
// ** Line Austin -> The LINE
var firstWord = location.split(' ')[0];
var singleWordVenues = ['ACC', 'Courtyard', 'Fairmont', 'Hilton', 'Westin'];
if (singleWordVenues.includes(firstWord)) {
return firstWord;
} else if (location === 'Line Austin') {
// Strange exception: The LINE
return 'The LINE';
} else {
// Four Seasons, JW Marriott
return location;
}
}
// Get list of links from matrix
function getLinksFromMatrix(matrix, date) {
var dict = {};
for (var i = 1; i < matrix.length; i++) {
var line = matrix[i];
// Name
var fullName = line[5];
// Crew
var tempCrew = line[0];
var crew = '';
if (tempCrew.endsWith('Lead')) {
crew = 'Shift+Leader';
} else if (tempCrew.endsWith('Ninja')) {
crew = 'Ninja';
} else {
continue;
}
// Location
var location = mapLoc(line[2]);
// Date
var day = date.getDate();
var monthIndex = date.getMonth() + 1;
var year = date.getFullYear();
var dateStr = monthIndex + '/' + day + '/' + year;
// Now, create link if name not already in Set
if (!(fullName in dict)) {
// Generate link!
dict[fullName] = getLinkWithParams(fullName, crew, location, dateStr);
}
}
// Return result
return dict;
}
// Returns formatted link based on params
function getLinkWithParams(fullName, crew, location, dateStr) {
var result = "";
result += "https://docs.google.com/forms/d/e/1FAIpQLSdrjMtCx2BNfufLthp5u3parOey8anxGktU0SsOcsl38vXhZg/viewform?usp=pp_url&";
// Name
result += "entry.1000000=";
result += fullName.replace(' ', '+');
// Role
result += "&entry.441130460=";
result += crew.replace(' ', '+');
// Date
result += "&entry.1000008=";
result += dateStr;
// Venue
result += "&entry.1000004=";
result += location.replace(' ', '+');
return result;
}
// Generates actual sheet base data from dictionary
function generateArrayFromDict(dict) {
var names = [];
for (key in dict) {
names.push(key);
}
names.sort();
var result = [];
result.push(["Name", "Link"]);
for (i in names) {
var name = names[i];
result.push([name, dict[name]]);
}
return result;
}
// Get title for spreadsheet based on date
function getLinkSheetTitle(tgtDate) {
var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
let day = days[ tgtDate.getDay() ];
let trueMonth = tgtDate.getMonth() + 1;
return 'Vol Scoring Links - ' + day + ' ' + trueMonth + '/' + tgtDate.getDate();
}
// Transforms matrix data into Sheet object
function getLinkSheet(matrix) {
var sheet = getSheetTemplate();
sheet.properties.title = null;
var rowData = sheet.data[0].rowData;
// Header
rowData.push(rowToBoldedSheetRow(matrix, 0));
for (var i = 1; i < matrix.length; i++) {
rowData.push(rowToSheetRow(matrix, i));
}
return sheet;
}
// Creates object in correct format for Google Sheets
function createLinkSheetUploadObject(sheetData, tgtDate) {
var result = getSpreadsheet(getLinkSheetTitle(tgtDate));
result.sheets.push(getLinkSheet(sheetData));
return result;
}