-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
553 additions
and
420 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Dailies | ||
class GridEnergyExport < Daily | ||
self.table_name = "daily_grid_energy_export" | ||
|
||
validates :max, presence: true, numericality: { greater_than_or_equal_to: 0 } | ||
validates :maxhour, presence: true, numericality: { | ||
only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 23 | ||
} | ||
validates :sum, presence: true, numericality: { greater_than_or_equal_to: 0 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Dailies | ||
class GridEnergyImport < Daily | ||
self.table_name = "daily_grid_energy_import" | ||
|
||
validates :max, presence: true, numericality: { greater_than_or_equal_to: 0 } | ||
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: { greater_than_or_equal_to: 0 } | ||
validates :minhour, presence: true, numericality: { | ||
only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 23 | ||
} | ||
validates :sum, presence: true, numericality: { greater_than_or_equal_to: 0 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Dailies | ||
class GridPowerExport < Daily | ||
self.table_name = "daily_grid_power_export" | ||
|
||
validates :max, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } | ||
validates :maxtime, presence: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Dailies | ||
class GridPowerImport < Daily | ||
self.table_name = "daily_grid_power_import" | ||
|
||
validates :max, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } | ||
validates :maxtime, presence: true | ||
validates :min, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } | ||
validates :mintime, presence: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Dailies | ||
class SolarEnergy < Daily | ||
self.table_name = "daily_solar_energy" | ||
|
||
validates :max, presence: true, numericality: { greater_than_or_equal_to: 0 } | ||
validates :maxhour, presence: true, numericality: { | ||
only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 23 | ||
} | ||
validates :sum, presence: true, numericality: { greater_than_or_equal_to: 0 } | ||
|
||
def compute_max | ||
sum_by_hour.values.max.round(2) | ||
end | ||
|
||
def compute_maxhour | ||
sum_by_hour.max_by(&:last).first | ||
end | ||
|
||
def compute_sum | ||
Archive.by_date(date).maximum(:solar_energy) | ||
end | ||
|
||
private | ||
|
||
def group_by_hour | ||
@group_by_hour ||= Archive.by_date(date).group_by(&:hour) | ||
end | ||
|
||
def sum_by_hour | ||
@sum_by_hour ||= group_by_hour.transform_values do |archives| | ||
archives.last.solar_energy - archives.first.solar_energy | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Dailies | ||
class SolarPower < Daily | ||
self.table_name = "daily_solar_power" | ||
|
||
validates :max, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 } | ||
validates :maxtime, presence: true | ||
|
||
def compute_max | ||
Archive.by_date(date).maximum(:solar_power) | ||
end | ||
|
||
def compute_maxtime | ||
Archive.by_date(date).max_by(&:solar_power).try(:datetime) | ||
end | ||
end | ||
end |
Oops, something went wrong.