-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraph.html
134 lines (125 loc) · 3.76 KB
/
graph.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<title>Smart Room Sensor</title>
<html>
<head>
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/css/materialize.min.css">
<link rel="stylesheet" type="text/css" href="./bower_components/c3/c3.min.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/materialize/0.97.8/js/materialize.min.js"></script>
<script src="./bower_components/d3/d3.min.js" charset="utf-8"></script>
<script src="./bower_components/c3/c3.js"></script>
<script>
var chart;
$(function(){
load();
window.setInterval(update,10000);
});
function load(){
var value = $("#building-select").val();
$.get("db/getEnergy.php?building=kearney",{
},function(data){
console.log("select loading");
data = JSON.parse(data);
var powers = ['data1'];
var counts = ['data2'];
var xpower = ['x1'];
var xcount = ['x2'];
for(var i=0; i<data.length;i++){
if(data[i].power){
data[i].time = data[i].time.substr(0,data[i].time.length-8);
data[i].power = parseInt(data[i].power);
xpower.push(data[i].time);
powers.push(data[i].power);
}
if(data[i].count){
data[i].count = parseInt(data[i].count);
xcount.push(data[i].time);
counts.push(data[i].count);
}
}
console.log(data);
chart = c3.generate({
bindto:"#roomCount",
data:{
xs:{
'data1':'x1',
'data2':'x2'
},
xFormat: '%Y-%m-%d %H:%M:%S',
columns:[
xpower,
xcount,
powers,
counts
],
types:{
data1:'area',
data2:'line'
}
},
names:{
data1: 'power',
data2: 'count'
},
axis:{
x:{
type: 'timeseries',
tick:{
format:'%Y-%m-%d %H:%M:%S'
}
}
}
});
});
}
function update(){
$.get("db/getEnergy.php?building=kearney",{
floor:1,
room:0
},function(data){
data = JSON.parse(data);
//chart.load(data);
});
}
/*test = 30;
window.temp = 99;
setInterval(function(){ showCount(0, test); }, 1000);
function showCount(room) {
window.test = 88;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
test = this.responseText;
if (test == temp) return;
window.temp = test;
document.getElementById("roomCount").innerText = test;
anotherDataSet = [
{ y: '2003', a: 100, b: 80 },
{ y: '2004', a: 100, b: 20 },
{ y: '2005', a: 100, b: 30 },
{ y: '2006', a: 100, b: 90 },
{ y: '2007', a: 75, b: 65 },
{ y: '2008', a: 50, b: test },
{ y: '2009', a: 75, b: 65 },
{ y: '2010', a: 50, b: 40 },
{ y: '2011', a: 75, b: 65 },
{ y: '2012', a: 100, b: 90 }]
graph.setData(anotherDataSet);
}
};
xmlhttp.open("GET", "db/getCount.php?floor=1&room=" + room, true);
xmlhttp.send();
}*/
</script>
</head>
<body>
<nav>
<div class="nav-wrapper">
<ul id="nav-mobile" class="left hide-on-med-and-down">
<li><a href="index.html">Live</a></li>
<li class="active"><a href="#">Usage</a></li>
</ul>
</div>
</nav>
<div id="roomCount"></div>
</body>
</html>