-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathview.php
More file actions
433 lines (373 loc) · 19.6 KB
/
view.php
File metadata and controls
433 lines (373 loc) · 19.6 KB
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<?php
defined('EMONCMS_EXEC') or die('Restricted access');
/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.
---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
*/
global $path, $embed, $session, $settings;
$userid = 0;
$v = 28;
$feedidsLH = "";
if (isset($_GET['feedidsLH'])) $feedidsLH = $_GET['feedidsLH'];
$feedidsRH = "";
if (isset($_GET['feedidsRH'])) $feedidsRH = $_GET['feedidsRH'];
$load_saved = "";
if (isset($_GET['load'])) $load_saved = $_GET['load'];
$apikey = "";
if (isset($_GET['apikey'])) $apikey = $_GET['apikey'];
$min_feed_interval = 10;
if (isset($settings['feed']['min_feed_interval'])) {
$min_feed_interval = (int) $settings['feed']['min_feed_interval'];
}
?>
<!--[if IE]><script src="<?php echo $path;?>Lib/flot/excanvas.min.js"></script><![endif]-->
<style>
[v-cloak] {
visibility: hidden
}
</style>
<link href="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
<link href="<?php echo $path; ?>Modules/graph/graph.css?v=<?php echo $v; ?>" rel="stylesheet">
<script src="<?php echo $path;?>Lib/flot/jquery.flot.merged.js"></script>
<!-- <script src="<?php echo $path;?>Lib/flot/jquery.flot.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.time.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.selection.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.touch.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.togglelegend.min.js"></script>
<script src="<?php echo $path;?>Lib/flot/jquery.flot.resize.min.js"></script>
<script src="<?php echo $path; ?>Lib/flot/jquery.flot.stack.min.js"></script>
-->
<script src="<?php echo $path; ?>Lib/flot/jquery.flot.stack.min.js"></script>
<script>var min_feed_interval = <?php echo $min_feed_interval; ?>;</script>
<script src="<?php echo $path;?>Modules/graph/vis.helper.js?v=<?php echo $v; ?>"></script>
<script src="<?php echo $path;?>Lib/misc/clipboard.js?v=<?php echo $v; ?>"></script>
<script src="<?php echo $path; ?>Lib/bootstrap-datetimepicker-0.0.11/js/bootstrap-datetimepicker.min.js"></script>
<script src="<?php echo $path; ?>Lib/vue.min.js?v=<?php echo $v; ?>"></script>
<h3><?php echo tr('Data viewer'); ?></h3>
<div id="error" style="display:none"></div>
<div id="navigation" style="padding-bottom:5px;">
<div class="input-prepend input-append" style="margin-bottom:0 !important">
<button class='btn graph_time_refresh' title="<?php echo tr('Refresh') ?>"><i class="icon-repeat"></i></button>
<select class='btn graph_time' style="width:110px; padding-left:5px">
<option value='1'><?php echo tr('1 hour') ?></option>
<option value='6'><?php echo tr('6 hours') ?></option>
<option value='12'><?php echo tr('12 hours') ?></option>
<option value='24'><?php echo tr('24 hours') ?></option>
<option value='168' selected><?php echo tr('1 Week') ?></option>
<option value='336'><?php echo tr('2 Weeks') ?></option>
<option value='720'><?php echo tr('Month') ?></option>
<option value='8760'><?php echo tr('Year') ?></option>
</select>
</div>
<!--
<button class='btn graph_time' type='button' data-time='1' title="<?php echo tr('Day') ?>"><?php echo tr('D') ?></button>
<button class='btn graph_time' type='button' data-time='7' title="<?php echo tr('Week') ?>"><?php echo tr('W') ?></button>
<button class='btn graph_time' type='button' data-time='30' title="<?php echo tr('Month') ?>"><?php echo tr('M') ?></button>
<button class='btn graph_time' type='button' data-time='365' title="<?php echo tr('Year') ?>"><?php echo tr('Y') ?></button>
-->
<button id='graph_zoomin' class='btn' title="<?php echo tr('Zoom In') ?>">+</button>
<button id='graph_zoomout' class='btn' title="<?php echo tr('Zoom Out') ?>">-</button>
<button id='graph_left' class='btn' title="<?php echo tr('Earlier') ?>"><</button>
<button id='graph_right' class='btn' title="<?php echo tr('Later') ?>">></button>
<div id="showcontrols" class="input-prepend input-append">
<span class="add-on"><?php echo tr('Show') ?></span>
<span class="add-on"><?php echo tr('missing data') ?>: <input type="checkbox" id="showmissing" style="margin-top:1px" /></span>
<span class="add-on"><?php echo tr('legend') ?>: <input type="checkbox" id="showlegend" style="margin-top:1px" /></span>
<span class="add-on"><?php echo tr('feed tag') ?>: <input type="checkbox" id="showtag" style="margin-top:1px" /></span>
</div>
<div style="clear:both"></div>
</div>
<div id="histogram-controls" style="padding-bottom:5px; display:none;">
<div class="input-prepend input-append">
<span class="add-on" style="width:100px"><b><?php echo tr('Histogram') ?></b></span>
<span class="add-on" style="width:75px"><?php echo tr('Type') ?></span>
<select id="histogram-type" style="width:150px">
<option value="timeatvalue" ><?php echo tr('Time at value') ?></option>
<option value="kwhatpower" ><?php echo tr('kWh at Power') ?></option>
</select>
<span class="add-on" style="width:75px"><?php echo tr('Resolution') ?></span>
<input id="histogram-resolution" type="text" style="width:60px"/>
</div>
<button id="histogram-back" class="btn" style="float:right"><?php echo tr('Back to main view') ?></button>
</div>
<div id="legend"></div>
<div id="placeholder_bound" style="width:100%; height:400px;">
<div id="placeholder"></div>
</div>
<div id="info">
<div class="input-prepend input-append" style="padding-right:5px">
<span class="add-on" style="width:50px"><?php echo tr('Start') ?></span>
<span id="datetimepicker1">
<input id="request-start" data-format="dd/MM/yyyy hh:mm:ss" type="text" style="width:140px" />
<span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
</span>
</div>
<div class="input-prepend input-append" style="padding-right:5px">
<span class="add-on" style="width:50px"><?php echo tr('End') ?></span>
<span id="datetimepicker2">
<input id="request-end" data-format="dd/MM/yyyy hh:mm:ss" type="text" style="width:140px" />
<span class="add-on"><i data-time-icon="icon-time" data-date-icon="icon-calendar"></i></span>
</span>
</div>
<div class="input-prepend input-append" style="padding-right:5px">
<span class="add-on" style="width:50px"><?php echo tr('Type') ?></span>
<select id="request-type" style="width:130px">
<option value="interval"><?php echo tr('Fixed Interval') ?></option>
<option value="daily"><?php echo tr('Daily') ?></option>
<option value="weekly"><?php echo tr('Weekly') ?></option>
<option value="monthly"><?php echo tr('Monthly') ?></option>
<option value="annual"><?php echo tr('Annual') ?></option>
</select>
</div>
<div class="input-prepend input-append" style="padding-right:5px">
<span class="fixed-interval-options">
<input id="request-interval" type="text" style="width:60px" />
<span class="add-on"><?php echo tr('Fix') ?> <input id="request-fixinterval" type="checkbox" style="margin-top:1px" /></span>
<span class="add-on"><?php echo tr('Limit to data interval') ?> <input id="request-limitinterval" type="checkbox" style="margin-top:1px" checked></span>
</span>
</div>
<div>
<div id="yaxis_left" class="input-append input-prepend">
<span id="yaxis-left" class="add-on"><?php echo tr('Y-axis').' ('.tr('Left').')' ?>:</span>
<span class="yaxis-minmax-label add-on"><?php echo tr('min') ?></span>
<input class="yaxis-minmax" id="yaxis-min" type="text" value="auto">
<span class="yaxis-minmax-label add-on"><?php echo tr('max') ?></span>
<input class="yaxis-minmax" id="yaxis-max" type="text" value="auto">
<button class="btn reset-yaxis"><?php echo tr('Reset') ?></button>
</div>
<div id="yaxis_right" class="input-append input-prepend">
<span id="yaxis-right" class="add-on"><?php echo tr('Y-axis').' ('.tr('Right').')' ?>:</span>
<span class="yaxis-minmax-label add-on"><?php echo tr('min') ?></span>
<input class="yaxis-minmax" id="yaxis-min2" type="text" value="auto">
<span class="yaxis-minmax-label add-on"><?php echo tr('max') ?></span>
<input class="yaxis-minmax" id="yaxis-max2" type="text" value="auto">
<button class="btn reset-yaxis"><?php echo tr('Reset') ?></button>
</div>
<button id="reload" class="btn" style="vertical-align:top"><?php echo tr('Reload') ?></button>
<button id="clear" class="btn" style="vertical-align:top"><?php echo tr('Clear All') ?></button>
</div>
<!--
var remove_null = $(".remove-null")[0].checked;
var remove_null_max_duration = $(".remove-null-max-duration").val();
-->
<div class="input-prepend input-append">
<span class="add-on"><?php echo tr('Remove null values') ?>:</span>
<span class="add-on"><input type="checkbox" class="remove-null" style="margin-top:3px" /></span>
<span class="add-on"><?php echo tr('Max fill length') ?>:</span>
<input type="text" class="remove-null-max-duration" value="900" style="width:60px"/>
<span class="add-on"><?php echo tr('s') ?></span>
</div>
<div id="window-info" style=""></div><br>
<div class="feed-options hide">
<div class="feed-options-header">
<div class="feed-options-show-options btn btn-default hide"><?php echo tr('Show options') ?></div>
<div class="feed-options-show-stats btn btn-default"><?php echo tr('Show statistics') ?></div>
<a href="#tables" class="feed-options-title">
<span class="caret pull-left"></span>
<?php echo tr('Feeds in view') ?>
</a>
</div>
<div id="tables">
<table id="feed-options-table" class="table">
<tr>
<th></th>
<th><?php echo tr('Feed') ?></th>
<th><?php echo tr('Type') ?></th>
<th><?php echo tr('Color') ?></th>
<th><?php echo tr('Fill') ?></th>
<th><?php echo tr('Stack') ?></th>
<th style='text-align:center'><?php echo tr('Scale') ?></th>
<th style='text-align:center'><?php echo tr('Offset') ?></th>
<th style='text-align:center'><?php echo tr('Delta') ?></th>
<th style='text-align:center'><?php echo tr('Average') ?></th>
<th><?php echo tr('DP') ?></th><th style="width:120px"></th>
</tr>
<tbody id="feed-controls"></tbody>
</table>
<table id="feed-stats-table" class="table hide">
<tr>
<th></th>
<th><?php echo tr('Feed') ?></th>
<th><?php echo tr('Quality') ?></th>
<th><?php echo tr('Min') ?></th>
<th><?php echo tr('Max') ?></th>
<th><?php echo tr('Diff') ?></th>
<th><?php echo tr('Mean') ?></th>
<th><?php echo tr('Stdev') ?></th>
<th><?php echo tr('Wh') ?></th>
</tr>
<tbody id="feed-stats"></tbody>
</table>
</div>
</div>
<br>
<div class="input-prepend input-append">
<button class="btn" id="showcsv" ><?php echo tr('Show CSV Output') ?></button>
<span class="add-on csvoptions"><?php echo tr('Time format') ?>:</span>
<select id="csvtimeformat" class="csvoptions">
<option value="unix"><?php echo tr('Unix timestamp') ?></option>
<option value="seconds"><?php echo tr('Seconds since start') ?></option>
<option value="datestr"><?php echo tr('Date-time string') ?></option>
</select>
<span class="add-on csvoptions"><?php echo tr('Null values') ?>:</span>
<select id="csvnullvalues" class="csvoptions">
<option value="show"><?php echo tr('Show') ?></option>
<option value="lastvalue"><?php echo tr('Replace with last value') ?></option>
<option value="remove"><?php echo tr('Remove whole line') ?></option>
</select>
<span class="add-on csvoptions"><?php echo tr('Headers') ?>:</span>
<select id="csvheaders" class="csvoptions">
<option value="showNameTag"><?php echo tr('Show name and tag') ?></option>
<option value="showName"><?php echo tr('Show name') ?></option>
<option value="hide"><?php echo tr('Hide') ?></option>
</select>
</div>
<div class="input-prepend">
<button id="download-csv" class="csvoptions btn "><?php echo tr('Download') ?></button>
</div>
<div class="input-append"><!-- just to match the styling of the other items -->
<button onclick="copyToClipboardCustomMsg(document.getElementById('csv'), 'copy-csv-feedback','<?php echo tr('Copied') ?>')" class="csvoptions btn hidden" id="copy-csv" type="button"><?php echo tr('Copy') ?> <i class="icon-share-alt"></i></button>
</div>
<span id="copy-csv-feedback" class="csvoptions"></span>
<textarea id="csv" style="width:98%; height:500px; display:none; margin-top:10px"></textarea>
<!-- Graph sidebar hidden element: moved to actual sidebar by javascript -->
<div id="sidebar_html" class="hide"><?php echo view("Modules/graph/Views/sidebar.php",array()); ?></div>
</div>
<script>
var apikey = "<?php echo $apikey; ?>";
var apikeystr = "";
if (apikey!="") apikeystr = "&apikey="+apikey;
</script>
<script src="<?php echo $path;?>Modules/graph/graph.js?v=<?php echo $v; ?>"></script>
<script src="<?php echo $path;?>Lib/moment.min.js?v=1"></script>
<script>
var _user = {
lang : "<?php if (isset($_SESSION['lang'])) echo $_SESSION['lang']; ?>"
}
_locale_loaded = function (event){
// callback when locale file loaded
graph_reload(); // redraw xaxis with correct monthNames and dayNames
}
</script>
<script src="<?php echo $path; ?>Lib/user_locale.js"></script>
<script src="<?php echo $path; ?>Lib/misc/gettext.js"></script>
<script>
var session_write = <?php echo $session["write"]; ?>;
var userid = <?php echo $userid; ?>;
var feedidsLH = "<?php echo $feedidsLH; ?>";
var feedidsRH = "<?php echo $feedidsRH; ?>";
var load_savegraphs = "<?php echo $load_saved; ?>";
var feeds = false;
var _lang = <?php
$lang['Select a feed'] = tr('Select a feed');
$lang['Please select a feed from the Feeds List'] = tr('Please select a feed from the Feeds List');
$lang['Select graph'] = tr('Select graph');
$lang['Show CSV Output'] = tr('Show CSV Output');
$lang['Hide CSV Output'] = tr('Hide CSV Output');
$lang['Lines'] = tr('Lines');
$lang['Bars'] = tr('Bars');
$lang['Points'] = tr('Points');
$lang['Steps'] = tr('Steps');
$lang['Histogram'] = tr('Histogram');
$lang['Move up'] = tr('Move up');
$lang['Move down'] = tr('Move down');
$lang['Window'] = tr('Window');
$lang['Length'] = tr('Length');
echo json_encode($lang) . ';';
echo "\n";
?>;
// Load public feeds for a particular user
if (public_userid) {
var public_username_str = "";
if (public_userid) public_username_str = public_username+"/";
$.ajax({
url: path+public_username_str+"feed/list.json", async: false, dataType: "json",
success: function(data_in) { feeds = data_in; }
});
} else {
// Load user feeds
$.ajax({
url: path+"feed/list.json"+apikeystr, async: false, dataType: "json",
success: function(data_in) { feeds = data_in; }
});
}
// stops a part upgrade error - this change requires emoncms/emoncms repo to also be updated
// keep button hidden if new version of clipboard.js is not available
if (typeof copyToClipboardCustomMsg === 'function') {
document.getElementById('copy-csv').classList.remove('hidden');
} else {
copyToClipboardCustomMsg = function () {}
}
if (load_savegraphs=="") {
// Assign active feedid from URL
var urlparts = window.location.pathname.split("graph/");
if (urlparts.length==2) {
var feedids = urlparts[1].split(",");
for (var z in feedids) {
var feedid = parseInt(feedids[z]);
if (feedid) {
var f = getfeed(feedid);
if (f==false) f = getfeedpublic(feedid);
if (f!=false) feedlist.push({id:feedid, name:f.name, tag:f.tag, yaxis:1, fill:0, scale: 1.0, average:0, delta:0, dp:1, plottype:'lines'});
}
}
}
// Left hand feed ids property
if (feedidsLH!="") {
var feedids = feedidsLH.split(",");
for (var z in feedids) {
var feedid = parseInt(feedids[z]);
if (feedid) {
var f = getfeed(feedid);
if (f==false) f = getfeedpublic(feedid);
if (f!=false) feedlist.push({id:feedid, name:f.name, tag:f.tag, yaxis:1, fill:0, scale: 1.0, average:0, delta:0, dp:1, plottype:'lines'});
}
}
}
// Right hand feed ids property
if (feedidsRH!="") {
var feedids = feedidsRH.split(",");
for (var z in feedids) {
var feedid = parseInt(feedids[z]);
if (feedid) {
var f = getfeed(feedid);
if (f==false) f = getfeedpublic(feedid);
if (f!=false) feedlist.push({id:feedid, name:f.name, tag:f.tag, yaxis:2, fill:0, scale: 1.0, average:0, delta:0, dp:1, plottype:'lines'});
}
}
}
}
graph_init_editor();
load_feed_selector();
graph_resize();
var timeWindow = 3600000*24.0*7;
var now = Math.round(+new Date * 0.001)*1000;
view.start = now - timeWindow;
view.end = now;
view.calc_interval();
graph_reload();
$(function(){
// manually add hide/show
$('#tables').collapse()
// trigger hide/show
$('.feed-options-title').on('click', function (event) {
event.preventDefault();
event.target.querySelector('.caret').classList.toggle('open');
$('#tables').collapse('toggle');
})
});
<?php
$translations = array(
"Received data not in correct format. Check the logs for more details" => tr("Received data not in correct format. Check the logs for more details"),
"Request error" => tr("Request error"),
"User" => tr("User"),
"Browser" => tr("Browser"),
"Authentication Required" => tr("Authentication Required")
);
printf("var translations = %s;\n",json_encode($translations));
?>
</script>