-
Notifications
You must be signed in to change notification settings - Fork 3
/
slomo_gsheet_script.js
108 lines (93 loc) · 2.75 KB
/
slomo_gsheet_script.js
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menuEntries = [
{name: "Download MLAB dataset", functionName: "importMLabData"}
];
ss.addMenu("SloMo", menuEntries);
ss.removeMenu("SloMo 1");
}
function importMLabData() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
// var sheet = ss.getActiveSheet();
var prodSheet = ss.getSheetByName("PROD");
if(prodSheet==null)
prodSheet = ss.insertSheet("PROD");
getJsonData("https://api.mlab.com/api/1/databases/slomo_mlab_db/collections/xpresults?apiKey=JGRi1YtRl0XpJqfrkULg_zrmLoJceS_m",prodSheet);
var labSheet = ss.getSheetByName("LAB");
if(labSheet==null)
labSheet = ss.insertSheet("LAB");
getJsonData("https://api.mlab.com/api/1/databases/slomo_mlab_db_lab/collections/xpresults?apiKey=JGRi1YtRl0XpJqfrkULg_zrmLoJceS_m",labSheet);
var devSheet = ss.getSheetByName("DEV");
if(devSheet==null)
devSheet = ss.insertSheet("DEV");
getJsonData("https://api.mlab.com/api/1/databases/slomo_mlab_db_dev/collections/xpresults?apiKey=JGRi1YtRl0XpJqfrkULg_zrmLoJceS_m",devSheet);
}
function getJsonData(url, sheet){
var responseString = UrlFetchApp.fetch(url).getContentText();
response = JSON.parse(responseString);
var rows = [],
data;
rows.push(["tries",
"bpm",
"cv",
"intervals",
"date",
"lat",
"long",
"accuracy",
"userAgent",
"date_of_birth",
"gender",
"heritage",
"city_size",
"q1",
"q2",
"q3",
"q4",
"q5",
"q6",
"q7"])
for (i = 0; i < response.length; i++) {
data = response[i];
rows.push([data.tries,
data.bpm,
data.cv,
data.intervals,
data.date,
data.lat,
data.long,
data.accuracy,
data.userAgent,
data.date_of_birth,
data.gender,
data.heritage,
data.city_size,
data.q1,
data.q2,
data.q3,
data.q4,
data.q5,
data.q6,
data.q7]);
}
dataRange = sheet.getRange(1, 1, rows.length, 20);
sheet.getRa
dataRange.setValues(rows);
}
function someFunction() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var sheet = ss.getActiveSheet();
var dataSet = [
{"id":"xyz","name":"xy"},
{"id":"zyx","name":"yx"}
];
var rows = [],
data;
for (i = 0; i < dataSet.length; i++) {
data = dataSet[i];
rows.push([data.id, data.name]);
}
dataRange = sheet.getRange(1, 1, rows.length, 2);
dataRange.setValues(rows);
}