Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor dailies and energy prices #85

Draft
wants to merge 1 commit into
base: development
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading