-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.gs
75 lines (64 loc) · 1.82 KB
/
utils.gs
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
function promptForText(msg) {
var ui = SpreadsheetApp.getUi();
var result = ui.prompt(
msg+":",
ui.ButtonSet.OK_CANCEL);
// Process the user's response.
var button = result.getSelectedButton();
if(button == ui.Button.CANCEL) return null;
var text = result.getResponseText();
return text;
}
function getConfigDetails(){
var cfg = SpreadsheetApp.getActive().getSheetByName(CONFIG_SHEET_NAME);
var session_id=cfg.getRange(SESSION_ID_CELL).getValue();
var user_id=cfg.getRange(USER_ID_CELL).getValue();
var tz=cfg.getRange(TIME_ZONE_CELL).getValue();
return {
"peloton":{
"http_base":PELOTON_API_BASE,
"session_id":session_id,
"user_id":user_id,
"timezone":tz,
"http_options":
{
'headers':
{
'peloton-platform':PELOTON_PLATFORM,
'cookie':'peloton_session_id='+session_id
}
}
}
};
}
Array.prototype.max = function() {
return Math.max.apply(null, this);
};
Array.prototype.min = function() {
return Math.min.apply(null, this);
};
function findTimeSubarray(arr, property, timeSubarray) {
for (var i = 0; i < 1 + (arr.length - timeSubarray.length); i++) {
var j = 0;
for (; j < timeSubarray.length; j++)
{
console.log(arr[i + j][property]+" == "+timeSubarray[j]);
if (arr[i + j][property] != timeSubarray[j])
break;
}
console.log("i="+i+", j="+j);
if (j == timeSubarray.length)
return i;
}
return -1;
}
function groupByArray(xs, key) {
return xs.reduce(
function (rv, x) {
let v = key instanceof Function ? key(x) : x[key];
let el = rv.find((r) => r && r.key === v);
if (el) { el.values.push(x); }
else { rv.push({ key: v, values: [x] }); }
return rv; },
[]);
}