-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathflespidata.js
74 lines (64 loc) · 2.1 KB
/
flespidata.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
(function () {
var myConnector = tableau.makeConnector();
myConnector.getSchema = function (schemaCallback) {
var cols = [{
id: "time",
dataType: tableau.dataTypeEnum.int
}, {
id: "latitude",
dataType: tableau.dataTypeEnum.float
}, {
id: "longitude",
dataType: tableau.dataTypeEnum.float
}, {
id: "location",
dataType: tableau.dataTypeEnum.string
}, {
id: "duration",
dataType: tableau.dataTypeEnum.int
}];
var tableSchema = {
id: "flespianalytics",
alias: "flespi analytics data",
columns: cols
};
schemaCallback([tableSchema]);
};
// https://flespi.io/gw/calcs/162/devices/183982/intervals/all?data=%7B%22count%22%3A100%7D
myConnector.getData = function(table, doneCallback) {
var tmpdata = JSON.parse(tableau.connectionData);
$.ajax("https://flespi.io/gw/calcs/" + tmpdata.calcid + "/devices/" + tmpdata.deviceid + "/intervals/all?data=%7B%22count%22%3A" + tmpdata.messagescount + "%7D", {
success: function(resp) {
var feat = resp.result,
tableData = [];
// Iterate over the JSON object
for (var i = 0, len = feat.length; i < len; i++) {
tableData.push({
"time": feat[i]["time"],
"latitude": feat[i]["position.latitude"],
"longitude": feat[i]["position.longitude"],
"location": feat[i]["location"],
"duration": feat[i]["duration"],
});
}
// append rows (messages) to the table
table.appendRows(tableData);
doneCallback();
},
headers: {
"Accept": "application/json",
"Authorization":"FlespiToken " + tableau.password
}
});
};
tableau.registerConnector(myConnector);
$(document).ready(function () {
$("#submitButton").click(function () {
tableau.connectionName = "flespianalytics";
// flespi token
tableau.password = $("#input_token").val();
tableau.connectionData = JSON.stringify({messagescount: $("#input_messages").val(), deviceid: parseInt($("#input_device").val()), calcid: parseInt($("#input_calc").val())})
tableau.submit();
});
});
})();