-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinterface.html
executable file
·172 lines (148 loc) · 3.9 KB
/
interface.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
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Lidless</title>
<style>
div.trace {
float: right;
width:76%;
height:120px;
margin: auto;
}
div.ratio {
float: left;
text-align: center;
font-size: 63pt;
vertical-align: middle;
width: 20%;
height: 120px;
}
</style>
</head>
<!--[if lte IE 9]><script language="javascript" type="text/javascript" src="/flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="/flot/jquery.js"></script>
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.js"></script>
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.time.js"></script>
</script>
<script type="text/javascript">
var cams;
var history_timeout;
var period = 3600*1000;
function camera_discover() {
$.ajax({
url: '/api',
dataType: 'json',
success: function(data) {
var graphhtml = '';
for (var i in data.data) {
var camname = data.data[i];
graphhtml = graphhtml + '<div style="text-align: left; width: 100%; float: left;"><div id="' + camname + 'description">' + camname + '</div><div id="' + camname + 'ratio" class="ratio">Unk%</div><div id="' + camname + 'trace" style="float: right;" class="trace"></div></div>';
}
$('#graphs').html(graphhtml);
cams = data.data;
start_ratio();
start_description();
start_history();
}
});
}
function ajax_description(camname) {
$.ajax({
url: '/api/' + camname + '/description',
dataType: 'json',
success: function(data) {
if (data.data != null) {
$('#' + camname + 'description').html(data.data);
}
}
});
}
function start_description() {
for (var i in cams) {
ajax_description(cams[i]);
}
}
function ajax_ratio(camname) {
$.ajax({
url: '/api/' + camname + '/ratio',
dataType: 'json',
success: function(data) {
var mytext;
if (data.data == null) {
var mytext = "Unk%";
} else {
mytext = Math.round(data.data * 100) + '%';
}
$('#' + camname + 'ratio').html(mytext);
}
});
}
function start_ratio() {
for (var i in cams) {
ajax_ratio(cams[i]);
}
setTimeout(start_ratio, 10000);
}
function ajax_history(camname) {
$.ajax({
url: '/api/' + camname + '/history/' + period,
dataType: 'json',
success : function(data) {
var localData = new Array(data.data.length);
var timeZoneOffsetMs = new Date().getTimezoneOffset() * 60 * 1000; //convert from minutes to ms
for(var i = 0; i < localData.length;i++){
localData[i] = data.data[i];
localData[i][0] += timeZoneOffsetMs;
}
$.plot($("#" + camname + "trace"), [localData], {
xaxis: { mode: "time" },
yaxis: { min: 0 }
});
}
});
}
function start_history() {
for (var i in cams) {
ajax_history(cams[i]);
}
history_timeout = setTimeout(start_history, period / 30);
}
function set_history(per) {
period = per;
clearTimeout(history_timeout);
start_history();
}
$(function () {
camera_discover();
$("#quarter").click(function () {
set_history(60*15*1000);
});
$("#hour").click(function () {
set_history(3600*1000);
});
$("#four").click(function () {
set_history(4*3600*1000);
});
$("#day").click(function () {
set_history(24*3600*1000);
});
$("#week").click(function () {
set_history(7*24*3600*1000);
});
});
</script>
<body style="height: 100%;">
<div id="graphs">
</div>
<div style="float: right; width:76%;height:120px;margin: auto; text-align: center;">
<tt>Note: times are UTC.</tt>
<button id="quarter">15 minutes</button>
<button id="hour">hour</button>
<button id="four">four hours</button>
<button id="day">1 day</button>
<button id="week">1 week</button>
<a href="https://github.com/eastein/lidless">code: github</a>
</div>
</body>
</html>