-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
399 lines (328 loc) · 14.7 KB
/
index.html
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<html>
<meta charset="UTF-8">
<head>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/index.css">
<link rel="stylesheet" href="css/theme.bootstrap_4.css">
<link rel="stylesheet" href="css/datepicker.min.css">
</head>
<body>
<div class="form-group">
<label for="dtmsAcftReportXslx">Choose the DTMS ACFT report to process</label>
<input type="file" id="dtmsAcftReportXslx" name="dtmsAcftReportXslx"/>
</div>
<div class="form-group">
<label for="acftComplianceDate">Choose the date to calculate the ACFT stats off of</label>
<input id="acftComplianceDate" type="text" placeholder="" />
</br>
<button id="displayAcftStats" type="button" class="btn btn-primary btn-lg">Display ACFT Statistics</button>
</div>
<table id="acftComplianceTable" class="table table-dark table-bordered" > </table>
<table id="personTable" class="table table-dark table-bordered" > </table>
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/jquery.csv.min.js"></script>
<script src="js/luxon.min.js"></script>
<script src="js/jszip.js"></script>
<script src="js/xlsx.js"></script>
<script src="js/jquery.tablesorter.min.js"></script>
<script src="js/datepicker.min.js"></script>
<script>
var DateTime = luxon.DateTime
var dtmsAcftReport = []
let acftComplianceDate = document.getElementById('acftComplianceDate')
const acftComplianceDatePicker= datepicker(acftComplianceDate, {
formatter: (input, date, instance) => {
const value = date.toISOString().slice(0,10)
acftComplianceDate.value = value
}
})
// this contains personnel acft records
$('#dtmsAcftReportXslx').on('change', event => {
var dtmsAcftReportFile = event.target.files[0]
var reader = new FileReader()
reader.onload = e => {
binary = ""
bytes = new Uint8Array(e.target.result)
length = bytes.byteLength
for (var i = 0; i < length; i += 1) {
binary += String.fromCharCode(bytes[i])
}
workbook = XLSX.read(binary, {
type: 'binary',
//cellDates: true,
cellDates: false,
})
dtmsAcftReport = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
// this is not parsing the dates properly
// create a luxon DateTime named 'parsedLastAcft' from the 'Lastacft' JS Date
dtmsAcftReport = dtmsAcftReport.map(setParsedLastAcft)
}
reader.onerror = ex => {
console.log(ex)
}
reader.readAsArrayBuffer(dtmsAcftReportFile)
})
function generateAcftTable () {
let acftTable = document.getElementById('acftComplianceTable')
while(acftTable.hasChildNodes()) {
acftTable.removeChild(acftTable.firstChild);
}
let acftTableHead = acftTable.createTHead()
let acftTableHeadRow = acftTableHead.insertRow(-1)
let acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Unit'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Complete/Req'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Expired'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Due within 30 days'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Average MDL Score'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Average SPT Score'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Average HRP Score'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Average SDC Score'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Average LTK Score'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Average 2MR Score'
acftTableHeadCell = acftTableHeadRow.insertCell(-1)
acftTableHeadCell.innerHTML = 'Average Score'
let acftTableBody = document.createElement('tbody')
let acftComplianceDate = document.getElementById('acftComplianceDate').value
let acftComplianceDateParsed = ''
if (acftComplianceDate == undefined || acftComplianceDate === '') {
acftComplianceDateParsed = luxon.DateTime.local()
} else {
acftComplianceDateParsed = luxon.DateTime.fromISO(acftComplianceDate)
}
// get the list of units from the dtmsAcftReport
// use the 'Unit Attached' if exists, then use the 'Unit Assigned'
// sort the units alphabetically
let dtmsUnitArray = dtmsAcftReport.map(getUnits).sort()
let uniqueUnits = new Set(dtmsUnitArray)
// add the 'All' group to the dtmsUnitArray to show stats for all Soldiers
uniqueUnits.add('All')
uniqueUnits.forEach(unit => {
// generate the list of all Soldiers in the unit, then find their acft scores, it is ok if a Soldier doesn't have an acft score, just print blank
// get Soldiers in the unit
let soldierList = dtmsAcftReport.filter(getUnitSoldierList, { unit: unit })
acftTableRow = acftTableBody.insertRow(-1)
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = unit
acftTableCell.setAttribute('data-unit',unit)
acftTableCell.setAttribute('data-column','unit')
acftTableCell.onclick = cellClickHandler
acftTableCell = acftTableRow.insertCell(-1)
let completeAcft = soldierList.filter(isSoldierCurrentAcft, { projectedDate: acftComplianceDateParsed })
let notCompleteAcft = soldierList.filter(isSoldierExpiredAcft, { projectedDate: acftComplianceDateParsed })
let numCompleteAcft = completeAcft.length
let numRequiredAcft = parseInt(completeAcft.length) + parseInt(notCompleteAcft.length)
acftTableCell.innerHTML = `${Math.round(numCompleteAcft * 100 / numRequiredAcft)}% (${numCompleteAcft} / ${numRequiredAcft})`;
acftTableCell.setAttribute('data-unit',unit)
acftTableCell.setAttribute('data-column','currentAcft')
acftTableCell.onclick = cellClickHandler
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = notCompleteAcft.length.toString()
acftTableCell.setAttribute('data-unit',unit)
acftTableCell.setAttribute('data-column','expiredAcft')
acftTableCell.onclick = cellClickHandler
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = soldierList.filter(isSoldierDueAcftWithin30Days, { projectedDate: acftComplianceDateParsed }).length.toString()
acftTableCell.setAttribute('data-unit',unit)
acftTableCell.setAttribute('data-column','dueAcftWithin30Days')
acftTableCell.onclick = cellClickHandler
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = Math.round(getEventScoreAverage(completeAcft, 'Deadlift Score')).toString()
acftTableCell.setAttribute('data-unit',unit)
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = Math.round(getEventScoreAverage(completeAcft, 'Throw Score')).toString()
acftTableCell.setAttribute('data-unit',unit)
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = Math.round(getEventScoreAverage(completeAcft, 'Push-Up Score')).toString()
acftTableCell.setAttribute('data-unit',unit)
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = Math.round(getEventScoreAverage(completeAcft, 'S/D/C Score')).toString()
acftTableCell.setAttribute('data-unit',unit)
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = Math.round(getEventScoreAverage(completeAcft, 'Leg Tuck Score')).toString()
acftTableCell.setAttribute('data-unit',unit)
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = Math.round(getEventScoreAverage(completeAcft, '2M Run Score')).toString()
acftTableCell.setAttribute('data-unit',unit)
// to calculate the average score, sum the averages
acftTableCell = acftTableRow.insertCell(-1)
acftTableCell.innerHTML = Math.round(getScoreAverage(completeAcft)).toString()
acftTableCell.setAttribute('data-unit',unit)
})
acftTable.appendChild(acftTableBody)
}
function cellClickHandler (e) {
let unitText = e.srcElement.getAttribute('data-unit')
let columnText = e.srcElement.getAttribute('data-column')
let acftComplianceDate = document.getElementById('acftComplianceDate').value
let acftComplianceDateParsed = ''
if (acftComplianceDate == undefined || acftComplianceDate === '') {
acftComplianceDateParsed = luxon.DateTime.local()
} else {
acftComplianceDateParsed = luxon.DateTime.fromISO(acftComplianceDate)
}
let soldierList = []
if (unitText === 'All') {
soldierList = dtmsAcftReport
} else {
soldierList = dtmsAcftReport.filter(getUnitSoldierList, { unit: unitText })
}
// check to see what column of data is requested
if (columnText === 'dueAcftWithin30Days') {
soldierList = soldierList.filter(isSoldierDueAcftWithin30Days, { projectedDate: acftComplianceDateParsed })
} else if (columnText === 'currentAcft') {
soldierList = soldierList.filter(isSoldierCurrentAcft, { projectedDate: acftComplianceDateParsed } )
} else if (columnText === 'expiredAcft') {
soldierList = soldierList.filter(isSoldierExpiredAcft, { projectedDate: acftComplianceDateParsed } )
} else if (columnText === 'unit') {
soldierList = soldierList
} else {
soldierList = dtmsAcftReport
}
displayPersonList(soldierList)
}
function displayPersonList (soldierList) {
let personTable = document.getElementById('personTable')
while(personTable.hasChildNodes()) {
personTable.removeChild(personTable.firstChild);
}
let personTableHeader = personTable.createTHead()
let personTableHeaderRow = personTableHeader.insertRow(-1)
let personTableHeaderCell = personTableHeaderRow.insertCell(-1)
personTableHeaderCell.innerHTML = 'Rank'
personTableHeaderCell = personTableHeaderRow.insertCell(-1)
personTableHeaderCell.innerHTML = 'Name'
personTableHeaderCell = personTableHeaderRow.insertCell(-1)
personTableHeaderCell.innerHTML = 'Unit'
personTableHeaderCell = personTableHeaderRow.insertCell(-1)
personTableHeaderCell.innerHTML = 'Date of Last Acft'
personTableHeaderCell = personTableHeaderRow.insertCell(-1)
personTableHeaderCell.innerHTML = 'Score'
let personTableBody = document.createElement('tbody')
personTable.appendChild(personTableBody)
let personTableBodyRow
let personTableBodyCell
soldierList.forEach(soldier => {
personTableBodyRow = personTableBody.insertRow(-1)
personTableBodyCell = personTableBodyRow.insertCell(-1)
personTableBodyCell.innerHTML = soldier['Rank']
personTableBodyCell = personTableBodyRow.insertCell(-1)
personTableBodyCell.innerHTML = soldier['Last Name']
// show Unit Attached, if none show Unit Assigned
personTableBodyCell = personTableBodyRow.insertCell(-1)
if (soldier['Unit Attached'] !== undefined) {
personTableBodyCell.innerHTML = soldier['Unit Attached']
} else {
personTableBodyCell.innerHTML = soldier['Unit Assigned']
}
personTableBodyCell = personTableBodyRow.insertCell(-1)
if (soldier['parsedLastAcft'] !== undefined) {
personTableBodyCell.innerHTML = soldier['parsedLastAcft'].toFormat('MM/dd/yyyy')
} else {
personTableBodyCell.innerHTML = ''
}
personTableBodyCell = personTableBodyRow.insertCell(-1)
if (soldier['parsedLastAcft'] !== undefined) {
personTableBodyCell.innerHTML = soldier['Total Score']
} else {
personTableBodyCell.innerHTML = ''
}
})
// after the first load, use 'updateAll' to refresh the table sort
$("#personTable").tablesorter({
theme: 'bootstrap',
sortReset: true,
sortRestart: true,
})
$("#personTable").trigger("updateAll")
}
function getUnitSoldierList (record) {
// check to see if the unit selector is set to 'All', if yes then send back every record
if (this.unit === 'All') {
return true
}
// check to see if the soldier is attached to the unit, if attached to a unit, then he should not be listed on the 'assigned' roster
if (record['Unit Attached'] !== undefined && record['Unit Attached'].length > 0) {
return record['Unit Attached'] === this.unit
} else {
return record['Unit Assigned'] === this.unit
}
}
function isSoldierCurrentAcft (record) {
return ((record['parsedLastAcft'] !== undefined) && (record['parsedLastAcft'].plus({ months: 6 }) >= this.projectedDate))
}
function isSoldierDueAcftWithin30Days (record) {
return (record['parsedLastAcft'] === undefined || record['parsedLastAcft'].plus({ months: 5 }) <= this.projectedDate)
}
function isSoldierExpiredAcft (record) {
return ((record['parsedLastAcft'] === undefined) || (record['parsedLastAcft'].plus({ months: 6 }) < this.projectedDate))
}
function addScores({ totalScore, scoreCount }, score) {
return {
totalScore: totalScore + score,
scoreCount: scoreCount + 1,
}
}
function getScoreAverage (soldierList) {
let mdlScore = getEventScoreAverage(soldierList, 'Deadlift Score')
let sptScore = getEventScoreAverage(soldierList, 'Throw Score')
let hrpScore = getEventScoreAverage(soldierList, 'Push-Up Score')
let sdcScore = getEventScoreAverage(soldierList, 'S/D/C Score')
let ltkScore = getEventScoreAverage(soldierList, 'Leg Tuck Score')
let runScore = getEventScoreAverage(soldierList, '2M Run Score')
// round the event averages before summing them so the integers that appear in each column sum to the average
let roundedAverage = Math.round(mdlScore) + Math.round(sptScore) + Math.round(hrpScore) + Math.round(sdcScore) + Math.round(ltkScore) + Math.round(runScore)
return roundedAverage
}
function getEventScoreAverage (soldierList, eventType) {
const initialInfo = { totalScore: 0, scoreCount: 0 }
// for now, only check whether they have a score, don't check if it is for record
const scoreInfo = soldierList.filter(record => record['Last ACFT'] !== undefined)
.filter(function (record) { return record[this] > 0 }, eventType)
.map(function (record) { return record[this] }, eventType)
.reduce(addScores, initialInfo)
const {totalScore, scoreCount} = scoreInfo
let averageScore = totalScore / scoreCount
if (isNaN(averageScore)) {
averageScore = 0
}
return averageScore
}
function getUnits (record) {
if (record['Unit Attached'] !== undefined && record['Unit Attached'].length > 0) {
return record['Unit Attached']
} else {
return record['Unit Assigned']
}
}
// take in a 'Last ACFT' Date, return a luxon time as the parsedLastAcft field
function setParsedLastAcft(record) {
if (record['Last ACFT'] !== undefined) {
let splitDate = record['Last ACFT'].split('/')
record['parsedLastAcft'] = DateTime.utc(parseInt(splitDate[2]), parseInt(splitDate[0]), parseInt(splitDate[1]))
}
return record
}
// by team, by person
$('#displayAcftStats').on('click', () => {
// build the html table to show the acft data
generateAcftTable()
$("#acftComplianceTable").tablesorter({
theme: 'bootstrap',
sortReset: true,
sortRestart: true,
})
$("#acftComplianceTable").trigger("updateAll")
})
</script>
</body>
</html>