forked from levizimmerman/fe3-assessment-3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcleandata.js
More file actions
55 lines (46 loc) · 1.4 KB
/
cleandata.js
File metadata and controls
55 lines (46 loc) · 1.4 KB
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
/*---------------------------------
Data cleanen
----------------------------------*/
var doc = d3.text('./index.csv')
.mimeType('text/plain;charset=iso88591') // Removed the strange signs from the data.
.get(onload);
function onload(err, doc) {
if (err) throw err;
doc = doc.replace(/"/g, '') // Remove doube quotes (stackoverflow)
doc = doc.replace(/;/g, ', ') // Remove semicolon
var header = doc.indexOf('2005');
var footer = doc.indexOf('© Centraal');
doc = doc.slice(header, footer); //Removes the header and footer
// First data set
var vacation = d3.csvParseRows(doc, vacationNum)
function vacationNum(d) {
return {
year: d[0],
totaalNed: Number(d[3]),
totaalBuiten: Number(d[28])
}
}
//Second data set
var dataCountries = d3.csvParseRows(doc, countries)
function countries(d) {
// Vakanties buiten Nederland
return {
year: d[0],
Country: [
"België", "Luxemburg", "Frankrijk", "Spanje", "Portugal","Oostenrijk", "Zwitserland"
],
Code: ["BEL", "LUX", "FRA", "ESP", "PRT", "AUT", "CHE"],
vacationNum: [
Number(d[29]),
Number(d[30]),
Number(d[31]),
Number(d[32]),
Number(d[33]),
Number(d[34]),
Number(d[35]),
]
}
}
// console.log(vacation)
// console.log(dataCountries)
}