Skip to content

Commit

Permalink
Refactor dailies and energy prices
Browse files Browse the repository at this point in the history
  • Loading branch information
javierav committed Jan 21, 2024
1 parent 3417d5b commit 69dae92
Show file tree
Hide file tree
Showing 62 changed files with 870 additions and 530 deletions.
32 changes: 0 additions & 32 deletions app/lib/solaris/daily_archive.rb

This file was deleted.

34 changes: 0 additions & 34 deletions app/lib/solaris/daily_archives/base.rb

This file was deleted.

25 changes: 0 additions & 25 deletions app/lib/solaris/daily_archives/energy_price_export.rb

This file was deleted.

25 changes: 0 additions & 25 deletions app/lib/solaris/daily_archives/energy_price_import.rb

This file was deleted.

35 changes: 0 additions & 35 deletions app/lib/solaris/daily_archives/grid_energy_export.rb

This file was deleted.

35 changes: 0 additions & 35 deletions app/lib/solaris/daily_archives/grid_energy_import.rb

This file was deleted.

17 changes: 0 additions & 17 deletions app/lib/solaris/daily_archives/grid_power_export.rb

This file was deleted.

17 changes: 0 additions & 17 deletions app/lib/solaris/daily_archives/grid_power_import.rb

This file was deleted.

35 changes: 0 additions & 35 deletions app/lib/solaris/daily_archives/solar_energy.rb

This file was deleted.

17 changes: 0 additions & 17 deletions app/lib/solaris/daily_archives/solar_power.rb

This file was deleted.

4 changes: 3 additions & 1 deletion app/models/archive.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Archive < ApplicationRecord
self.table_name = "archive"

scope :by_date, ->(date) { where(created_at: date.all_day).order(created_at: :asc) }
delegate :hour, to: :datetime

scope :by_date, ->(date) { where(datetime: date.all_day).order(datetime: :asc) }
end
3 changes: 0 additions & 3 deletions app/models/archive_daily_energy_price_export.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/archive_daily_energy_price_import.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/archive_daily_grid_energy_export.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/archive_daily_grid_energy_import.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/archive_daily_grid_power_export.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/archive_daily_grid_power_import.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/archive_daily_solar_energy.rb

This file was deleted.

3 changes: 0 additions & 3 deletions app/models/archive_daily_solar_power.rb

This file was deleted.

35 changes: 35 additions & 0 deletions app/models/dailies/energy_price_export.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Dailies
class EnergyPriceExport < Daily
self.table_name = "daily_energy_price_export"

validates :max, presence: true, numericality: true
validates :maxhour, presence: true, numericality: {
only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 23
}
validates :min, presence: true, numericality: true
validates :minhour, presence: true, numericality: {
only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 23
}
validates :avg, presence: true, numericality: true

def compute_max
EnergyPrice.by_date(date).maximum(:export)
end

def compute_maxhour
EnergyPrice.by_date(date).max_by(&:export).try(:datetime).try(:hour)
end

def compute_min
EnergyPrice.by_date(date).minimum(:export)
end

def compute_minhour
EnergyPrice.by_date(date).min_by(&:export).try(:datetime).try(:hour)
end

def compute_avg
EnergyPrice.by_date(date).average(:export).try(:round, 4)
end
end
end
35 changes: 35 additions & 0 deletions app/models/dailies/energy_price_import.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Dailies
class EnergyPriceImport < Daily
self.table_name = "daily_energy_price_import"

validates :max, presence: true, numericality: true
validates :maxhour, presence: true, numericality: {
only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 23
}
validates :min, presence: true, numericality: true
validates :minhour, presence: true, numericality: {
only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 23
}
validates :avg, presence: true, numericality: true

def compute_max
EnergyPrice.by_date(date).maximum(:import)
end

def compute_maxhour
EnergyPrice.by_date(date).max_by(&:import).try(:datetime).try(:hour)
end

def compute_min
EnergyPrice.by_date(date).minimum(:import)
end

def compute_minhour
EnergyPrice.by_date(date).min_by(&:import).try(:datetime).try(:hour)
end

def compute_avg
EnergyPrice.by_date(date).average(:import).try(:round, 4)
end
end
end
Loading

0 comments on commit 69dae92

Please sign in to comment.