From 921b9e7a140e3774cec04418b3bd6123e67eeb05 Mon Sep 17 00:00:00 2001 From: Javier Aranda Date: Sun, 7 Jan 2024 23:50:14 +0100 Subject: [PATCH] [skip ci] WIP --- Gemfile | 1 + Gemfile.lock | 3 + app/aggregations/application_aggregation.rb | 28 +++ .../daily_grid_energy_export_aggregation.rb | 31 ++++ .../grid_energy_import.rb | 0 .../grid_power_export.rb | 0 .../grid_power_import.rb | 0 .../solar_energy.rb | 0 .../solar_power.rb | 0 app/lib/solaris/daily_archives/base.rb | 34 ---- .../daily_archives/energy_price_export.rb | 25 --- .../daily_archives/grid_energy_export.rb | 35 ---- app/lib/solaris/pvpcs/daily/export_price.rb | 27 +++ .../daily/import_price.rb} | 0 .../archive_daily_energy_price_export.rb | 3 - .../archive_daily_energy_price_import.rb | 3 - app/models/cost.rb | 18 ++ app/models/daily_energy_export_price.rb | 2 + app/models/daily_energy_import_price.rb | 2 + app/models/energy_period.rb | 14 ++ app/models/energy_price.rb | 15 ++ app/models/energy_prices/pvpc.rb | 11 ++ app/models/rate.rb | 5 + app/models/rates/by_period.rb | 4 + app/models/rates/fixed.rb | 4 + app/models/rates/pvpc.rb | 4 + app/models/tax.rb | 15 ++ app/services/esios/indicator.rb | 2 +- config/initializers/core_extensions.rb | 2 + db/migrate/20230805174919_create_archive.rb | 10 +- ...183244_create_archive_daily_solar_power.rb | 2 +- ...72241_create_archive_daily_solar_energy.rb | 4 +- ..._create_archive_daily_grid_power_export.rb | 4 +- ..._create_archive_daily_grid_power_import.rb | 4 +- ...create_archive_daily_grid_energy_import.rb | 4 +- ...create_archive_daily_grid_energy_export.rb | 4 +- ...reate_archive_daily_energy_price_import.rb | 11 -- ...reate_archive_daily_energy_price_export.rb | 11 -- .../20231224203015_create_energy_prices.rb | 12 ++ ...03523_create_daily_energy_import_prices.rb | 15 ++ ...03754_create_daily_energy_export_prices.rb | 15 ++ .../20231226105540_create_energy_periods.rb | 18 ++ db/migrate/20231229001020_create_costs.rb | 18 ++ db/migrate/20231229003253_create_taxes.rb | 13 ++ db/migrate/20231229145024_create_rates.rb | 14 ++ ...31229200236_create_zones_energy_periods.rb | 9 + db/schema.rb | 158 +++++++++++++---- lib/core_extensions/time.rb | 11 ++ test/fixtures/costs.yml | 25 +++ test/fixtures/energy_periods.yml | 114 ++++++++++++ test/fixtures/energy_prices.yml | 167 ++++++++++++++++++ test/fixtures/rates.yml | 49 +++++ test/fixtures/taxes.yml | 17 ++ test/fixtures/zones_energy_periods.yml | 15 ++ test/models/cost_test.rb | 7 + test/models/energy_period_test.rb | 7 + test/models/rate_test.rb | 7 + test/models/tax_test.rb | 7 + test/test_helper.rb | 2 - 59 files changed, 869 insertions(+), 173 deletions(-) create mode 100644 app/aggregations/application_aggregation.rb create mode 100644 app/aggregations/daily_grid_energy_export_aggregation.rb rename app/lib/solaris/{daily_archives => archives}/grid_energy_import.rb (100%) rename app/lib/solaris/{daily_archives => archives}/grid_power_export.rb (100%) rename app/lib/solaris/{daily_archives => archives}/grid_power_import.rb (100%) rename app/lib/solaris/{daily_archives => archives}/solar_energy.rb (100%) rename app/lib/solaris/{daily_archives => archives}/solar_power.rb (100%) delete mode 100644 app/lib/solaris/daily_archives/base.rb delete mode 100644 app/lib/solaris/daily_archives/energy_price_export.rb delete mode 100644 app/lib/solaris/daily_archives/grid_energy_export.rb create mode 100644 app/lib/solaris/pvpcs/daily/export_price.rb rename app/lib/solaris/{daily_archives/energy_price_import.rb => pvpcs/daily/import_price.rb} (100%) delete mode 100644 app/models/archive_daily_energy_price_export.rb delete mode 100644 app/models/archive_daily_energy_price_import.rb create mode 100644 app/models/cost.rb create mode 100644 app/models/daily_energy_export_price.rb create mode 100644 app/models/daily_energy_import_price.rb create mode 100644 app/models/energy_period.rb create mode 100644 app/models/energy_price.rb create mode 100644 app/models/energy_prices/pvpc.rb create mode 100644 app/models/rate.rb create mode 100644 app/models/rates/by_period.rb create mode 100644 app/models/rates/fixed.rb create mode 100644 app/models/rates/pvpc.rb create mode 100644 app/models/tax.rb delete mode 100644 db/migrate/20230808184043_create_archive_daily_energy_price_import.rb delete mode 100644 db/migrate/20230808185034_create_archive_daily_energy_price_export.rb create mode 100644 db/migrate/20231224203015_create_energy_prices.rb create mode 100644 db/migrate/20231224203523_create_daily_energy_import_prices.rb create mode 100644 db/migrate/20231224203754_create_daily_energy_export_prices.rb create mode 100644 db/migrate/20231226105540_create_energy_periods.rb create mode 100644 db/migrate/20231229001020_create_costs.rb create mode 100644 db/migrate/20231229003253_create_taxes.rb create mode 100644 db/migrate/20231229145024_create_rates.rb create mode 100644 db/migrate/20231229200236_create_zones_energy_periods.rb create mode 100644 lib/core_extensions/time.rb create mode 100644 test/fixtures/costs.yml create mode 100644 test/fixtures/energy_periods.yml create mode 100644 test/fixtures/energy_prices.yml create mode 100644 test/fixtures/rates.yml create mode 100644 test/fixtures/taxes.yml create mode 100644 test/fixtures/zones_energy_periods.yml create mode 100644 test/models/cost_test.rb create mode 100644 test/models/energy_period_test.rb create mode 100644 test/models/rate_test.rb create mode 100644 test/models/tax_test.rb diff --git a/Gemfile b/Gemfile index fd04203..3cb0267 100644 --- a/Gemfile +++ b/Gemfile @@ -24,6 +24,7 @@ gem "bindata" gem "bootsnap", require: false gem "concurrent-ruby" gem "foreman" +gem "groupdate" gem "http" gem "mqtt" gem "rails-settings-cached" diff --git a/Gemfile.lock b/Gemfile.lock index 0c365c5..8fe4ae6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -126,6 +126,8 @@ GEM raabro (~> 1.4) globalid (1.2.1) activesupport (>= 6.1) + groupdate (6.4.0) + activesupport (>= 6.1) http (5.1.1) addressable (~> 2.8) http-cookie (~> 1.0) @@ -336,6 +338,7 @@ DEPENDENCIES debug dotenv-rails foreman + groupdate http importmap-rails mqtt diff --git a/app/aggregations/application_aggregation.rb b/app/aggregations/application_aggregation.rb new file mode 100644 index 0000000..d74f19d --- /dev/null +++ b/app/aggregations/application_aggregation.rb @@ -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 diff --git a/app/aggregations/daily_grid_energy_export_aggregation.rb b/app/aggregations/daily_grid_energy_export_aggregation.rb new file mode 100644 index 0000000..eaaed11 --- /dev/null +++ b/app/aggregations/daily_grid_energy_export_aggregation.rb @@ -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 diff --git a/app/lib/solaris/daily_archives/grid_energy_import.rb b/app/lib/solaris/archives/grid_energy_import.rb similarity index 100% rename from app/lib/solaris/daily_archives/grid_energy_import.rb rename to app/lib/solaris/archives/grid_energy_import.rb diff --git a/app/lib/solaris/daily_archives/grid_power_export.rb b/app/lib/solaris/archives/grid_power_export.rb similarity index 100% rename from app/lib/solaris/daily_archives/grid_power_export.rb rename to app/lib/solaris/archives/grid_power_export.rb diff --git a/app/lib/solaris/daily_archives/grid_power_import.rb b/app/lib/solaris/archives/grid_power_import.rb similarity index 100% rename from app/lib/solaris/daily_archives/grid_power_import.rb rename to app/lib/solaris/archives/grid_power_import.rb diff --git a/app/lib/solaris/daily_archives/solar_energy.rb b/app/lib/solaris/archives/solar_energy.rb similarity index 100% rename from app/lib/solaris/daily_archives/solar_energy.rb rename to app/lib/solaris/archives/solar_energy.rb diff --git a/app/lib/solaris/daily_archives/solar_power.rb b/app/lib/solaris/archives/solar_power.rb similarity index 100% rename from app/lib/solaris/daily_archives/solar_power.rb rename to app/lib/solaris/archives/solar_power.rb diff --git a/app/lib/solaris/daily_archives/base.rb b/app/lib/solaris/daily_archives/base.rb deleted file mode 100644 index 59356f2..0000000 --- a/app/lib/solaris/daily_archives/base.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Solaris - module DailyArchives - class Base - attr_reader :date, :archives - - 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 - end -end diff --git a/app/lib/solaris/daily_archives/energy_price_export.rb b/app/lib/solaris/daily_archives/energy_price_export.rb deleted file mode 100644 index 1aab39e..0000000 --- a/app/lib/solaris/daily_archives/energy_price_export.rb +++ /dev/null @@ -1,25 +0,0 @@ -module Solaris - module DailyArchives - class EnergyPriceExport < 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 diff --git a/app/lib/solaris/daily_archives/grid_energy_export.rb b/app/lib/solaris/daily_archives/grid_energy_export.rb deleted file mode 100644 index 345fca2..0000000 --- a/app/lib/solaris/daily_archives/grid_energy_export.rb +++ /dev/null @@ -1,35 +0,0 @@ -module Solaris - module DailyArchives - class GridEnergyExport < 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 - end -end diff --git a/app/lib/solaris/pvpcs/daily/export_price.rb b/app/lib/solaris/pvpcs/daily/export_price.rb new file mode 100644 index 0000000..45a6104 --- /dev/null +++ b/app/lib/solaris/pvpcs/daily/export_price.rb @@ -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 diff --git a/app/lib/solaris/daily_archives/energy_price_import.rb b/app/lib/solaris/pvpcs/daily/import_price.rb similarity index 100% rename from app/lib/solaris/daily_archives/energy_price_import.rb rename to app/lib/solaris/pvpcs/daily/import_price.rb diff --git a/app/models/archive_daily_energy_price_export.rb b/app/models/archive_daily_energy_price_export.rb deleted file mode 100644 index 448acfd..0000000 --- a/app/models/archive_daily_energy_price_export.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ArchiveDailyEnergyPriceExport < ApplicationRecord - self.table_name = "archive_daily_energy_price_export" -end diff --git a/app/models/archive_daily_energy_price_import.rb b/app/models/archive_daily_energy_price_import.rb deleted file mode 100644 index 8cd4b82..0000000 --- a/app/models/archive_daily_energy_price_import.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ArchiveDailyEnergyPriceImport < ApplicationRecord - self.table_name = "archive_daily_energy_price_import" -end diff --git a/app/models/cost.rb b/app/models/cost.rb new file mode 100644 index 0000000..a60396d --- /dev/null +++ b/app/models/cost.rb @@ -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 diff --git a/app/models/daily_energy_export_price.rb b/app/models/daily_energy_export_price.rb new file mode 100644 index 0000000..18cf601 --- /dev/null +++ b/app/models/daily_energy_export_price.rb @@ -0,0 +1,2 @@ +class DailyEnergyExportPrice < ApplicationRecord +end diff --git a/app/models/daily_energy_import_price.rb b/app/models/daily_energy_import_price.rb new file mode 100644 index 0000000..3c84da0 --- /dev/null +++ b/app/models/daily_energy_import_price.rb @@ -0,0 +1,2 @@ +class DailyEnergyImportPrice < ApplicationRecord +end diff --git a/app/models/energy_period.rb b/app/models/energy_period.rb new file mode 100644 index 0000000..30263e5 --- /dev/null +++ b/app/models/energy_period.rb @@ -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 diff --git a/app/models/energy_price.rb b/app/models/energy_price.rb new file mode 100644 index 0000000..67ff977 --- /dev/null +++ b/app/models/energy_price.rb @@ -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 diff --git a/app/models/energy_prices/pvpc.rb b/app/models/energy_prices/pvpc.rb new file mode 100644 index 0000000..7e30067 --- /dev/null +++ b/app/models/energy_prices/pvpc.rb @@ -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 diff --git a/app/models/rate.rb b/app/models/rate.rb new file mode 100644 index 0000000..e5d51c6 --- /dev/null +++ b/app/models/rate.rb @@ -0,0 +1,5 @@ +class Rate < ApplicationRecord + belongs_to :inverter + + validates :start_at, presence: true, uniqueness: { scope: :inverter_id } +end diff --git a/app/models/rates/by_period.rb b/app/models/rates/by_period.rb new file mode 100644 index 0000000..8de14ff --- /dev/null +++ b/app/models/rates/by_period.rb @@ -0,0 +1,4 @@ +module Rates + class ByPeriod < Rate + end +end diff --git a/app/models/rates/fixed.rb b/app/models/rates/fixed.rb new file mode 100644 index 0000000..9ce8ee2 --- /dev/null +++ b/app/models/rates/fixed.rb @@ -0,0 +1,4 @@ +module Rates + class Fixed < Rate + end +end diff --git a/app/models/rates/pvpc.rb b/app/models/rates/pvpc.rb new file mode 100644 index 0000000..1e08a3d --- /dev/null +++ b/app/models/rates/pvpc.rb @@ -0,0 +1,4 @@ +module Rates + class PVPC < Rate + end +end diff --git a/app/models/tax.rb b/app/models/tax.rb new file mode 100644 index 0000000..129336b --- /dev/null +++ b/app/models/tax.rb @@ -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 diff --git a/app/services/esios/indicator.rb b/app/services/esios/indicator.rb index 4441975..fd69272 100644 --- a/app/services/esios/indicator.rb +++ b/app/services/esios/indicator.rb @@ -35,7 +35,7 @@ def url end def perform_request(params = {}) - parse_response(base_request.get(url, params: base_params.merge(params))) + parse_response(base_request.get(url, params: params.compact)) end def parse_response(response) diff --git a/config/initializers/core_extensions.rb b/config/initializers/core_extensions.rb index a607933..ec6be0e 100644 --- a/config/initializers/core_extensions.rb +++ b/config/initializers/core_extensions.rb @@ -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 diff --git a/db/migrate/20230805174919_create_archive.rb b/db/migrate/20230805174919_create_archive.rb index 7cbde35..14e8ada 100644 --- a/db/migrate/20230805174919_create_archive.rb +++ b/db/migrate/20230805174919_create_archive.rb @@ -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 diff --git a/db/migrate/20230806183244_create_archive_daily_solar_power.rb b/db/migrate/20230806183244_create_archive_daily_solar_power.rb index 194ae3d..ba8e443 100644 --- a/db/migrate/20230806183244_create_archive_daily_solar_power.rb +++ b/db/migrate/20230806183244_create_archive_daily_solar_power.rb @@ -1,7 +1,7 @@ class CreateArchiveDailySolarPower < ActiveRecord::Migration[7.1] def change create_table :archive_daily_solar_power, id: :date, primary_key: :date do |t| - t.float :max, null: false + t.integer :max, null: false t.datetime :maxtime, null: false end end diff --git a/db/migrate/20230807072241_create_archive_daily_solar_energy.rb b/db/migrate/20230807072241_create_archive_daily_solar_energy.rb index 912c6bb..f171f43 100644 --- a/db/migrate/20230807072241_create_archive_daily_solar_energy.rb +++ b/db/migrate/20230807072241_create_archive_daily_solar_energy.rb @@ -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 diff --git a/db/migrate/20230807181438_create_archive_daily_grid_power_export.rb b/db/migrate/20230807181438_create_archive_daily_grid_power_export.rb index cc9cfe5..c852741 100644 --- a/db/migrate/20230807181438_create_archive_daily_grid_power_export.rb +++ b/db/migrate/20230807181438_create_archive_daily_grid_power_export.rb @@ -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 diff --git a/db/migrate/20230807181440_create_archive_daily_grid_power_import.rb b/db/migrate/20230807181440_create_archive_daily_grid_power_import.rb index 98fa1b4..b85907f 100644 --- a/db/migrate/20230807181440_create_archive_daily_grid_power_import.rb +++ b/db/migrate/20230807181440_create_archive_daily_grid_power_import.rb @@ -1,8 +1,8 @@ class CreateArchiveDailyGridPowerImport < ActiveRecord::Migration[7.1] def change create_table :archive_daily_grid_power_import, 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 diff --git a/db/migrate/20230807181444_create_archive_daily_grid_energy_import.rb b/db/migrate/20230807181444_create_archive_daily_grid_energy_import.rb index ab4be47..14b2b47 100644 --- a/db/migrate/20230807181444_create_archive_daily_grid_energy_import.rb +++ b/db/migrate/20230807181444_create_archive_daily_grid_energy_import.rb @@ -1,9 +1,9 @@ class CreateArchiveDailyGridEnergyImport < ActiveRecord::Migration[7.1] def change create_table :archive_daily_grid_energy_import, id: :date, primary_key: :date do |t| - t.float :max, null: false + t.decimal :max, precision: 8, 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 diff --git a/db/migrate/20230807182537_create_archive_daily_grid_energy_export.rb b/db/migrate/20230807182537_create_archive_daily_grid_energy_export.rb index dbb0222..b98d771 100644 --- a/db/migrate/20230807182537_create_archive_daily_grid_energy_export.rb +++ b/db/migrate/20230807182537_create_archive_daily_grid_energy_export.rb @@ -1,9 +1,9 @@ class CreateArchiveDailyGridEnergyExport < ActiveRecord::Migration[7.1] def change create_table :archive_daily_grid_energy_export, id: :date, primary_key: :date do |t| - t.float :max, null: false + t.decimal :max, precision: 8, 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 diff --git a/db/migrate/20230808184043_create_archive_daily_energy_price_import.rb b/db/migrate/20230808184043_create_archive_daily_energy_price_import.rb deleted file mode 100644 index 22b77b4..0000000 --- a/db/migrate/20230808184043_create_archive_daily_energy_price_import.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateArchiveDailyEnergyPriceImport < ActiveRecord::Migration[7.1] - def change - create_table :archive_daily_energy_price_import, id: :date, primary_key: :date do |t| - t.float :max, null: false - t.datetime :maxtime, null: false - t.float :min, null: false - t.datetime :mintime, null: false - t.float :avg, null: false - end - end -end diff --git a/db/migrate/20230808185034_create_archive_daily_energy_price_export.rb b/db/migrate/20230808185034_create_archive_daily_energy_price_export.rb deleted file mode 100644 index 5768c72..0000000 --- a/db/migrate/20230808185034_create_archive_daily_energy_price_export.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateArchiveDailyEnergyPriceExport < ActiveRecord::Migration[7.1] - def change - create_table :archive_daily_energy_price_export, id: :date, primary_key: :date do |t| - t.float :max, null: false - t.datetime :maxtime, null: false - t.float :min, null: false - t.datetime :mintime, null: false - t.float :avg, null: false - end - end -end diff --git a/db/migrate/20231224203015_create_energy_prices.rb b/db/migrate/20231224203015_create_energy_prices.rb new file mode 100644 index 0000000..9895214 --- /dev/null +++ b/db/migrate/20231224203015_create_energy_prices.rb @@ -0,0 +1,12 @@ +class CreateEnergyPrices < ActiveRecord::Migration[7.1] + def change + create_table :energy_prices, id: false do |t| + t.string :type, null: false + t.references :zone, null: false, foreign_key: true + t.datetime :datetime, null: false + t.decimal :import, precision: 8, scale: 6, null: false + t.decimal :export, precision: 8, scale: 6, null: false + t.index %i[type zone_id datetime], unique: true + end + end +end diff --git a/db/migrate/20231224203523_create_daily_energy_import_prices.rb b/db/migrate/20231224203523_create_daily_energy_import_prices.rb new file mode 100644 index 0000000..b85a85d --- /dev/null +++ b/db/migrate/20231224203523_create_daily_energy_import_prices.rb @@ -0,0 +1,15 @@ +class CreateDailyEnergyImportPrices < ActiveRecord::Migration[7.1] + def change + create_table :daily_energy_import_prices, id: false do |t| + t.string :type, null: false + t.references :zone, null: false, foreign_key: true + t.date :date, null: false + t.decimal :max, precision: 8, scale: 6, null: false + t.datetime :maxtime, null: false + t.decimal :min, precision: 8, scale: 6, null: false + t.datetime :mintime, null: false + t.decimal :avg, precision: 8, scale: 6, null: false + t.index %i[type zone_id date], unique: true + end + end +end diff --git a/db/migrate/20231224203754_create_daily_energy_export_prices.rb b/db/migrate/20231224203754_create_daily_energy_export_prices.rb new file mode 100644 index 0000000..78627f6 --- /dev/null +++ b/db/migrate/20231224203754_create_daily_energy_export_prices.rb @@ -0,0 +1,15 @@ +class CreateDailyEnergyExportPrices < ActiveRecord::Migration[7.1] + def change + create_table :daily_energy_export_prices, id: false do |t| + t.string :type, null: false + t.references :zone, null: false, foreign_key: true + t.date :date, null: false + t.decimal :max, precision: 8, scale: 6, null: false + t.datetime :maxtime, null: false + t.decimal :min, precision: 8, scale: 6, null: false + t.datetime :mintime, null: false + t.decimal :avg, precision: 8, scale: 6, null: false + t.index %i[type zone_id date], unique: true + end + end +end diff --git a/db/migrate/20231226105540_create_energy_periods.rb b/db/migrate/20231226105540_create_energy_periods.rb new file mode 100644 index 0000000..efe9fb2 --- /dev/null +++ b/db/migrate/20231226105540_create_energy_periods.rb @@ -0,0 +1,18 @@ +class CreateEnergyPeriods < ActiveRecord::Migration[7.1] + def change + create_table :energy_periods do |t| + t.timestamps null: false + t.boolean :monday, null: false, default: false + t.boolean :tuesday, null: false, default: false + t.boolean :wednesday, null: false, default: false + t.boolean :thursday, null: false, default: false + t.boolean :friday, null: false, default: false + t.boolean :saturday, null: false, default: false + t.boolean :sunday, null: false, default: false + t.boolean :holiday, null: false, default: false + t.integer :start_hour, null: false + t.integer :end_hour, null: false + t.string :name, null: false + end + end +end diff --git a/db/migrate/20231229001020_create_costs.rb b/db/migrate/20231229001020_create_costs.rb new file mode 100644 index 0000000..587adad --- /dev/null +++ b/db/migrate/20231229001020_create_costs.rb @@ -0,0 +1,18 @@ +class CreateCosts < ActiveRecord::Migration[7.1] + def change + create_table :costs do |t| + t.timestamps null: false + t.references :country, null: false, foreign_key: true + t.datetime :start_at, null: false + t.decimal :transport_toll_p1, precision: 8, scale: 6, null: false + t.decimal :distribution_toll_p1, precision: 8, scale: 6, null: false + t.decimal :charges_p1, precision: 8, scale: 6, null: false + t.decimal :transport_toll_p2, precision: 8, scale: 6, null: false + t.decimal :distribution_toll_p2, precision: 8, scale: 6, null: false + t.decimal :charges_p2, precision: 8, scale: 6, null: false + t.decimal :transport_toll_p3, precision: 8, scale: 6, null: false + t.decimal :distribution_toll_p3, precision: 8, scale: 6, null: false + t.decimal :charges_p3, precision: 8, scale: 6, null: false + end + end +end diff --git a/db/migrate/20231229003253_create_taxes.rb b/db/migrate/20231229003253_create_taxes.rb new file mode 100644 index 0000000..1174336 --- /dev/null +++ b/db/migrate/20231229003253_create_taxes.rb @@ -0,0 +1,13 @@ +class CreateTaxes < ActiveRecord::Migration[7.1] + def change + create_table :taxes do |t| + t.timestamps null: false + t.references :zone, null: false, foreign_key: true + t.string :kind, null: false + t.string :installation_type, null: false + t.datetime :start_at, null: false + t.string :name, null: false + t.decimal :percentage, precision: 12, scale: 10, null: false + end + end +end diff --git a/db/migrate/20231229145024_create_rates.rb b/db/migrate/20231229145024_create_rates.rb new file mode 100644 index 0000000..9316f0e --- /dev/null +++ b/db/migrate/20231229145024_create_rates.rb @@ -0,0 +1,14 @@ +class CreateRates < ActiveRecord::Migration[7.1] + def change + create_table :rates do |t| + t.timestamps null: false + t.references :inverter, null: false, foreign_key: true + t.string :type, null: false + t.datetime :start_at, null: false + t.decimal :p1, precision: 8, scale: 6 + t.decimal :p2, precision: 8, scale: 6 + t.decimal :p3, precision: 8, scale: 6 + t.index %i[inverter_id start_at], unique: true + end + end +end diff --git a/db/migrate/20231229200236_create_zones_energy_periods.rb b/db/migrate/20231229200236_create_zones_energy_periods.rb new file mode 100644 index 0000000..591031b --- /dev/null +++ b/db/migrate/20231229200236_create_zones_energy_periods.rb @@ -0,0 +1,9 @@ +class CreateZonesEnergyPeriods < ActiveRecord::Migration[7.1] + def change + create_table :zones_energy_periods, id: false do |t| + t.references :zone, null: false, foreign_key: true + t.references :energy_period, null: false, foreign_key: true + t.index %i[energy_period_id zone_id], unique: true + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 0f6d56f..d58e55e 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -12,62 +12,115 @@ ActiveRecord::Schema[7.1].define(version: 2024_01_09_182558) do create_table "archive", primary_key: "datetime", id: { type: :datetime, precision: 0 }, force: :cascade 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 - end - - create_table "archive_daily_energy_price_export", primary_key: "date", id: :date, force: :cascade do |t| - t.float "max", null: false - t.datetime "maxtime", null: false - t.float "min", null: false - t.datetime "mintime", null: false - t.float "avg", null: false - end - - create_table "archive_daily_energy_price_import", primary_key: "date", id: :date, force: :cascade do |t| - t.float "max", null: false - t.datetime "maxtime", null: false - t.float "min", null: false - t.datetime "mintime", null: false - t.float "avg", 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 create_table "archive_daily_grid_energy_export", primary_key: "date", id: :date, force: :cascade do |t| - t.float "max", null: false + t.decimal "max", precision: 8, scale: 2, null: false t.datetime "maxtime", null: false - t.float "sum", null: false + t.decimal "sum", precision: 8, scale: 2, null: false end create_table "archive_daily_grid_energy_import", primary_key: "date", id: :date, force: :cascade do |t| - t.float "max", null: false + t.decimal "max", precision: 8, scale: 2, null: false t.datetime "maxtime", null: false - t.float "sum", null: false + t.decimal "sum", precision: 8, scale: 2, null: false end create_table "archive_daily_grid_power_export", primary_key: "date", id: :date, force: :cascade do |t| - t.float "max", null: false - t.datetime "maxtime" + t.integer "max", null: false + t.datetime "maxtime", null: false end create_table "archive_daily_grid_power_import", primary_key: "date", id: :date, force: :cascade do |t| - t.float "max", null: false - t.datetime "maxtime" + t.integer "max", null: false + t.datetime "maxtime", null: false end create_table "archive_daily_solar_energy", primary_key: "date", id: :date, force: :cascade 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 create_table "archive_daily_solar_power", primary_key: "date", id: :date, force: :cascade do |t| - t.float "max", null: false + t.integer "max", null: false t.datetime "maxtime", null: false end + create_table "costs", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "country_id", null: false + t.datetime "start_at", null: false + t.decimal "transport_toll_p1", precision: 8, scale: 6, null: false + t.decimal "distribution_toll_p1", precision: 8, scale: 6, null: false + t.decimal "charges_p1", precision: 8, scale: 6, null: false + t.decimal "transport_toll_p2", precision: 8, scale: 6, null: false + t.decimal "distribution_toll_p2", precision: 8, scale: 6, null: false + t.decimal "charges_p2", precision: 8, scale: 6, null: false + t.decimal "transport_toll_p3", precision: 8, scale: 6, null: false + t.decimal "distribution_toll_p3", precision: 8, scale: 6, null: false + t.decimal "charges_p3", precision: 8, scale: 6, null: false + t.index ["country_id"], name: "index_costs_on_country_id" + end + + create_table "daily_energy_export_prices", id: false, force: :cascade do |t| + t.string "type", null: false + t.integer "zone_id", null: false + t.date "date", null: false + t.decimal "max", precision: 8, scale: 6, null: false + t.datetime "maxtime", null: false + t.decimal "min", precision: 8, scale: 6, null: false + t.datetime "mintime", null: false + t.decimal "avg", precision: 8, scale: 6, null: false + t.index ["type", "zone_id", "date"], name: "index_daily_energy_export_prices_on_type_and_zone_id_and_date", unique: true + t.index ["zone_id"], name: "index_daily_energy_export_prices_on_zone_id" + end + + create_table "daily_energy_import_prices", id: false, force: :cascade do |t| + t.string "type", null: false + t.integer "zone_id", null: false + t.date "date", null: false + t.decimal "max", precision: 8, scale: 6, null: false + t.datetime "maxtime", null: false + t.decimal "min", precision: 8, scale: 6, null: false + t.datetime "mintime", null: false + t.decimal "avg", precision: 8, scale: 6, null: false + t.index ["type", "zone_id", "date"], name: "index_daily_energy_import_prices_on_type_and_zone_id_and_date", unique: true + t.index ["zone_id"], name: "index_daily_energy_import_prices_on_zone_id" + end + + create_table "energy_periods", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.boolean "monday", default: false, null: false + t.boolean "tuesday", default: false, null: false + t.boolean "wednesday", default: false, null: false + t.boolean "thursday", default: false, null: false + t.boolean "friday", default: false, null: false + t.boolean "saturday", default: false, null: false + t.boolean "sunday", default: false, null: false + t.boolean "holiday", default: false, null: false + t.integer "start_hour", null: false + t.integer "end_hour", null: false + t.string "name", null: false + end + + create_table "energy_prices", id: false, force: :cascade do |t| + t.string "type", null: false + t.integer "zone_id", null: false + t.datetime "datetime", null: false + t.decimal "import", precision: 8, scale: 6, null: false + t.decimal "export", precision: 8, scale: 6, null: false + t.index ["type", "zone_id", "datetime"], name: "index_energy_prices_on_type_and_zone_id_and_datetime", unique: true + t.index ["zone_id"], name: "index_energy_prices_on_zone_id" + end + create_table "holidays", id: false, force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -82,6 +135,19 @@ t.decimal "factor", precision: 4, scale: 2, null: false end + create_table "rates", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "inverter_id", null: false + t.string "type", null: false + t.datetime "start_at", null: false + t.decimal "p1", precision: 8, scale: 6 + t.decimal "p2", precision: 8, scale: 6 + t.decimal "p3", precision: 8, scale: 6 + t.index ["inverter_id", "start_at"], name: "index_rates_on_inverter_id_and_start_at", unique: true + t.index ["inverter_id"], name: "index_rates_on_inverter_id" + end + create_table "settings", force: :cascade do |t| t.datetime "created_at", null: false t.datetime "updated_at", null: false @@ -183,9 +249,37 @@ t.index ["key"], name: "index_solid_queue_semaphores_on_key", unique: true end + create_table "taxes", force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "zone_id", null: false + t.string "kind", null: false + t.string "installation_type", null: false + t.datetime "start_at", null: false + t.string "name", null: false + t.decimal "percentage", precision: 12, scale: 10, null: false + t.index ["zone_id"], name: "index_taxes_on_zone_id" + end + + create_table "zones_energy_periods", id: false, force: :cascade do |t| + t.integer "zone_id", null: false + t.integer "energy_period_id", null: false + t.index ["energy_period_id", "zone_id"], name: "index_zones_energy_periods_on_energy_period_id_and_zone_id", unique: true + t.index ["energy_period_id"], name: "index_zones_energy_periods_on_energy_period_id" + t.index ["zone_id"], name: "index_zones_energy_periods_on_zone_id" + end + + add_foreign_key "costs", "countries" + add_foreign_key "daily_energy_export_prices", "zones" + add_foreign_key "daily_energy_import_prices", "zones" + add_foreign_key "energy_prices", "zones" + add_foreign_key "rates", "inverters" add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade add_foreign_key "solid_queue_scheduled_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade + add_foreign_key "taxes", "zones" + add_foreign_key "zones_energy_periods", "energy_periods" + add_foreign_key "zones_energy_periods", "zones" end diff --git a/lib/core_extensions/time.rb b/lib/core_extensions/time.rb new file mode 100644 index 0000000..68518ed --- /dev/null +++ b/lib/core_extensions/time.rb @@ -0,0 +1,11 @@ +module CoreExtensions + module Time + def holiday? + Holiday.where(date: self.to_date).any? + end + + def day_type + saturday? || sunday? || holiday? ? :weekend_holiday : :working_day + end + end +end diff --git a/test/fixtures/costs.yml b/test/fixtures/costs.yml new file mode 100644 index 0000000..3788ded --- /dev/null +++ b/test/fixtures/costs.yml @@ -0,0 +1,25 @@ +cost_1: + country_id: 1 + start_at: <%= Time.zone.parse("2023-01-01 00:00:00") %> + transport_toll_p1: 0.004506 + distribution_toll_p1: 0.024592 + charges_p1: 0.043893 + transport_toll_p2: 0.00305 + distribution_toll_p2: 0.016744 + charges_p2: 0.008779 + transport_toll_p3: 0.000128 + distribution_toll_p3: 0.000852 + charges_p3: 0.002195 + +cost_2: + country_id: 1 + start_at: <%= Time.zone.parse("2024-01-01 00:00:00") %> + transport_toll_p1: 0.004528 + distribution_toll_p1: 0.028553 + charges_p1: 0.0 + transport_toll_p2: 0.002589 + distribution_toll_p2: 0.016595 + charges_p2: 0.0 + transport_toll_p3: 0.000075 + distribution_toll_p3: 0.000482 + charges_p3: 0.0 diff --git a/test/fixtures/energy_periods.yml b/test/fixtures/energy_periods.yml new file mode 100644 index 0000000..ed6f9c1 --- /dev/null +++ b/test/fixtures/energy_periods.yml @@ -0,0 +1,114 @@ +_fixture: + ignore: + - working_day + - weekend_holiday + +working_day: &working_day + monday: true + tuesday: true + wednesday: true + thursday: true + friday: true + +weekend_holiday: &weekend_holiday + saturday: true + sunday: true + holiday: true + +energy_period_pcb_1: + <<: *working_day + id: 1 + start_hour: 0 + end_hour: 7 + name: "p3" + +energy_period_pcb_2: + <<: *working_day + id: 2 + start_hour: 8 + end_hour: 9 + name: "p2" + +energy_period_pcb_3: + <<: *working_day + id: 3 + start_hour: 10 + end_hour: 13 + name: "p1" + +energy_period_pcb_4: + <<: *working_day + id: 4 + start_hour: 14 + end_hour: 17 + name: "p2" + +energy_period_pcb_5: + <<: *working_day + id: 5 + start_hour: 18 + end_hour: 21 + name: "p1" + +energy_period_pcb_6: + <<: *working_day + id: 6 + start_hour: 22 + end_hour: 23 + name: "p2" + +energy_period_pcb_7: + <<: *weekend_holiday + id: 7 + start_hour: 0 + end_hour: 23 + name: "p3" + +energy_period_cm_1: + <<: *working_day + id: 8 + start_hour: 0 + end_hour: 7 + name: "p3" + +energy_period_cm_2: + <<: *working_day + id: 9 + start_hour: 8 + end_hour: 10 + name: "p2" + +energy_period_cm_3: + <<: *working_day + id: 10 + start_hour: 11 + end_hour: 14 + name: "p1" + +energy_period_cm_4: + <<: *working_day + id: 11 + start_hour: 15 + end_hour: 18 + name: "p2" + +energy_period_cm_5: + <<: *working_day + id: 12 + start_hour: 19 + end_hour: 22 + name: "p1" + +energy_period_cm_6: + <<: *working_day + id: 13 + start_hour: 23 + end_hour: 23 + name: "p2" + +energy_period_cm_7: + <<: *weekend_holiday + id: 14 + start_hour: 0 + end_hour: 23 + name: "p3" diff --git a/test/fixtures/energy_prices.yml b/test/fixtures/energy_prices.yml new file mode 100644 index 0000000..57e3f98 --- /dev/null +++ b/test/fixtures/energy_prices.yml @@ -0,0 +1,167 @@ +energy_price0: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T00:00:00+01:00") %> + import: 0.1563 + export: 0.1087 + +energy_price1: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T01:00:00+01:00") %> + import: 0.1542 + export: 0.1047 + +energy_price2: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T02:00:00+01:00") %> + import: 0.1498 + export: 0.0984 + +energy_price3: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T03:00:00+01:00") %> + import: 0.1513 + export: 0.0981 + +energy_price4: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T04:00:00+01:00") %> + import: 0.1507 + export: 0.0975 + +energy_price5: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T05:00:00+01:00") %> + import: 0.1554 + export: 0.1021 + +energy_price6: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T06:00:00+01:00") %> + import: 0.1503 + export: 0.0988 + +energy_price7: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T07:00:00+01:00") %> + import: 0.1508 + export: 0.1012 + +energy_price8: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T08:00:00+01:00") %> + import: 0.1464 + export: 0.0982 + +energy_price9: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T09:00:00+01:00") %> + import: 0.1136 + export: 0.0689 + +energy_price10: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T10:00:00+01:00") %> + import: 0.104 + export: 0.064 + +energy_price11: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T11:00:00+01:00") %> + import: 0.1022 + export: 0.064 + +energy_price12: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T12:00:00+01:00") %> + import: 0.1042 + export: 0.0652 + +energy_price13: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T13:00:00+01:00") %> + import: 0.1076 + export: 0.0686 + +energy_price14: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T14:00:00+01:00") %> + import: 0.1082 + export: 0.0686 + +energy_price15: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T15:00:00+01:00") %> + import: 0.0864 + export: 0.049 + +energy_price16: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T16:00:00+01:00") %> + import: 0.0988 + export: 0.057 + +energy_price17: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T17:00:00+01:00") %> + import: 0.1117 + export: 0.0681 + +energy_price18: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T18:00:00+01:00") %> + import: 0.1491 + export: 0.1028 + +energy_price19: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T19:00:00+01:00") %> + import: 0.2012 + export: 0.1517 + +energy_price20: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T20:00:00+01:00") %> + import: 0.1912 + export: 0.1437 + +energy_price21: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T21:00:00+01:00") %> + import: 0.181 + export: 0.1343 + +energy_price22: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T22:00:00+01:00") %> + import: 0.1792 + export: 0.1319 + +energy_price23: + type: "PVPC" + zone_id: 1 + datetime: <%= Time.zone.parse("2023-03-19T23:00:00+01:00") %> + import: 0.1775 + export: 0.129 diff --git a/test/fixtures/rates.yml b/test/fixtures/rates.yml new file mode 100644 index 0000000..8e2e249 --- /dev/null +++ b/test/fixtures/rates.yml @@ -0,0 +1,49 @@ +house_1: + inverter: house_1 + type: "Rates::Fixed" + start_at: <%= Time.zone.parse("2023-01-01 00:00:00") %> + p1: 0.122400 + p2: 0.122400 + p3: 0.122400 + +house_2_1: + inverter: house_2 + type: "Rates::ByPeriod" + start_at: <%= Time.zone.parse("2023-01-01 00:00:00") %> + p1: 0.342000 + p2: 0.281000 + p3: 0.234000 +house_2_2: + inverter: house_2 + type: "Rates::ByPeriod" + start_at: <%= Time.zone.parse("2023-05-01 00:00:00") %> + p1: 0.295000 + p2: 0.237000 + p3: 0.199000 +house_2_3: + inverter: house_2 + type: "Rates::ByPeriod" + start_at: <%= Time.zone.parse("2024-01-01 00:00:00") %> + p1: 0.247000 + p2: 0.189000 + p3: 0.154000 + +house_3: + inverter: house_3 + type: "Rates::PVPC" + start_at: <%= Time.zone.parse("2023-01-01 00:00:00") %> + +house_4_1: + inverter: house_4 + type: "Rates::Fixed" + start_at: <%= Time.zone.parse("2023-01-01 00:00:00") %> + p1: 0.122400 + p2: 0.122400 + p3: 0.122400 +house_4_2: + inverter: house_4 + type: "Rates::ByPeriod" + start_at: <%= Time.zone.parse("2023-06-01 00:00:00") %> + p1: 0.295000 + p2: 0.237000 + p3: 0.199000 diff --git a/test/fixtures/taxes.yml b/test/fixtures/taxes.yml new file mode 100644 index 0000000..0318a05 --- /dev/null +++ b/test/fixtures/taxes.yml @@ -0,0 +1,17 @@ +ie_peninsula: + id: 1 + zone_id: 1 + kind: "other" + installation_type: "domestic" + start_at: <%= Time.new(2023, 1, 1) %> + name: "Impuesto Electricidad" + percentage: 0.005 + +iva_peninsula: + id: 2 + zone_id: 1 + kind: "value_add" + installation_type: "domestic" + start_at: <%= Time.new(2023, 1, 1) %> + name: "IVA" + percentage: 0.05 diff --git a/test/fixtures/zones_energy_periods.yml b/test/fixtures/zones_energy_periods.yml new file mode 100644 index 0000000..2b56335 --- /dev/null +++ b/test/fixtures/zones_energy_periods.yml @@ -0,0 +1,15 @@ +<% (1..3).each do |zone_id| %> + <% (1..7).each do |energy_period| %> +zone_<%= zone_id %>_ep_<%= energy_period %>: + zone_id: <%= zone_id %> + energy_period_id: <%= energy_period %> + <% end %> +<% end %> + +<% (4..5).each do |zone_id| %> + <% (8..14).each do |energy_period| %> +zone_<%= zone_id %>_ep_<%= energy_period %>: + zone_id: <%= zone_id %> + energy_period_id: <%= energy_period %> + <% end %> +<% end %> diff --git a/test/models/cost_test.rb b/test/models/cost_test.rb new file mode 100644 index 0000000..88f0533 --- /dev/null +++ b/test/models/cost_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/energy_period_test.rb b/test/models/energy_period_test.rb new file mode 100644 index 0000000..6a145c0 --- /dev/null +++ b/test/models/energy_period_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class EnergyPeriodTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/rate_test.rb b/test/models/rate_test.rb new file mode 100644 index 0000000..0e99eb8 --- /dev/null +++ b/test/models/rate_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RateTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/tax_test.rb b/test/models/tax_test.rb new file mode 100644 index 0000000..54b7a23 --- /dev/null +++ b/test/models/tax_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class TaxTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index 332896f..c309a45 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -10,7 +10,5 @@ class TestCase # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. fixtures :all - - # Add more helper methods to be used by all tests here... end end