-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
536 lines (469 loc) · 18.3 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
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<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">
</head>
<body>
<div class="form-group">
<label for="dtmsPersReportXslx">DTMS Personnel File</label>
<input type="file" id="dtmsPersReportXslx" name="dtmsPersReportXslx"/>
</div>
<div class="form-group">
<label for="dtmsTngReportXslx">DTMS Training Report</label>
<input type="file" id="dtmsTngReportXslx" name="dtmsTngReportXslx"/>
</div>
<div class="form-group">
<label for="dtmsTngToTrackXslx">DTMS Training to Present</label>
<input type="file" id="dtmsTngToTrackXslx" name="dtmsTngToTrackXslx"/>
</div>
<div class="form-group">
<button id="displayUnitSize" type="button" class="btn btn-primary btn-lg">Display Unit Size</button>
<button id="display350_1Compliance" type="button" class="btn btn-primary btn-lg">Display 350-1 Compliance</button>
</div>
<div class="chart"> </div>
<table id="complianceTable" 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/d3.v5.min.js"></script>
<script src="js/jquery.tablesorter.min.js"></script>
<script>
var DateTime = luxon.DateTime;
var dtmsPersReport = [];
var dtmsTngReport = [];
var dtmsTngToTrack = [];
// create the dtmsPersReport from the Xslx file
// personnel report from DTMS
$('#dtmsPersReportXslx').on('change', event => {
let dtmsPersReportFile = event.target.files[0];
let reader = new FileReader();
reader.onload = function (e) {
let data = e.target.result;
let workbook = XLSX.read(data, {
type: 'binary'
});
dtmsPersReport = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
};
reader.onerror = ex => {
console.log(ex);
};
reader.readAsBinaryString(dtmsPersReportFile);
});
// create the dtmsTngReport from the Xslx file
// this contains training records
$('#dtmsTngReportXslx').on('change', event => {
var dtmsTngReportFile = event.target.files[0];
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
var workbook = XLSX.read(data, {
type: 'binary',
cellDates: true,
});
dtmsTngReport = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
// sort by date trained and remove duplicate person entries from the tng report
// only interested in the latest date trained
dtmsTngReport.forEach(tngRecord => {
tngRecord['parsedLastDateTrained'] = DateTime.fromJSDate(tngRecord['LastDateTrained']);
});
// sort the training by the date completed
dtmsTngReport = sortByDateDesc(dtmsTngReport);
// deduplicate the training records by person and tasknumber
dtmsTngReport = dtmsTngReport.filter(dedupTngRecords, []);
};
reader.onerror = ex => {
console.log(ex);
};
reader.readAsBinaryString(dtmsTngReportFile);
});
// create the dtmsTngToTrack from the Xslx file
// list of trainings that will be displayed
$('#dtmsTngToTrackXslx').on('change', event => {
let dtmsTngToTrackFile = event.target.files[0];
let reader = new FileReader();
reader.onload = e => {
let data = e.target.result;
let workbook = XLSX.read(data, {
type: 'binary'
});
dtmsTngToTrack = XLSX.utils.sheet_to_json(workbook.Sheets[workbook.SheetNames[0]]);
}
reader.onerror = ex => {
console.log(ex);
}
reader.readAsBinaryString(dtmsTngToTrackFile);
});
// DRAWING FUNCTIONS
function generate350_1Table () {
var complianceTable = document.getElementById('complianceTable');
// remove the current table
while(complianceTable.hasChildNodes()) {
complianceTable.removeChild(complianceTable.firstChild);
};
// setup the header, get the trainings that need to be displayed
var header = complianceTable.createTHead();
var headerRowName = header.insertRow(-1);
var headerRowNumber = header.insertRow(-1);
var headerCellName = headerRowName.insertCell(-1);
var headerCellNumber = headerRowNumber.insertCell(-1);
headerCellName.innerHTML = 'Task Name';
headerCellNumber.innerHTML = 'Task Number';
dtmsTngToTrack.forEach(tngEntry => {
headerCellName = headerRowName.insertCell(-1);
headerCellName.innerHTML = tngEntry['TaskName'];
headerCellNumber = headerRowNumber.insertCell(-1);
headerCellNumber.innerHTML = tngEntry['TaskNumber'];
});
complianceTableBody = document.createElement('tbody');
// reduce to only include unique values
let dtmsUnitArray = dtmsPersReport.map(getUnits)
.reduce(getUniqueValues,[])
.sort();
// add 'All' value at the end
dtmsUnitArray.push('All');
dtmsUnitArray.forEach(unit => {
let unitRow = complianceTableBody.insertRow(-1);
let unitCell = unitRow.insertCell(-1);
unitCell.innerHTML = unit;
unitCell.setAttribute('data-unit',unit);
unitCell.onclick = unitListClickHandler;
// iterate through the tracked trainings training entries
dtmsTngToTrack.forEach(tngEntry => {
unitCell = unitRow.insertCell(-1);
// get the people for that unit that should complete the training
let persList = dtmsPersReport.filter(getPeopleInUnit,{ unit: unit });
let persNum = persList.length;
let soldierNum = persList.filter(getSoldiers).length;
let daCivNum = persList.filter(getDACivilians).length;
// get the training records for the soldiers in the unit for this training
let persHashArray = persList.reduce(genPersonHashArray,[]);
let tngCompleted = dtmsTngReport.filter(getTngForList,{ persHashArray: persHashArray, TaskNumber: tngEntry['TaskNumber'] });
let dayValue = luxon.DateTime.local();
let nonExpiredTngCompleted = tngCompleted.filter(checkTngValid,{ frequency: tngEntry['Frequency'], dayValue: dayValue });
let soldiersCompleted = nonExpiredTngCompleted.filter(getSoldiers).length;
let daCivsCompleted = nonExpiredTngCompleted.filter(getDACivilians).length;
let supervisorsCompleted = nonExpiredTngCompleted.filter(getSupervisors).length;
let audience = tngEntry['Audience'];
let required = 0;
let complete = 0;
if (audience === 'All') {
required = persNum;
complete = nonExpiredTngCompleted.length;
} else if (audience === 'Soldiers') {
required = soldierNum;
complete = soldiersCompleted;
} else if (audience === 'Civilians') {
required = daCivNum;
complete = daCivsCompleted;
} else if (audience === 'Supervisors') {
required = persList.filter(getSupervisors).length;
complete = supervisorsCompleted;
} else {
required = persNum;
complete = nonExpiredTngCompleted.length;
};
// set the chart up here
let compliance = Math.round(100 * complete / required);
unitCell.innerHTML = compliance + '%<br>' + complete + '/' + required;
if(isNaN(compliance)) {
unitCell.innerHTML = '';
unitCell.bgColor = 'black';
unitCell.style.color = 'black';
} else if(compliance < 70) {
unitCell.bgColor = 'red';
unitCell.style.color = 'white';
} else if (compliance < 80) {
unitCell.bgColor = 'yellow';
unitCell.style.color = 'black';
} else {
unitCell.bgColor = 'green';
unitCell.style.color = 'black';
};
unitCell.setAttribute('data-unit',unit);
unitCell.setAttribute('data-tng',tngEntry['TaskNumber']);
unitCell.onclick = tngListClickHandler;
});
});
complianceTable.appendChild(complianceTableBody);
}
function showTngList (tng, unit) {
// retrieve records for a unit for a tng
let personRecords = dtmsPersReport.filter(getPeopleInUnit,{ unit: unit });
let tngToTrackRecord = dtmsTngToTrack.filter(getTngToTrackRecord,{ tng: tng });
let audience = tngToTrackRecord[0]['Audience'];
if (audience === 'All') {
personRecords = personRecords;
} else if (audience === 'Soldiers') {
personRecords = personRecords.filter(getSoldiers);
} else if (audience === 'Civilians') {
personRecords = personRecords.filter(getDACivilians);
} else if (audience === 'Supervisors') {
personRecords = personRecords.filter(getSupervisors);
} else {
personRecords = personRecords;
};
let frequency = tngToTrackRecord[0]['Frequency'];
let dayValue = luxon.DateTime.local();
let personTable = document.getElementById('personTable');
// remove the current table
while(personTable.hasChildNodes()) {
personTable.removeChild(personTable.firstChild);
}
let header = personTable.createTHead();
let headerRow = header.insertRow(-1);
let rankHeaderCell = headerRow.insertCell(-1);
rankHeaderCell.innerHTML = 'Rank';
let nameHeaderCell = headerRow.insertCell(-1);
nameHeaderCell.innerHTML = 'Name';
let tngHeaderCell = headerRow.insertCell(-1);
tngHeaderCell.innerHTML = 'Task Number';
let tngDateHeaderCell = headerRow.insertCell(-1);
tngDateHeaderCell.innerHTML = 'Date Trained';
let personTableBody = document.createElement('tbody');
personRecords.forEach(person => {
let personHash = person['RankShort'] + "|" + person['FirstName'] + "|" + person['LastName'] + "|" + tng;
completedTngRecord = dtmsTngReport.filter(getPersonTngRecord,{ personHash: personHash });
let personRow = personTableBody.insertRow(-1);
let personRankCell = personRow.insertCell(-1);
let personNameCell = personRow.insertCell(-1);
let personTngCell = personRow.insertCell(-1);
let personTngDateCell = personRow.insertCell(-1);
personRankCell.innerHTML = person.RankShort;
personNameCell.innerHTML = person.LastName;
if (completedTngRecord.length > 0) {
personTngCell.innerHTML = completedTngRecord[0].TaskNumber;
personTngDateCell.innerHTML = completedTngRecord[0].parsedLastDateTrained.toFormat('MM/dd/yyyy');
if (completedTngRecord[0].parsedLastDateTrained.plus({ days: frequency }) < dayValue) {
personRow.bgColor = 'red';
personRow.style.color = 'white';
};
} else {
personTngDateCell.innerHTML = '';
personTngCell.innerHTML = '';
personRow.bgColor = 'red';
personRow.style.color = 'white';
};
});
personTable.appendChild(personTableBody);
$("#personTable").tablesorter({
theme: 'bootstrap',
sortReset: true,
sortRestart: true,
});
$("#personTable").trigger("updateAll");
};
function displayPersonnelCompliance (unit) {
// loop through all the personnel
let personTable = document.getElementById('personTable');
// remove the current table
while(personTable.hasChildNodes()) {
personTable.removeChild(personTable.firstChild);
};
// given a unit, display the people in that unit and when they completed the tracked training, display 'red' background if they do not have a training record
let persList = dtmsPersReport.filter(getPeopleInUnit,{ unit: unit });
// setup the header, get the trainings that need to be displayed
let header = personTable.createTHead();
let headerRowName = header.insertRow(-1);
let headerRowNumber = header.insertRow(-1);
let headerCellName = headerRowName.insertCell(-1);
let headerCellNumber = headerRowNumber.insertCell(-1);
headerCellName = headerRowName.insertCell(-1);
headerCellNumber = headerRowNumber.insertCell(-1);
headerCellName.innerHTML = 'Task Name';
headerCellNumber.innerHTML = 'Task Number';
dtmsTngToTrack.forEach(tngEntry => {
headerCellName = headerRowName.insertCell(-1);
headerCellName.innerHTML = tngEntry['TaskName'];
headerCellNumber = headerRowNumber.insertCell(-1);
headerCellNumber.innerHTML = tngEntry['TaskNumber'];
});
let unitTableBody = document.createElement('tbody');
let personRow = '';
persList.forEach(person => {
// show the training dates for a person
personRow = generatePersonTrainingRow(person);
unitTableBody.appendChild(personRow);
});
personTable.appendChild(unitTableBody);
$("#personTable").tablesorter({
theme: 'bootstrap',
sortReset: true,
sortRestart: true,
});
$("#personTable").trigger("updateAll");
};
function generatePersonTrainingRow (person) {
let persHeaderRow = document.createElement('tr');
let dateData = '';
let persHeaderCell = persHeaderRow.insertCell(-1);
persHeaderCell.innerHTML = person['RankShort'];
persHeaderCell = persHeaderRow.insertCell(-1);
persHeaderCell.innerHTML = person['LastName'];
dtmsTngToTrack.forEach(tngToTrack => {
personCell = persHeaderRow.insertCell(-1);
let personHash = person['RankShort'] + "|" + person['FirstName'] + "|" + person['LastName'] + "|" + tngToTrack['TaskNumber'];
completedTngRecord = dtmsTngReport.filter(getPersonTngRecord,{ personHash: personHash });
if (completedTngRecord.length > 0) {
// parse the date and then show the box
// green - good to go
// yellow - will expire in the next 30 days
// red - expired or no record found
let tngDate = completedTngRecord[0]['parsedLastDateTrained'];
let curDate = new DateTime.local();
let expDate = tngDate.plus({ days: parseInt(tngToTrack['Frequency']) });
let tngDuration = expDate.diff(curDate, 'days');
personCell.innerHTML = tngDate.toFormat('MM/dd/yyyy');
personCell.innerHTML += ' (' + Math.round(tngDuration.get('days')) + ')';
if (tngDuration.get('days') > 30) {
// tng is valid for more than 30 days, bg should be green
personCell.bgColor = 'green';
personCell.style.color = 'black';
} else if (tngDuration.get('days') > 0) {
personCell.bgColor = 'yellow';
personCell.style.color = 'black';
} else {
personCell.bgColor = 'red';
personCell.style.color = 'white';
};
};
if (personCell.innerHTML === '') {
personCell.bgColor = 'red';
};
});
return persHeaderRow;
};
// UTILITY FUNCTIONS
function dedupTngRecords (tngRecord) {
// filter the array for the values to get distinct values for:
// RankShort, FirstName, LastName, TaskNumber
let key = tngRecord['RankShort'] + "|" + tngRecord['FirstName'] + "|" + tngRecord['LastName'] + "|" + tngRecord['TaskNumber']
if (!this[key]) {
this[key] = true;
return true;
};
};
function getTngForList (tngRecord) {
if (this.persHashArray.includes(tngRecord['RankShort'] + "|" + tngRecord['FirstName'] + "|" + tngRecord['LastName'])) {
return this['TaskNumber'] === tngRecord['TaskNumber'];
};
};
function getPersonTngRecord (tngRecord) {
let tngHash = tngRecord['RankShort'] + "|" + tngRecord['FirstName'] + "|" + tngRecord['LastName'] + "|" + tngRecord['TaskNumber'];
return (this.personHash === tngHash);
};
function getUnits (persRecord) {
if (persRecord['UnitAttached'] !== undefined && persRecord['UnitAttached'].length > 0) {
return persRecord['UnitAttached'];
} else {
return persRecord['UnitAssigned'];
};
};
function getPeopleInUnit (persRecord) {
// 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 (persRecord['UnitAttached'] !== undefined && persRecord['UnitAttached'].length > 0) {
return persRecord['UnitAttached'] === this.unit;
} else {
return persRecord['UnitAssigned'] === this.unit;
};
};
function getUniqueValues (valueArray, valueRecord) {
if (!valueArray.includes(valueRecord)) {
valueArray.push(valueRecord);
};
return valueArray;
};
// sort by the date column descending (newest value on the top)
function sortByDateDesc (sort_file) {
// sort by the unit
sort_file.sort((a, b) => {
if (a.parsedLastDateTrained.valueOf() > b.parsedLastDateTrained.valueOf()) {
return -1;
} else if (a.parsedLastDateTrained.valueOf() < b.parsedLastDateTrained.valueOf()) {
return 1;
} else {
return 0;
};
});
return sort_file;
};
function getDACivilians (record) {
return record['RankShort'].indexOf('GS') >= 0;
};
function getSoldiers (record) {
return record['RankShort'].indexOf('GS') === -1;
};
// get the supervisors -> will be MAJ and GS13 at this time
function getSupervisors (persRecord) {
return (persRecord['RankShort'] === 'MAJ' || persRecord['RankShort'] === 'GS13');
};
function checkTngValid (tngRecord) {
return tngRecord['parsedLastDateTrained'].plus({ days: this.frequency }) >= this.dayValue;
};
function getTngToTrackRecord (tngToTrack) {
return tngToTrack['TaskNumber'] === this.tng;
};
function getMaxOfArray(a, b) {
return Math.max(a, b);
};
function genPersonHashArray (keyArray, persRecord) {
keyArray.push(persRecord['RankShort'] + '|' + persRecord['FirstName'] + '|' + persRecord['LastName']);
return keyArray;
};
// CLICK HANDLERS AND BUTTONS
function unitListClickHandler (e) {
let unit = e.srcElement.getAttribute('data-unit');
displayPersonnelCompliance(unit);
};
function tngListClickHandler (e) {
let unit = e.srcElement.getAttribute('data-unit');
let tng = e.srcElement.getAttribute('data-tng');
showTngList(tng, unit);
};
// display a personnel bar chart by unit
$('#displayUnitSize').on('click', () => {
let dtmsUnitArray = dtmsPersReport.map(getUnits)
.reduce(getUniqueValues,[])
.sort();
let unitSize = [];
let persList = [];
dtmsUnitArray.forEach(unit => {
persList = dtmsPersReport.filter(getPeopleInUnit,{ unit: unit });
unitSize.push({ unit: unit, persCount: persList.length });
});
// set the max of the domain to be the most people that are in a unit
// get the max number of people in a unit
let maxSize = unitSize.map(unit => unit.persCount)
.reduce(getMaxOfArray);
var scale = d3.scaleLinear()
.domain([0,maxSize])
.range([0,600]);
d3.select(".chart")
.selectAll("div")
.data(unitSize)
.enter()
.append("div")
.style("width", d => { return scale(d.persCount) + 'px' })
.text(d => { return d.unit + " Personnel: " + d.persCount });
});
$('#display350_1Compliance').on('click', () => {
// build the html table to show the training data
generate350_1Table();
$("#complianceTable").tablesorter({
theme: 'bootstrap',
sortReset: true,
sortRestart: true,
});
$("#complianceTable").trigger("updateAll");
});
</script>
</body>
</html>