-
Notifications
You must be signed in to change notification settings - Fork 1
/
pceParser.js
71 lines (56 loc) · 2.25 KB
/
pceParser.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
'use strict';
const csv2Array = require("csv-to-array");
let embarcationJson;
let licenciesJson;
module.exports = {parseEmbarcations, parseLicencies, getLicencesFromName, getLicenciesFromLicenceAndName, getLicenciesFromNames, getPceRowRegistrationMono, getAgeCategoryFromYear};
const columnsPceEmb = ["embarcationId", "boat", "category", "division", "club", "clubId", "cd", "cdId", "cr", "crId", "value", "licence", "lastname","firstname", "sex", "dob", "licence2", "lastname2","firstname2", "sex2", "dob2"];
function parseEmbarcations(cb) {
csv2Array({
file: "ffcanoe-sla.pce",
columns: columnsPceEmb,
csvOptions:{delimiter:';', charset: 'ISO-8859-15'}
}, (err, embarcations) => {
embarcationJson = embarcations;
if (cb) cb(embarcations);
});
}
const columnsPceLicencies = ["licence", "lastname","firstname", "sex", "dob", "club", "clubId"];
function parseLicencies(cb) {
csv2Array({
file: "licencies.pce",
columns: columnsPceLicencies,
csvOptions:{delimiter:';', charset: 'ISO-8859-15'}
}, (err, licencies) => {
for(let row of licencies) {
row.ageCategory = getAgeCategoryFromDob(row.dob);
}
licenciesJson = licencies;
if (cb) cb(licencies);
});
}
function getLicencesFromName(name) {
return licenciesJson.filter((elem) => elem.lastname=== name);
}
function getLicenciesFromLicenceAndName(licence, name) {
return licenciesJson.find((e) => e.licence === licence && e.lastname === name);
}
function getLicenciesFromNames(firstname, lastname) {
return licenciesJson.find((e) => e.lastname === lastname.toUpperCase() && e.firstname === firstname.toUpperCase());
}
function getPceRowRegistrationMono(embId, cat, catAge, club, clubId, licence, lastname, firstname, sex, dob ) {
return embId+';'+cat+';'+catAge+';'+cat+';'+club+';'+clubId+';;;;;;;1;'+licence+';'+lastname+
';'+firstname+';'+sex+';'+dob+';NT;Nt;;;Nt;;;;;;;;;;Nt;;;\n';
}
function getAgeCategoryFromDob(dob) {
return getAgeCategoryFromYear(Number(dob.substr(0,4)));
}
function getAgeCategoryFromYear(year) {
let nowYear = new Date();
nowYear = nowYear.getFullYear();
let diff = nowYear - year;
if(diff<15) return 'M';
else if(diff<17) return 'C';
else if(diff<19) return 'J';
else if(diff<35) return 'S';
else return 'V';
}