Skip to content

Commit

Permalink
Merge branch 'master' of github.com:maketronica/hivemom.rb
Browse files Browse the repository at this point in the history
s necessary,
  • Loading branch information
jsgarvin committed Jun 11, 2016
2 parents bafb3f3 + 34ed2fd commit eec0865
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 59 deletions.
2 changes: 1 addition & 1 deletion lib/hive_mom/reading_compositor/composition_set.rb
Expand Up @@ -18,8 +18,8 @@ def initialize(name,

def update
return if name.to_sym == :instant
reading_constructor.pluck(:hive_id).uniq.each do |hive_id|
begin
reading_constructor.pluck(:hive_id).uniq.each do |hive_id|
composition_constructor.new(hive_id, self).update
reset_previous_attempt_count
rescue ActiveRecord::StatementInvalid => e
Expand Down
Expand Up @@ -12,7 +12,7 @@ def initialize(hive_id, set)

def update
return unless first_reading
HiveMom.logger.info(self.class) do
HiveMom.logger.info(self.class) do
"Updating composition #{set.name} for hive #{hive_id}"
end
current_composite.update!(composite_params_for_update)
Expand Down
9 changes: 6 additions & 3 deletions lib/hive_mom/reading_compositor/csv_compilation.rb
Expand Up @@ -13,9 +13,7 @@ def initialize(composite_name)

def content
@content ||= CSV.generate do |csv|
csv << %w(probeid timestamp bot_uptime bot_temp bot_humidity
brood_temp brood_humidity ambient_temp ambient_humidity
hive_lbs)
csv << csv_header
readings.each do |r|
csv << data_row(r)
end
Expand All @@ -27,6 +25,11 @@ def content

private

def csv_header
%w(probeid timestamp bot_uptime bot_temp bot_humidity brood_temp
brood_humidity ambient_temp ambient_humidity hive_lbs)
end

def readings
@readings ||=
Reading.composite(composite_name)
Expand Down
52 changes: 0 additions & 52 deletions scripts/log_loader.rb

This file was deleted.

30 changes: 30 additions & 0 deletions spec/fixtures/readings.yml
Expand Up @@ -3,6 +3,7 @@ recent_<%= i %>:
created_at: <%= i.minutes.ago - 1.day %>
sampled_at: <%= i.minutes.ago - 1.day %>
updated_at: <%= i.minutes.ago - 1.day %>
bot_uptime: 1
bot_id: 1
hive_id: 2
bot_temp: 20
Expand All @@ -17,6 +18,7 @@ yesterday_<%= i %>:
created_at: <%= i.minutes.ago - 2.days %>
sampled_at: <%= i.minutes.ago - 2.days %>
updated_at: <%= i.minutes.ago - 2.days %>
bot_uptime: 1
bot_id: 1
hive_id: 2
bot_temp: 20
Expand All @@ -30,6 +32,7 @@ yesterday_composite:
created_at: <%= 1.day.ago %>
sampled_at: <%= 1.day.ago.beginning_of_day %>
updated_at: <%= 1.day.ago %>
bot_uptime: 1
bot_id: 1
hive_id: 2
bot_temp: 2
Expand All @@ -42,10 +45,37 @@ two_days_ago_composite:
created_at: <%= 2.days.ago %>
sampled_at: <%= 2.days.ago.beginning_of_day %>
updated_at: <%= 2.days.ago %>
bot_uptime: 1
bot_id: 1
hive_id: 2
bot_temp: 2
brood_temp: 2
bot_humidity: 5
brood_humidity: 5
composite: '1_day'

fifteen_minute_instant_source:
created_at: <%= 2.hours.ago %>
sampled_at: <%= 2.hours.ago.beginning_of_hour %>
updated_at: <%= 2.hours.ago %>
bot_uptime: 1
bot_id: 1
hive_id: 2
bot_temp: 20
brood_temp: 2
bot_humidity: 5
brood_humidity: 5
composite: 'instant'

fifteen_minute_composite:
created_at: <%= 2.hours.ago %>
sampled_at: <%= 2.hours.ago.beginning_of_hour %>
updated_at: <%= 2.hours.ago %>
bot_uptime: 1
bot_id: 1
hive_id: 2
bot_temp: 2
brood_temp: 2
bot_humidity: 5
brood_humidity: 5
composite: '15_minutes'
1 change: 1 addition & 0 deletions spec/integration/reading_compositor_spec.rb
Expand Up @@ -38,6 +38,7 @@ module HiveMom
end
Reading.instant.for_hive(hive_id).create(
sampled_at: Time.now,
bot_uptime: 1,
bot_temp: 42,
brood_temp: 42,
bot_humidity: 42,
Expand Down
Expand Up @@ -3,7 +3,7 @@ class ReadingCompositor
class CompositionSet
describe Composition do
let(:hive_id) { 2 }
let(:name) { '1_day' }
let(:name) { '15_minutes' }
let(:composition_set) { double('composition_set', name: name) }
let(:composition) { Composition.new(hive_id, composition_set) }

Expand Down Expand Up @@ -39,7 +39,9 @@ class CompositionSet
context 'when there is a current composite' do
it 'updates the current composite' do
expect { composition.update }
.to change { readings(:yesterday_composite).reload.bot_temp }
.to change {
readings(:fifteen_minute_composite).reload.bot_temp
}
.from(2).to(20)
end
end
Expand Down

0 comments on commit eec0865

Please sign in to comment.