Commit 21629269 authored by hugo's avatar hugo
Browse files

added support for new axis f34 camera

parent 95bc6477
source "http://rubygems.org"
gem 'mysql2', '~> 0.4.9'
gem 'activerecord', '~> 5.1', '>= 5.1.4'
gem "sinatra", "~> 2.0.0"
gem "sinatra-contrib", "~> 2.0.0"
gem 'mysql2', '~> 0.5.1'
gem 'net-http-digest_auth', '~> 1.4', '>= 1.4.1'
gem 'activerecord', '~> 5.2', '>= 5.2.0'
gem "sinatra", "~> 2.0.1"
gem "sinatra-contrib", "~> 2.0.1"
gem 'thin', '~> 1.7', '>= 1.7.2'
gem 'pry'
gem 'rake', '12.1.0'
GEM
remote: http://rubygems.org/
specs:
activemodel (5.1.4)
activesupport (= 5.1.4)
activerecord (5.1.4)
activemodel (= 5.1.4)
activesupport (= 5.1.4)
arel (~> 8.0)
activesupport (5.1.4)
activemodel (5.2.0)
activesupport (= 5.2.0)
activerecord (5.2.0)
activemodel (= 5.2.0)
activesupport (= 5.2.0)
arel (>= 9.0)
activesupport (5.2.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
arel (8.0.0)
backports (3.10.3)
arel (9.0.0)
backports (3.11.3)
coderay (1.1.2)
concurrent-ruby (1.0.5)
daemons (1.2.5)
eventmachine (1.2.5)
i18n (0.9.1)
i18n (1.0.1)
concurrent-ruby (~> 1.0)
method_source (0.9.0)
minitest (5.10.3)
multi_json (1.12.2)
mustermann (1.0.1)
mysql2 (0.4.10)
minitest (5.11.3)
multi_json (1.13.1)
mustermann (1.0.2)
mysql2 (0.5.1)
net-http-digest_auth (1.4.1)
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
rack (2.0.3)
rack-protection (2.0.0)
rack-protection (2.0.1)
rack
rake (12.1.0)
sinatra (2.0.0)
sinatra (2.0.1)
mustermann (~> 1.0)
rack (~> 2.0)
rack-protection (= 2.0.0)
rack-protection (= 2.0.1)
tilt (~> 2.0)
sinatra-contrib (2.0.0)
sinatra-contrib (2.0.1)
backports (>= 2.0)
multi_json
mustermann (~> 1.0)
rack-protection (= 2.0.0)
sinatra (= 2.0.0)
rack-protection (= 2.0.1)
sinatra (= 2.0.1)
tilt (>= 1.3, < 3)
thin (1.7.2)
daemons (~> 1.0, >= 1.0.9)
......@@ -50,19 +51,20 @@ GEM
rack (>= 1, < 3)
thread_safe (0.3.6)
tilt (2.0.8)
tzinfo (1.2.4)
tzinfo (1.2.5)
thread_safe (~> 0.1)
PLATFORMS
ruby
DEPENDENCIES
activerecord (~> 5.1, >= 5.1.4)
mysql2 (~> 0.4.9)
activerecord (~> 5.2, >= 5.2.0)
mysql2 (~> 0.5.1)
net-http-digest_auth (~> 1.4, >= 1.4.1)
pry
rake (= 12.1.0)
sinatra (~> 2.0.0)
sinatra-contrib (~> 2.0.0)
sinatra (~> 2.0.1)
sinatra-contrib (~> 2.0.1)
thin (~> 1.7, >= 1.7.2)
BUNDLED WITH
......
......@@ -2,6 +2,7 @@
require 'date'
require 'net/http'
require 'net/http/digest_auth'
require 'uri'
require 'json'
require 'csv'
......@@ -68,16 +69,25 @@ class DataCollector
end
CSV.parse(response.body, headers: true, header_converters: :symbol).each do |row|
row_date = Time.parse(row[:interval_stop]).strftime("%Y-%m-%d")
time = Time.parse(row[:interval_stop]).strftime("%H:%M:%S")
timestamp = Time.parse(row[:interval_start]) + 15.minutes
row_date = timestamp.strftime("%Y-%m-%d")
row_time = timestamp.strftime("%H:%M:%S")
code = has_oh ? branch.get_oh_code(date.cwday, time) : nil
code = has_oh ? branch.get_oh_code(date.cwday, row_time) : nil
begin
# the first generation People Counter cameras are prone to spitting out seemingly
# random numbers at seemingly random times. To counter this, we enforce that
# only timestamps conforming to the valid slots will be submitted to the database.
valid_slots = [0, 15, 30, 45]
if Time.parse(time).sec == 0 && valid_slots.include?(Time.parse(time).min)
record = Count.where(counter_id: counter.id, date: row_date, time: time).first_or_create
record.attributes = {visitors_in: row[:pedestrians_coming_in], visitors_out: row[:pedestrians_going_out], oh_code: code}
if timestamp.sec == 0 && valid_slots.include?(timestamp.min)
# TODO interrim fix for new camera having different csv headers
visitors_in = row[:pedestrians_coming_in] || row[:in]
visitors_out = row[:pedestrians_going_out] || row[:out]
record = Count.where(counter_id: counter.id, date: row_date, time: row_time).first_or_create
record.attributes = {visitors_in: visitors_in, visitors_out: visitors_out, oh_code: code}
record.save! if record.changed?
end
rescue => e
......
......@@ -418,21 +418,37 @@ end
class Camera < ActiveRecord::Base
has_one :counter, :as => :source
has_one :camera_interface
belongs_to :camera_interface
def http_get_data(date)
# TODO: this is just a quick-fix, elegantize code
use_digest = camera_interface.name == 'stereo'
if camera_interface.name == 'local'
query = "/local/people-counter/.api?export-csv&date=#{date.strftime('%Y%m%d')}&res=15m"
else
query = "/stereo/people-counter/export.json?resolution=15minute&date=#{date.strftime('%Y%m%d')}&method=download"
query = "stereo/people-counter/export.csv?resolution=900&date=#{date.strftime('%Y%m%d')}&method=open"
end
url = URI.parse(address + query)
url.user = self.user
url.password = self.pw
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url.request_uri)
# request.basic_auth(user, pw)
# newer cameras use digest for authentication, which requires an initial request
# to the server to get the auth headers
if use_digest
digest_auth = Net::HTTP::DigestAuth.new
digest = http.request(request)
auth = digest_auth.auth_header(url, digest['www-authenticate'], 'GET')
request = Net::HTTP::Get.new(url.request_uri)
request.add_field('Authorization', auth)
end
http.request(request)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment