-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.gs
More file actions
59 lines (52 loc) · 1.98 KB
/
code.gs
File metadata and controls
59 lines (52 loc) · 1.98 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
function getJSON() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const s = ss.getSheetByName("data");
const s2 = ss.getSheetByName("state");
const url = "https://api.covidtracking.com/v1/states/daily.json";
const response = UrlFetchApp.fetch(url).getContentText();
const responseJSON = JSON.parse(response);
const result = responseJSON.map(r => [r.state, r.death, r.positive, r.date]);
// cutting data in-half, if needed
const halfLength = Math.ceil(result.length / 1);
let halfData = result.splice(0, halfLength);
dataRange = s.getRange(2, 1, halfData.length, 4).setValues(halfData);
}
function returnData() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const s2 = ss.getSheetByName("state");
const readRange = s2.getRange(1, 1, s2.getLastRow(), s2.getLastColumn()).getDisplayValues();
const chartData = readRange.map(r => [r[0], parseInt(r[1]), parseInt(r[2])]);
console.log(chartData)
chartData[0][2] = "Positive Cases";
chartData[0][1] = "Deaths";
console.log(chartData)
return chartData;
}
function returnData2() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const s2 = ss.getSheetByName("dates");
const readRange = s2.getRange(1, 1, s2.getLastRow(), 3).getDisplayValues();
const chartData2 = readRange.map(r => [r[0], parseInt(r[2])]);
chartData2[0][1] = "Deaths";
chartData2[0][0] = {
type: 'date',
id: 'date'
};
console.log(chartData2)
return chartData2;
}
function returnData3() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const s2 = ss.getSheetByName("dates");
const readRange = s2.getRange(1, 1, s2.getLastRow(), 5).getDisplayValues();
const chartData3 = readRange.map(r => [r[0], parseInt(r[2]), parseInt(r[4])]);
console.log(chartData3)
chartData3[0][2] = "Cases";
chartData3[0][1] = "Deaths";
chartData3[0][0] = {
type: 'date',
id: 'date'
};
console.log(chartData3)
return chartData3;
}