-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathelectric.php
372 lines (339 loc) · 10.4 KB
/
electric.php
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
<?php
require_once( 'session.php' );
require_once( 'standard_page_top.php' );
?>
<script type='application/javascript' src='../common/js/calendarPicker/jquery.calendarPicker.js'></script>
<link rel='stylesheet' type='text/css' href='../common/js/calendarPicker/jquery.calendarPicker.css'/>
<script type='application/javascript' src='../common/js/moment-with-locales.js'></script>
<style>
.grid-container
{
display: grid;
grid-template-columns: repeat( 5, 1fr );
top: -47px;
position: relative;
}
.grid-container>div
{
border: 2px solid black;
margin: 2px;
background-color: #928d81;
}
.grid-container select
{
width: 160px !important;
height: 100px;
background-color: #928d81;
border-bottom: 1px dashed #666;
}
</style>
<script>
var rawData = [];
function fetchData(){
var fromDate = moment( calPickFrom.currentDate ).format( 'YYYY-MM-DD HH:mm' );
var toDate = moment( calPickTo.currentDate ).format( 'YYYY-MM-DD HH:mm' );
var query1 = {};
query1[ 'key' ] = 'use';
query1[ 'meter' ] = 1;
query1[ 'from_date' ] = fromDate;
query1[ 'to_date' ] = toDate;
var query2 = {};
query2[ 'key' ] = 'gen';
query2[ 'meter' ] = 2;
query2[ 'from_date' ] = fromDate;
query2[ 'to_date' ] = toDate;
var query = [];
query[0] = query1;
query[1] = query2;
var request = {};
request[ 'query' ] = query;
request[ 'response_type' ] = 'merge';
var jsonData = {};
jsonData[ 'user' ] = '<?php echo $user->getName() ?>';
jsonData[ 'session' ] = '<?php echo $user->getSession() ?>';
jsonData[ 'request' ] = request;
debugger;
$.ajax({
type: 'GET'
,url: 'electric_dl'
,data: jsonData
,contentType: 'application/json; charset=utf-8'
,dataType: 'json'
,success: function( data ){
debugger; // Check the result
console.log( data );
rawData = []; // Reset data array in case this is a re-run
$.each( data.response.answer, function( key, value ){
rawData.push( {"date": value.date, "con": value.watts, "gen": 0 } );
/*
if( value[0] == 1){
// $( '#consumption > tbody:last-child' ).append('<tr><td>'+value[1]+'</td><td>'+value[2]+'</td><td>'+value[3]+'</td></tr>');
generate = false;
consume = true;
rawData.push( {"date": value.date, "con": value.watts, "gen": 0 } );
}
else{
// $( '#generation > tbody:last-child' ).append('<tr><td>'+value[1]+'</td><td>'+value[2]+'</td><td>'+value[3]+'</td></tr>');
generate = true;
consume = false;
rawData.push( {"date": value[1], "con": 0, "gen": value[2] } );
}
*/
});
chart1 = doChart( false, true, rawData );
/*
if( consume ){
chart1 = doChart( generate, consume, rawData );
}
*/
}
,failure: function( errMsg ){
debugger; // Check the result
console.log( errMsg );
}
});
/*
var generate = false;
var consume = false;
// Make ajax call to data source
$.getJSON( url_string, function( data ){
rawData = []; // Reset data array in case this is a re-run
$.each( data.answer[ 'allData' ], function( key, value ){
if( value[0] == 1){
$( '#consumption > tbody:last-child' ).append('<tr><td>'+value[1]+'</td><td>'+value[2]+'</td><td>'+value[3]+'</td></tr>');
generate = false;
consume = true;
rawData.push( {"date": value[1], "con": value[2], "gen": 0 } );
}
else{
$( '#generation > tbody:last-child' ).append('<tr><td>'+value[1]+'</td><td>'+value[2]+'</td><td>'+value[3]+'</td></tr>');
generate = true;
consume = false;
rawData.push( {"date": value[1], "con": 0, "gen": value[2] } );
}
});
if( consume ){
chart1 = doChart( generate, consume, rawData );
}
});
*/
}
var calPickFrom;
var calPickTo;
$( document ).ready( function(){
// QQQ Check out the calendars that support aselecting a date RANGE
// QQQ http://roberto.open-lab.com/2010/03/23/so-hard-to-have-a-date/
calPickFrom = $( '#cpf' ).calendarPicker({
monthNames: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
,dayNames: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
//,useWheel: true
//,callbackDelay: 500
,years: 2 // Two on each side of selected
,months: 4 // Four on each side of selected
,days: 5 // Five on each side of selected
,date: new Date( (new Date().valueOf()) - (1000 * 60 * 60 * 24 * 7) ) // Last week
,showDayArrows: true
,callback: function( cal ){
$( '#cpfd' ).html( 'From date: ' + cal.currentDate );
}});
calPickTo = $( '#cpt' ).calendarPicker({
monthNames: [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' ]
,dayNames: [ 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ]
//,useWheel: true
//,callbackDelay: 500
,years: 2 // Two on each side of selected
,months: 4 // Four on each side of selected
,days: 5 // Five on each side of selected
,date: new Date() // Today
,showDayArrows: true
,callback: function( cal ){
$( '#cptd' ).html( 'To date: ' + cal.currentDate );
}});
fetchData();
});
</script>
<div class='grid-container' style='grid-auto-flow: row;'>
<div>
<div>Where</div>
<div>
<select id='LOC' size='3' style='width: 95px;'>
<option value='0'>Home</option>
<option value='1'>Parents</option>
<option value='2'>Rental 1</option>
<option value='3'>Rental 2</option>
<option value='4'>Rental 3</option>
</select>
</div>
</div>
<div>
<div>What</div>
<div>
<select multiple id='USE' size='3' style='width: 95px;'>
<option value='0'>Usage</option>
</select>
</div>
</div>
<div>
<div>What2</div>
<div>
<select multiple id='GEN' size='3' style='width: 95px;'>
<option value='0'>Generation</option>
</select>
</div>
</div>
<div>
<div>From <button onclick='calPickFrom.changeDate( new Date() );' style='line-height: 11px; float: right; position: relative; top: 2px; right: 2px;'>Today</button></div>
<div id='cpf' style='width: 340px'></div>
<span id='cpfd'></span>
<!--
<div>
<input type='date' id='FROM' size='10' value='' max='' min='' step='1'/>
</div>
-->
</div>
<div>
<div>To <button onclick='calPickTo.changeDate( new Date() );' style='line-height: 11px; float: right; position: relative; top: 2px; right: 2px;'>Today</button></div>
<div id='cpt' style='width: 340px'></div>
<span id='cptd'></span>
<!--
<div>
<input type='date' id='TO' size='10' value='' max='' min='' step='1'/>
</div>
-->
</div>
</div>
<button onClick='fetchData();'>Clicker</button>
<style>
#chartdiv {
width: 100%;
height: 500px;
}
</style>
<script type='application/javascript' src='../common/js/amcharts/amcharts.js'></script>
<script type='application/javascript' src='../common/js/amcharts/serial.js'></script>
<script type='application/javascript' src='../common/js/amcharts/themes/dark.js'></script>
<div id='chartdiv' style='width: 90%; height: 400px; background-color: #282828; margin: 0 auto; padding: 10px;'></div>
<script>
var chart1;
var chart2;
function doChart( g, c, rd ){
if( g ){
}
else{
}
debugger;
var chart = AmCharts.makeChart( 'chartdiv', {
"type": "serial",
"theme": "dark",
"dataProvider": rd,
"marginTop": 20,
"marginRight": 70,
"marginLeft": 40,
"marginBottom": 20,
"autoMargins": true,
"valueScrollbar":{
"enabled": false,
"offset":30
},
"valueAxes": [{
"id":"v1",
"axisColor": "#FF6600",
"axisThickness": 2,
"axisAlpha": 1,
"position": "left"
}, {
"id":"v1",
"axisColor": "#B0DE09",
"axisThickness": 2,
"gridAlpha": 0,
"offset": 50,
"axisAlpha": 1,
"position": "left"
}],
"graphs": [{
"valueField": "con",
"valueAxis": "v1",
"connect": false,
"lineColor": "#FF6600",
"bullet": "round",
"bulletBorderThickness": 1,
"hideBulletsCount": 30,
"title": "red line",
/* "balloonText":"<div style='margin:10px; text-align:left;'><span style='font-size:13px'>[[category]]</span><br><span style='font-size:18px'>Value:[[value]]</span>", */
"balloonText":"[[value]]",
"fillAlphas": 0
}, {
"valueField": "gen",
"valueAxis": "v1",
"connect": false,
"lineColor": "#B0DE09",
"bullet": "triangleUp",
"bulletBorderThickness": 1,
"hideBulletsCount": 30,
"title": "green line",
/* "balloonText":"<div style='margin:10px; text-align:left;'><span style='font-size:13px'>[[category]]</span><br><span style='font-size:18px'>Value:[[value]]</span>", */
"balloonText":"[[value]]",
"fillAlphas": 0
}],
"chartCursor": {
"graphBulletSize": 1.5,
"zoomable":false,
"valueZoomable":false,
"categoryBalloonText": "[[category]]",
"categoryBalloonDateFormat": "YYYY/MM/DD JJ:NN",
"cursorAlpha":0,
"valueLineEnabled":true,
"valueLineBalloonEnabled":true,
"valueLineAlpha":0.2
},
"dataDateFormat": "YYYY/MM/DD JJ:NN",
"categoryField": "date",
"categoryAxis": {
"parseDates": true,
"minPeriod": "mm",
"axisAlpha": 0,
"gridAlpha": 0,
"inside": true,
"title": "X axis title here",
"tickLength": 0
},
"export": {
"enabled": false
}
});
return chart;
}
</script>
<div style='display: grid; grid-template-columns: repeat( 2, 1fr );'>
<div style='width: 50%; margin: 5px; padding: 5px; font-family: ariel; font-size: normal;'>
Electric Consumption
<table id='consumption' style='width: 100%'>
<thead>
<tr>
<th>date</th>
<th>watts</th>
<th>volts</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div style='width: 50%; margin: 5px; padding: 5px; font-family: ariel; font-size: normal;'>
Electric Generation
<table id='generation' style='width: 100%'>
<thead>
<tr>
<th>date</th>
<th>watts</th>
<th>volts</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<?php
require_once( 'standard_page_foot.php' );
?>