-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReport.js
More file actions
58 lines (54 loc) · 1.85 KB
/
Report.js
File metadata and controls
58 lines (54 loc) · 1.85 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
var _data = {};
fetch('https://api.covid19india.org/raw_data6.json')
.then(response => {
console.log('response status : ' + response.status);
response.json()
.then(data =>{
_data = data["raw_data"];
console.log(`${_data.length} data received!`);
})
.catch(err=>{
console.log('Error after receiving data: ', err);
})
})
.catch(error => {
console.log('Error occurred to fetch data: ', error);
})
//Random
'length' in ['width', 'breadth', 'height'] //Outputs true. LOL
keys = Object.keys(_data[0]);
// A function that can group the data by the field provided for n number of data
// Usage : groupBy('nationality', 100)
// outputs group by nationality count for first 100 records
groupBy = function(field, count){ //count is optional
if (!field) console.log('group by what?');return;
report = {};
data = count ? _data.slice(0, count) : _data; //limiting data
if (keys.includes(field)){
for(row of data){
value = row[field];
report[value] = value in report
? report[value] + 1 // If entry is present increment it
: 1; // If entry is not present, enter it.
}
}
else console.log('Field not present');
return report;
}
//backup
groupBy = function(field, count){ //count is optional
if (!field) console.log('group by what?');return;
report = {};
data = count ? _data.slice(0, count) : _data; //limiting data
if (keys.includes(field)){
for(row of data){
value = row[field];
report[value] = value in report
? report[value] + 1 // If entry is present increment it
: 1; debugger; // If entry is not present, enter it.
}
debugger;
}
else console.log('Field not present');
return report;
}