-
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
65 changed files
with
902 additions
and
394 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,7 @@ | ||
class Country < ApplicationRecord | ||
has_many :zones, dependent: :destroy | ||
has_many :holidays, class_name: 'CountryHoliday', dependent: :destroy | ||
|
||
validates :code, presence: true, uniqueness: true | ||
validates :name, 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,6 @@ | ||
class CountryHoliday < ApplicationRecord | ||
belongs_to :country | ||
|
||
validates :name, presence: true | ||
validates :date, presence: true, uniqueness: { scope: :country_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,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 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,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 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,3 @@ | ||
class Rate < ApplicationRecord | ||
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 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, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class Zone < ApplicationRecord | ||
belongs_to :country | ||
|
||
has_many :energy_periods, dependent: :destroy | ||
has_many :pvpc, dependent: :destroy | ||
|
||
has_and_belongs_to_many :energy_periods, join_table: :zones_energy_periods | ||
|
||
validates :name, presence: true, uniqueness: true | ||
validates :timezone, presence: true | ||
validates :configuration, 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.
Oops, something went wrong.