-
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
59 changed files
with
869 additions
and
173 deletions.
There are no files selected for viewing
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
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
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,28 @@ | ||
class ApplicationAggregation | ||
def initialize(date, archives) | ||
@date = date | ||
@archives = archives | ||
end | ||
|
||
def run | ||
instance = model.find_or_initialize_by(date: @date) | ||
instance.assign_attributes(aggregations) | ||
instance.save! | ||
end | ||
|
||
private | ||
|
||
def aggregations_columns | ||
%i[max maxtime min mintime sum avg] | ||
end | ||
|
||
def aggregations | ||
aggregations_columns.each_with_object({}) do |column, hash| | ||
hash[column] = send(column) if respond_to?(column) | ||
end | ||
end | ||
|
||
def model | ||
"ArchiveDaily#{self.class.name.demodulize}".constantize | ||
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,31 @@ | ||
class DailyGridEnergyExportAggregation < Base | ||
def max | ||
sum_by_hour.values.max.round(2) | ||
end | ||
|
||
def maxtime | ||
date.to_time.change(hour: sum_by_hour.max_by { |a| a[1] }.first) | ||
end | ||
|
||
def sum | ||
(archives_array.last.grid_energy_export - archives_array.first.grid_energy_export).round(2) | ||
end | ||
|
||
private | ||
|
||
def archives_array | ||
@archives_array ||= archives.to_a | ||
end | ||
|
||
def group_by_hour | ||
@group_by_hour ||= archives_array.group_by do |archive| | ||
archive.created_at.hour | ||
end | ||
end | ||
|
||
def sum_by_hour | ||
@sum_by_hour ||= group_by_hour.transform_values do |archives| | ||
archives.last.grid_energy_export - archives.first.grid_energy_export | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,27 @@ | ||
module Solaris | ||
module PVPCs | ||
module Daily | ||
class ExportPrice < Base | ||
def max | ||
::EnergyPrice.by_date(date).maximum(:export) | ||
end | ||
|
||
def maxtime | ||
::EnergyPrice.by_date(date).where(export: max).first.datetime | ||
end | ||
|
||
def min | ||
::EnergyPrice.by_date(date).minimum(:export) | ||
end | ||
|
||
def mintime | ||
::EnergyPrice.by_date(date).where(export: min).first.datetime | ||
end | ||
|
||
def avg | ||
::EnergyPrice.by_date(date).average(:export).round(4) | ||
end | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
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,18 @@ | ||
class Cost < ApplicationRecord | ||
belongs_to :country | ||
|
||
validates :start_at, presence: true | ||
validates :transport_toll_p1, presence: true | ||
validates :distribution_toll_p1, presence: true | ||
validates :charges_p1, presence: true | ||
validates :transport_toll_p2, presence: true | ||
validates :distribution_toll_p2, presence: true | ||
validates :charges_p2, presence: true | ||
validates :transport_toll_p3, presence: true | ||
validates :distribution_toll_p3, presence: true | ||
validates :charges_p3, presence: true | ||
|
||
def self.for_time(time) | ||
where('start_at <= ?', time).order(start_at: :desc).first | ||
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,2 @@ | ||
class DailyEnergyExportPrice < ApplicationRecord | ||
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,2 @@ | ||
class DailyEnergyImportPrice < ApplicationRecord | ||
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,14 @@ | ||
class EnergyPeriod < ApplicationRecord | ||
has_and_belongs_to_many :zones, join_table: :zones_energy_periods | ||
|
||
enum :name, %i[p1 p2 p3].to_enum_hash | ||
|
||
validates :start_hour, presence: true | ||
validates :end_hour, presence: true | ||
validates :name, presence: true | ||
|
||
# TODO, this is not working with new format | ||
def self.kind_for(time, zone) | ||
where(zone: zone, day_type: time.day_type).where('start_hour <= ? AND end_hour >= ?', time.hour, time.hour).sole.name | ||
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 @@ | ||
class EnergyPrice < ApplicationRecord | ||
self.store_full_sti_class = false | ||
|
||
belongs_to :zone | ||
|
||
scope :by_date, ->(date) { where(time: date.all_day).order(time: :asc) } | ||
|
||
validates :datetime, uniqueness: { scope: %i[type zone_id] } | ||
validates :import, presence: true, numericality: true | ||
validates :export, presence: true, numericality: true | ||
|
||
def self.load(date, zone) | ||
create!({ import: import(date, zone) || [], export: export(date, zone) || [] }) | ||
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 EnergyPrices | ||
class PVPC < EnergyPrice | ||
def self.import(date, zone) | ||
::ESIOS::Import.for_date(date, zone) | ||
end | ||
|
||
def self.export(date, zone) | ||
::ESIOS::Export.for_date(date, zone) | ||
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,5 @@ | ||
class Rate < ApplicationRecord | ||
belongs_to :inverter | ||
|
||
validates :start_at, presence: true, uniqueness: { scope: :inverter_id } | ||
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,4 @@ | ||
module Rates | ||
class ByPeriod < Rate | ||
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,4 @@ | ||
module Rates | ||
class Fixed < Rate | ||
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,4 @@ | ||
module Rates | ||
class PVPC < Rate | ||
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 @@ | ||
class Tax < ApplicationRecord | ||
enum :kind, %i[value_add other].to_enum_hash, prefix: true | ||
enum :installation_type, %i[domestic other].to_enum_hash, prefix: true | ||
|
||
belongs_to :zone | ||
|
||
validates :installation_type, presence: true | ||
validates :start_at, presence: true | ||
validates :name, presence: true | ||
validates :percentage, presence: true, numericality: { greater_than_or_equal_to: 0, less_than_or_equal_to: 1 } | ||
|
||
def self.for_time_and_zone(time, zone) | ||
where(zone: zone).where('start_at <= ?', time).order(start_at: :desc).first # TODO, puede haber varios impuestos | ||
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
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 @@ | ||
require "core_extensions/array" | ||
require "core_extensions/string" | ||
require "core_extensions/time" | ||
|
||
Array.include CoreExtensions::Array | ||
String.include CoreExtensions::String | ||
Time.include CoreExtensions::Time |
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,11 +1,11 @@ | ||
class CreateArchive < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :archive, id: { type: :datetime, precision: 0 }, primary_key: :datetime do |t| | ||
t.float :solar_power, null: false | ||
t.float :solar_energy, null: false | ||
t.float :grid_power, null: false | ||
t.float :grid_energy_export, null: false | ||
t.float :grid_energy_import, null: false | ||
t.integer :solar_power, null: false | ||
t.decimal :solar_energy, precision: 4, scale: 2, null: false | ||
t.integer :grid_power, null: false | ||
t.decimal :grid_energy_export, precision: 8, scale: 2, null: false | ||
t.decimal :grid_energy_import, precision: 8, scale: 2, null: false | ||
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
4 changes: 2 additions & 2 deletions
4
db/migrate/20230807072241_create_archive_daily_solar_energy.rb
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,9 +1,9 @@ | ||
class CreateArchiveDailySolarEnergy < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :archive_daily_solar_energy, id: :date, primary_key: :date do |t| | ||
t.float :max, null: false | ||
t.decimal :max, precision: 4, scale: 2, null: false | ||
t.datetime :maxtime, null: false | ||
t.float :sum, null: false | ||
t.decimal :sum, precision: 8, scale: 2, null: false | ||
end | ||
end | ||
end |
4 changes: 2 additions & 2 deletions
4
db/migrate/20230807181438_create_archive_daily_grid_power_export.rb
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,8 +1,8 @@ | ||
class CreateArchiveDailyGridPowerExport < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :archive_daily_grid_power_export, id: :date, primary_key: :date do |t| | ||
t.float :max, null: false | ||
t.datetime :maxtime | ||
t.integer :max, null: false | ||
t.datetime :maxtime, null: false | ||
end | ||
end | ||
end |
Oops, something went wrong.