Repository navigation
Expand file tree
/
Copy pathparse.js
More file actions
68 lines (62 loc) · 1.77 KB
/
Copy pathparse.js
File metadata and controls
68 lines (62 loc) · 1.77 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
64
65
66
67
68
var csv = require('csv');
var request = require('request');
const https = require("https");
var csvUrl = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_19-covid-Confirmed.csv';
var etl = [];
exports.data = etl;
exports.run = function(callback){
request.get(csvUrl, {
columns: true
}, function (error, response, body) {
if (!error && response.statusCode == 200) {
let data = body;
process(data, callback);
}
});
}
function process(data, callback){
etl = [];
return csv.parse(data, {
columns : true,
on_record : (record, {lines}) => {
var columns = Object.keys(record);
columns.forEach(col => {
loadEtl(record, col);
});
return record
}
}, function(err, output){
callback(etl);
})
}
function loadEtl(record, col){
let skip = ['Province/State','Country/Region','Lat','Long'];
if(skip.includes(col)){
return;
}
else{
let ct = parseInt(record[col]);
if(ct > 0){
var rec = {
//"Location" : record["Location"],
//"Label" : record["Label"],
Country : record['Country/Region'],
State_Province : record['Province/State'] ? record['Province/State'] : record['Country/Region'],
Confirmed : ct,
Date : col,
Lat : parseFloat(record["Lat"]),
Long : parseFloat(record["Long"])
}
rec.Label = (record['Province/State'] + ' [' + record['Country/Region'] + ']').trim();
rec.Location = record["Lat"] + ',' + record["Long"];
etl.push(rec);
}
else if(ct != 0){
//console.log(record);
}
}
}
exports.run(function(d){
console.log(d[d.length - 1]);
console.log(d.length);
});