-
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
49 changed files
with
557 additions
and
377 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
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,3 +1,3 @@ | ||
web: bin/puma -C config/puma.rb | ||
job: bin/rails solid_queue:start | ||
clock: bin/clockwork config/clockwork.rb | ||
scheduler: ruby config/scheduler.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
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,16 @@ | ||
class Cost < ApplicationRecord | ||
validates :start_at, presence: true | ||
validates :transport_toll_p1, presence: true | ||
validates :transport_toll_p2, presence: true | ||
validates :transport_toll_p3, presence: true | ||
validates :distribution_toll_p1, presence: true | ||
validates :distribution_toll_p2, presence: true | ||
validates :distribution_toll_p3, presence: true | ||
validates :charge_p1, presence: true | ||
validates :charge_p2, presence: true | ||
validates :charge_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,13 @@ | ||
class EnergyPeriod < ApplicationRecord | ||
belongs_to :zone | ||
|
||
enum :day_type, %i[working_day weekend_holiday].to_enum_hash | ||
enum :kind, %i[p1 p2 p3].to_enum_hash # P1 (Punta), P2 (Llano), P3 (Valle) | ||
|
||
validates :start_hour, presence: true | ||
validates :end_hour, presence: true | ||
|
||
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.kind | ||
end | ||
end |
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,4 @@ | ||
class Holiday < ApplicationRecord | ||
validates :name, presence: true | ||
validates :date, presence: true, uniqueness: true | ||
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
class Inverter < ApplicationRecord | ||
include Sqideable | ||
|
||
enum :installation_type, %i[domestic other].to_enum_hash | ||
|
||
belongs_to :protocol | ||
belongs_to :zone | ||
|
||
validates :name, presence: true | ||
validates :timezone, presence: true | ||
validates :installation_type, presence: true | ||
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,19 @@ | ||
class PVPC < ApplicationRecord | ||
self.table_name = "pvpc" | ||
|
||
belongs_to :zone | ||
|
||
scope :by_date, ->(date) { where(time: date.all_day).order(time: :asc) } | ||
|
||
def self.read(date, zone) | ||
create!({ import: import(date, zone) || [], export: export(date, zone) || [] }) | ||
end | ||
|
||
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 |
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,15 @@ | ||
class Tax < ApplicationRecord | ||
enum :kind, %i[value_add other].to_enum_hash | ||
enum :installation_type, %i[domestic other].to_enum_hash | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Zone < ApplicationRecord | ||
has_many :energy_periods, dependent: :destroy | ||
has_many :pvpc, dependent: :destroy | ||
|
||
validates :name, presence: true, uniqueness: true | ||
validates :timezone, presence: true | ||
validates :esios_import_geo_id, presence: true | ||
validates :esios_export_geo_id, presence: true | ||
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 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 +1,2 @@ | ||
require "core_extensions/array" | ||
require "core_extensions/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 |
---|---|---|
|
@@ -12,4 +12,5 @@ | |
|
||
ActiveSupport::Inflector.inflections(:en) do |inflect| | ||
inflect.acronym "ESIOS" | ||
inflect.acronym "PVPC" | ||
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,18 @@ | ||
require_relative "environment" | ||
|
||
scheduler = Rufus::Scheduler.new | ||
loop_interval = ENV.fetch("SOLARIS_LOOP_INTERVAL", 30).to_i | ||
|
||
scheduler.every loop_interval, name: "solaris.loop", first_at: Time.current.beginning_of_minute + 1.minute do | ||
Solaris::Loop.run | ||
end | ||
|
||
scheduler.cron "0 21 * * * Europe/Madrid", name: "solaris.energy_prices.esios_pvpc" do | ||
Solaris::EnergyPrice.store(Date.tomorrow) | ||
end | ||
|
||
scheduler.cron "1 0 * * * #{tz}", name: "solaris.archive.daily" do | ||
Solaris::DailyArchive.run | ||
end | ||
|
||
scheduler.join |
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,12 @@ | ||
class CreateZones < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :zones do |t| | ||
t.timestamps null: false | ||
t.string :name, null: false | ||
t.string :timezone, null: false | ||
t.integer :esios_import_geo_id, null: false | ||
t.integer :esios_export_geo_id, null: false | ||
t.index :name, unique: true | ||
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,9 @@ | ||
class CreatePVPC < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :pvpc, id: :time, primary_key: :time do |t| | ||
t.references :zone, null: false, foreign_key: true | ||
t.decimal :import, precision: 8, scale: 6, null: false | ||
t.decimal :export, precision: 8, scale: 6, null: false | ||
end | ||
end | ||
end |
Oops, something went wrong.