-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.js
42 lines (38 loc) · 1.4 KB
/
graph.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
function plot(csvData, location){
var firstrows = csvData.split("\r\n")
var lastHours = firstrows.slice(firstrows.length - 5000,firstrows.length)
var condensed = []
var lastTempIndex = 0
for (var i = 0; i< lastHours.length; i++) {
var currTemp = lastHours[i].split(",")[1]
if (i === 0 || i === lastHours.length-1) {
condensed.push(lastHours[i])
} else {
var lastTemp = lastHours[i-1].split(",")[1]
var nextTemp = lastHours[i+1].split(",")[1]
if (currTemp !== lastTemp || currTemp !== nextTemp) {
condensed.push(lastHours[i])
}
}
if (currTemp !== undefined) {
lastTempIndex = i
}
}
var date = new Date(parseInt(lastHours[lastTempIndex].split(",")[0])*1000);
var currTime = date.toLocaleString()
var currTemp = lastHours[lastTempIndex].split(",")[1]
// insert current temp
document.getElementById("freezer1-current-temp").innerHTML = currTemp + "° C <br/> Recorded at: " + currTime
secondrows = [["time", "temp"]]
for(var i = 0; i< condensed.length; i++){
var next = condensed[i].split(",")
secondrows.push([parseInt(next[0]), parseFloat(next[1])])
}
var chart = c3.generate({
bindto: "#freezer1-chart",
data: {
x: 'time',
rows: secondrows
}
})
}