2014-04-15 01:09:02 +00:00
|
|
|
<script src="https://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
|
|
|
|
<link rel="stylesheet" href="https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
|
|
|
|
<script src="https://code.highcharts.com/highcharts.js"></script>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
graph_data = <%= raw @door_log_graph.to_json %>;
|
|
|
|
|
|
|
|
plot_band_start_hour = 16;
|
|
|
|
plot_band_end_hour = 22;
|
|
|
|
|
|
|
|
$(function() {
|
|
|
|
|
|
|
|
$( "#graph-dialog" ).dialog({
|
|
|
|
autoOpen: false,
|
|
|
|
height: 480,
|
|
|
|
width: 640,
|
|
|
|
modal: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
$( "#graph-button" ).click(function() {
|
|
|
|
$( "#graph-dialog" ).dialog( "open" );
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
$('#graph').highcharts({
|
|
|
|
chart: {
|
|
|
|
type: 'line',
|
|
|
|
zoomType : 'x'
|
|
|
|
},
|
|
|
|
colors: [
|
|
|
|
'#2f7ed8',
|
|
|
|
'#910000'
|
|
|
|
],
|
|
|
|
title: {
|
|
|
|
style : { fontSize: '12px' },
|
|
|
|
text: "Click a Door in the Legend to Hide"
|
|
|
|
},
|
|
|
|
subtitle: {
|
|
|
|
style : { fontSize: '10px' },
|
|
|
|
text: "Click and Drag to Zoom."
|
|
|
|
},
|
|
|
|
xAxis: {
|
|
|
|
type : 'datetime',
|
|
|
|
// grab plot bands from start and end time
|
|
|
|
plotBands: generatePlotBands(graph_data[0][0][0], graph_data[0][graph_data[0].length-1][0]),
|
|
|
|
labels : { align : "left" }
|
|
|
|
},
|
|
|
|
yAxis : {
|
|
|
|
title : {
|
|
|
|
text : "Door Open History"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
series: [
|
|
|
|
{
|
|
|
|
name: "Door 1",
|
|
|
|
data: graph_data[0]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Door 2",
|
|
|
|
data: graph_data[1]
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tooltip: {
|
|
|
|
shared: true,
|
|
|
|
xDateFormat: '%A %B %e, %l:%M %P',
|
|
|
|
formatter: function() {
|
|
|
|
output = '<b>'+ Highcharts.dateFormat(this.points[0].series.tooltipOptions.xDateFormat,this.x) +'</b><br/>';
|
|
|
|
total = 0;
|
|
|
|
this.points.forEach(function(e,i,a){
|
|
|
|
if(e.y == 1){ val = "Open"; } else { val = "Closed"; }
|
|
|
|
output += '<b><span style="color:'+e.series.color+'">'+e.series.name +'</span>: ' + val +'</b><br/>';
|
|
|
|
});
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plotOptions: {
|
|
|
|
line: {
|
|
|
|
marker: {
|
|
|
|
enabled: false
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Highcharts.setOptions({
|
|
|
|
global : {
|
|
|
|
useUTC : false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function generatePlotBands(start,end){
|
|
|
|
plotBands = new Array();
|
|
|
|
for (var d = new Date(start); d <= end; d.setDate(d.getDate() + 1)) {
|
|
|
|
// weekends
|
|
|
|
if(d.getDay()%6==0){
|
|
|
|
// highlight the whole day
|
|
|
|
plotBands.push({
|
|
|
|
color: '#eee',
|
|
|
|
from: d.setHours(0),
|
|
|
|
to: d.setHours(23)
|
|
|
|
});
|
|
|
|
// weekend hours
|
|
|
|
plotBands.push({
|
|
|
|
color: '#94C9EC',
|
|
|
|
from: d.setHours(12),
|
|
|
|
to: d.setHours(18)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else if(d.getDay()==3){
|
|
|
|
// special wednesday hours
|
|
|
|
plotBands.push({
|
|
|
|
color: '#94C9EC',
|
|
|
|
from: d.setHours(12),
|
|
|
|
to: d.setHours(plot_band_end_hour)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// open hours
|
|
|
|
plotBands.push({
|
|
|
|
color: '#82DAC9',
|
|
|
|
from: d.setHours(plot_band_start_hour),
|
|
|
|
to: d.setHours(plot_band_end_hour)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return plotBands;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div id="graph-dialog" title="Door Status">
|
|
|
|
|
|
|
|
<div id="graph" style="height: 400px; width: 600px; float: right;"></div>
|
|
|
|
|
|
|
|
<%= form_tag(nil, :method => :get) do %>
|
|
|
|
<label>Start Date
|
|
|
|
<input id="start" name="start" type="date" value="<%= @start_date.to_date.to_s %>" />
|
|
|
|
</label>
|
|
|
|
<label>End Date
|
|
|
|
<input id="end" name="end" type="date" value="<%= @end_date.to_date.to_s %>" />
|
|
|
|
</label>
|
|
|
|
<%= submit_tag("Change Date", :name => nil, :class => 'btn') %>
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<h1>Door Logs <button id="graph-button" class="btn">View Graph</button></h1>
|
2012-08-25 06:28:00 +00:00
|
|
|
|
|
|
|
<%= link_to 'Download Door Logs', download_path %>
|
2012-09-17 04:01:21 +00:00
|
|
|
<a href="#" onclick="$('#log-guide').toggle();">Show Log Guide</a>
|
|
|
|
<div id="log-guide" style="display: none;">
|
|
|
|
<pre>
|
|
|
|
Guide to Card Number storage:
|
|
|
|
cardnum = (R+(r*32767)), convert to hex
|
|
|
|
|
|
|
|
Guide to log keys and data:
|
2013-12-02 09:03:40 +00:00
|
|
|
|
|
|
|
Commands:
|
|
|
|
* rem_ = remote command issues via web UI (#=user id)
|
|
|
|
Statuses:
|
|
|
|
* armed = current status of alarm arming
|
|
|
|
* activated = current status of alarm ringing
|
|
|
|
* alarm_2 = current status of alarm sensor 2
|
|
|
|
* alarm_3 = current status of alarm sensor 3
|
|
|
|
* door_1_locked = status of door 1
|
|
|
|
* door_2_locked = status of door 2
|
|
|
|
Log Entries:
|
2012-09-17 04:01:21 +00:00
|
|
|
* A=alarm armed (# level)
|
|
|
|
* a=added user (# usernum)
|
|
|
|
* C=keypad command (# command)
|
|
|
|
* c=second half
|
|
|
|
* c=checked user (0=failed, #=found usernum)
|
|
|
|
* D=denied access (# card num)
|
|
|
|
* d=second half
|
|
|
|
* d=deleted user (# usernum)
|
|
|
|
* E=second (#=second)
|
|
|
|
* F=priv fail (0=wrong pw, 1=too many attempts, 2=not logged in)
|
|
|
|
* f=second half
|
|
|
|
* f=card fail (#=usermask)
|
|
|
|
* G=granted access (# card num)
|
|
|
|
* g=second half of card
|
|
|
|
* H=hour (#=hour)
|
|
|
|
* i=attempt to write to invalid eeprom address (# usernum)
|
|
|
|
* I=attempt to delete from invalid eeprom address (# usernum)
|
|
|
|
* L=locked (1=door1, 2=door2, 3=bedtime)
|
|
|
|
* M=minute (#=minute)
|
|
|
|
* m=alarm state (# level)
|
2014-02-01 01:41:52 +00:00
|
|
|
* p=power restored / arduino boot (1)
|
2012-09-17 04:01:21 +00:00
|
|
|
* R=read tag (# card num)
|
|
|
|
* r=second half of tag
|
|
|
|
* Q=superuser authed (#=superuser)
|
|
|
|
* S=auth (0=privileged mode enabled)
|
|
|
|
* s=alarm sensor (# zone)
|
|
|
|
* t=alarm trained (#=sensor value)
|
|
|
|
* T=alarm triggered (0)
|
|
|
|
* U=unlocked door (1=door1, 2=door2, # card num)
|
|
|
|
* u=second half of card
|
|
|
|
* Z=user db cleared (0)
|
|
|
|
* z=log cleared (0)
|
|
|
|
</pre>
|
|
|
|
</div>
|
2012-08-25 06:28:00 +00:00
|
|
|
<table>
|
|
|
|
<tr>
|
2012-09-16 05:52:17 +00:00
|
|
|
<th>Date</th>
|
2012-08-25 06:28:00 +00:00
|
|
|
<th>Key</th>
|
|
|
|
<th>Data</th>
|
|
|
|
<th></th>
|
|
|
|
<th></th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
|
2012-09-16 05:52:17 +00:00
|
|
|
<% @divided_tmp = nil %>
|
2012-08-25 06:28:00 +00:00
|
|
|
<% @door_logs.each do |door_log| %>
|
|
|
|
<tr>
|
2012-09-16 05:52:17 +00:00
|
|
|
<td><%= door_log.created_at %></td>
|
2012-08-25 06:28:00 +00:00
|
|
|
<td><%= door_log.key %></td>
|
|
|
|
<td><%= door_log.data %></td>
|
2012-09-16 04:41:11 +00:00
|
|
|
<%
|
2012-09-16 05:52:17 +00:00
|
|
|
if door_log.key == 'r' || door_log.key == 'd' ||door_log.key == 'g'
|
|
|
|
@divided_tmp = door_log.data.to_i
|
|
|
|
elsif (door_log.key == 'R' || door_log.key == 'D' || door_log.key == 'G') && !@divided_tmp.nil? %>
|
2012-09-16 04:41:11 +00:00
|
|
|
<td>
|
|
|
|
<%= case door_log.key
|
2012-09-16 05:52:17 +00:00
|
|
|
when 'R'
|
2012-09-16 04:41:11 +00:00
|
|
|
"Read"
|
2012-09-16 05:52:17 +00:00
|
|
|
when 'D'
|
2012-09-16 04:41:11 +00:00
|
|
|
"Denied"
|
2012-09-16 05:52:17 +00:00
|
|
|
when 'G'
|
2012-09-16 04:41:11 +00:00
|
|
|
"Granted"
|
|
|
|
end %>
|
2012-09-16 09:53:45 +00:00
|
|
|
<% @cardnum = (door_log.data.to_i+(@divided_tmp*32767)).to_s(16) %>
|
|
|
|
<%= "Card: "+@cardnum %>
|
2013-10-04 09:59:41 +00:00
|
|
|
<% @card = Card.find(:first,:conditions=>['lower(card_number) = ?', @cardnum.downcase]) %>
|
2012-12-16 03:37:44 +00:00
|
|
|
<%= "("+@card.user.name+")" unless @card.nil? %>
|
2012-09-16 04:41:11 +00:00
|
|
|
</td>
|
|
|
|
<% else
|
2012-09-16 05:52:17 +00:00
|
|
|
@divided_tmp = nil
|
2012-09-16 04:41:11 +00:00
|
|
|
end %>
|
2012-08-25 06:28:00 +00:00
|
|
|
</tr>
|
|
|
|
<% end %>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|