2012-08-25 06:28:00 +00:00
|
|
|
class DoorLogsController < ApplicationController
|
2012-09-16 10:24:54 +00:00
|
|
|
authorize_resource :except => :auto_download
|
|
|
|
before_filter :authenticate_user!, :except => :auto_download
|
2012-09-02 11:19:13 +00:00
|
|
|
|
2012-08-25 06:28:00 +00:00
|
|
|
# GET /door_logs
|
|
|
|
# GET /door_logs.json
|
|
|
|
def index
|
2014-10-08 02:55:34 +00:00
|
|
|
@door_logs = DoorLog.find(:all, :order => "created_at DESC", :limit => 1000)
|
2014-04-15 01:09:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
@start_date = DateTime.parse(params[:start])
|
|
|
|
@end_date = DateTime.parse(params[:end])
|
|
|
|
rescue
|
|
|
|
@start_date = DateTime.now - 2.weeks
|
|
|
|
@end_date = DateTime.now
|
|
|
|
end
|
|
|
|
|
|
|
|
@door_logs_by_hour = DoorLog.where("created_at > ? AND created_at < ? AND (key = ? OR key = ?)", @start_date, @end_date,"door_1_locked","door_2_locked").order("created_at ASC").group_by(&:key)
|
|
|
|
@door_log_graph = [
|
|
|
|
@door_logs_by_hour["door_1_locked"].map{|d| [d.created_at.to_time.to_i*1000, 1^d.data.to_i]}, # use XOR to invert 1 into 0 and vice versa
|
|
|
|
@door_logs_by_hour["door_2_locked"].map{|d| [d.created_at.to_time.to_i*1000, 1^d.data.to_i]}
|
|
|
|
]
|
|
|
|
|
|
|
|
# @door_logs_by_hour.each do |door_log|
|
|
|
|
# # Add one computer for activate, subtract one for deactivate
|
|
|
|
# if door_log.data == 1
|
|
|
|
#
|
|
|
|
# elsif door_log.data == 0
|
|
|
|
# mac_running_balance -= 1
|
|
|
|
# end
|
|
|
|
|
|
|
|
# @door_log_graph << [time.to_time.to_i*1000,mac_running_balance]
|
|
|
|
# end
|
|
|
|
|
|
|
|
|
2012-08-25 06:28:00 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # index.html.erb
|
|
|
|
format.json { render :json => @door_logs }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-16 10:24:54 +00:00
|
|
|
# GET /door_logs/download
|
2012-08-25 06:28:00 +00:00
|
|
|
def download
|
|
|
|
@results = DoorLog.download_from_door
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.json { render :json => @results }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-16 10:24:54 +00:00
|
|
|
# GET /door_logs/auto_download
|
|
|
|
def auto_download
|
|
|
|
@results = DoorLog.download_from_door
|
2013-12-02 02:32:08 +00:00
|
|
|
@status = DoorLog.download_status # for space_api
|
2012-09-16 10:24:54 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html # show.html.erb
|
|
|
|
format.json { render :json => @results }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-08-25 06:28:00 +00:00
|
|
|
end
|