forked from Medium/snowflake
-
Notifications
You must be signed in to change notification settings - Fork 4
/
conversion.js
executable file
·67 lines (53 loc) · 1.6 KB
/
conversion.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
'use strict'
let Papa = require('papaparse');
let fs = require('fs');
let inputFileName = process.argv[2];
let outputFileName = process.argv[3];
fs.readFile(inputFileName, function (err, data) {
if (err) {
throw err;
}
let results = Papa.parse(data.toString(), {
delimiter: ",",
newline: "",
skipEmptyLines: true,
});
var tracks = {};
var rowOffset = 7;
var trackOffset = 2;
for (var i = 0; i < 4; i++) {
let track = buildTrack(results.data, rowOffset, trackOffset);
if (track["displayName"] != undefined) {
tracks[track["displayName"].toUpperCase()] = track;
}
trackOffset += 3;
}
fs.writeFile(outputFileName, JSON.stringify(tracks, null, 4), (err) => {
// throws an error, you could also catch it here
if (err) throw err;
// success case, the file was saved
console.log('Saved');
});
});
function buildTrack(data, rowOffset, trackOffset) {
var track = {};
track["displayName"] = data[rowOffset][trackOffset];
track["description"] = data[rowOffset + 1][trackOffset];
track["milestones"] = [];
for (var i = 0; i < 5; i++) {
track["milestones"][i] = buildMilestone(data, rowOffset + 2, trackOffset);
rowOffset += 5;
}
return track;
}
function buildMilestone(data, rowOffset, trackOffset) {
var milestone = {};
milestone["summary"] = data[rowOffset][trackOffset];
milestone["signals"] = [];
milestone["examples"] = [];
for (var i = 2; i <= 4; i++) {
milestone["signals"][i - 2] = data[rowOffset + i][trackOffset];
milestone["examples"][i - 2] = data[rowOffset + i][trackOffset + 1];
}
return milestone;
}