-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractApData.js
39 lines (33 loc) · 1.12 KB
/
extractApData.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
const XLSX = require('xlsx');
const initialData = XLSX.readFile('./data/STU-AP Advanced Placement Test Scores.xls');
function dataToJSON(excelSheet) {
return XLSX.utils.sheet_to_json(excelSheet.Sheets.Sheet);
}
const apDataObjects = dataToJSON(initialData);
function mergeObjects() {
const mergedStudentObjects = {};
apDataObjects.forEach(recordInstance => {
const studentId = Number(recordInstance['Univ Id']);
const studentAdvisor = recordInstance['Advisor Name'];
const ifIdFound = mergedStudentObjects.hasOwnProperty(studentId);
const apCode = recordInstance['Test Code'];
const apTestEntry = {
testcode: apCode,
testname: recordInstance['Test Desc'],
testscore: recordInstance['Test Score'],
loadDate: recordInstance['AP Load Date'],
}
if (ifIdFound) {
mergedStudentObjects[studentId].tests.push(apTestEntry)
} else {
mergedStudentObjects[studentId] = {
name: recordInstance.Student,
id: studentId,
advisor: studentAdvisor,
tests: [apTestEntry]
}
}
})
return mergedStudentObjects;
}
module.exports = mergeObjects();