-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
63 lines (54 loc) · 2.06 KB
/
script.js
File metadata and controls
63 lines (54 loc) · 2.06 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
56
57
58
59
60
61
62
63
// Practising with RDW Open Data
const endpointOne = 'https://opendata.rdw.nl/resource/b3us-f26s.json'; // API endpoint - Charging Points (dataset 1)
const selectedColumn = 'areaid';
// NPR dataset has also Charging POints data - Discuss if I'm going to use that dataset. It contains all my needed variables.
// - accesspointlocation (long,lat) + PlaatsNaam is in it, but not at each place.
// - capacity && chargingPointCapacity, but not at each place.
// Fetching data - API
fetchingData(endpointOne).then((dataRDW) => {
const getAreaIdArray = newStringDataArray(dataRDW, selectedColumn);
const getCapacityArray = newDataArray(dataRDW, 'capacity');
// console.log('AreaId is:', getAreaIdArray);
// console.log('Charging Capacity is:', getCapacityArray);
});
// Receiving data using fetch()
async function fetchingData(url) {
try {
const response = await fetch(url); // Waits till the data is fetched
const data = await response.json(); // Waits till the data is formatted to JSON
return data; // Returns the JSON data
} catch {
console.log(err); // Catches and shows an error when it's occurring
}
}
// Filter and transform data - Make a new Array based on an unique key and checks if value is correct
function newDataArray(dataArray, key) {
return dataArray.map((item) => {
item[key] = Number(item[key]); // Makes all items from unique key a NUMBER type.
if (item[key] <= 0) {
// When item is lower than or equal to 0, return null
// console.log('Negative or zero value');
return null;
} else {
return item[key];
}
});
}
// NOT DONE YET Filter string data - Make a new Array based on an unique key and checks if value is correct
function newStringDataArray(dataArray, key) {
return dataArray.map((item) => {
item[key] = item[key];
// console.log(item[key])
if (item[key] === '') {
console.log('Empty string');
console.log(item);
return null;
} else {
return item[key];
}
});
}
// Clean & Transform data
// - transform random/incorrect data in NULL
// Combine datasets
// - Filter out which columns I do not use