aeeg_time 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/aeeg_time.rb +26 -0
- data/lib/aeeg_time/core_ext/date.rb +9 -0
- data/lib/aeeg_time/core_ext/time.rb +16 -0
- data/lib/aeeg_time/easter_dates.rb +24 -0
- data/lib/aeeg_time/energy_time.rb +28 -0
- data/lib/aeeg_time/italian_holidays.rb +21 -0
- metadata +53 -0
data/lib/aeeg_time.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'aeeg_time/energy_time'
|
2
|
+
require_relative 'aeeg_time/italian_holidays'
|
3
|
+
|
4
|
+
# reminder: irb -Ilib -raeeg_time
|
5
|
+
|
6
|
+
|
7
|
+
class AeegTime < EnergyTime
|
8
|
+
include ItalianHolidays
|
9
|
+
|
10
|
+
# Fascie orarie definite nell'Allegato A, tabella 6, deliberazione 301/12
|
11
|
+
def aeeg_band(return_a_number=false)
|
12
|
+
n = case
|
13
|
+
when holiday?
|
14
|
+
3
|
15
|
+
when !saturday? && hour_in?(8...19)
|
16
|
+
1
|
17
|
+
when saturday? && hour_in?(7...23)
|
18
|
+
2
|
19
|
+
when !saturday? && hour_in?(7...23)
|
20
|
+
2
|
21
|
+
else
|
22
|
+
3
|
23
|
+
end
|
24
|
+
return_a_number ? n : "F#{n}"
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
Time.class_eval do
|
4
|
+
def to_date
|
5
|
+
::Date.new(year, month, day)
|
6
|
+
end
|
7
|
+
|
8
|
+
def monthday
|
9
|
+
strftime("%m%d")
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(sym, *args, &block)
|
13
|
+
return self.to_date.send(sym, *args, &block) if self.to_date.respond_to?(sym)
|
14
|
+
super(sym, *args, &block)
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module EasterDates
|
2
|
+
|
3
|
+
# year => "mmdd" hash of easters
|
4
|
+
EASTERS = {2009 => "0412", 2010 => "0404", 2011 => "0424", 2012 => "0408", 2013 => "0331", 2014 => "0420", 2015 => "0405", 2016 => "0327", 2017 => "0416", 2018 => "0401", 2019 => "0421", 2020 => "0412"}
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
def easter_mm_dd(year)
|
8
|
+
raise "No easter date for year=#{year}" if !EASTERS.has_key? year
|
9
|
+
EASTERS[year]
|
10
|
+
end
|
11
|
+
|
12
|
+
def easter?
|
13
|
+
easter_mm_dd(year)==monthday
|
14
|
+
end
|
15
|
+
|
16
|
+
def easter_monday?
|
17
|
+
easter_mm_dd(year)==(self-(24*60*60)).monthday
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.included(receiver)
|
22
|
+
receiver.send :include, InstanceMethods
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'core_ext/time'
|
2
|
+
require_relative 'core_ext/date'
|
3
|
+
|
4
|
+
class EnergyTime < Time
|
5
|
+
|
6
|
+
def holiday?
|
7
|
+
sunday? || national_holiday?
|
8
|
+
end
|
9
|
+
|
10
|
+
def +(seconds)
|
11
|
+
self.class.at(super(seconds))
|
12
|
+
end
|
13
|
+
|
14
|
+
# collection must be a Range or an Array
|
15
|
+
def hour_in?(collection)
|
16
|
+
collection.include?(self.hour)
|
17
|
+
end
|
18
|
+
|
19
|
+
def interval
|
20
|
+
"#{strftime('%H:00')} -> #{(self+3600).strftime('%H:00')}"
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
def hour_count
|
25
|
+
hour+1
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'easter_dates'
|
2
|
+
|
3
|
+
module ItalianHolidays
|
4
|
+
include EasterDates
|
5
|
+
|
6
|
+
module InstanceMethods
|
7
|
+
|
8
|
+
def national_holiday?
|
9
|
+
national_holidays = %w(0101 0106 0425 0501 0602 0815 1101 1208 1225 1226) # for italy
|
10
|
+
return true if national_holidays.include? monthday
|
11
|
+
|
12
|
+
easters = {2009 => "0412", 2010 => "0404", 2011 => "0424", 2012 => "0408", 2013 => "0331", 2014 => "0420", 2015 => "0405", 2016 => "0327", 2017 => "0416", 2018 => "0401", 2019 => "0421", 2020 => "0412"}
|
13
|
+
return true if easter_monday?
|
14
|
+
false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(receiver)
|
19
|
+
receiver.send :include, InstanceMethods
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aeeg_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Iwan Buetti
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-05 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: This is a small gem that extend the Time class to introduce a method
|
15
|
+
to generate electricity market time slot used by The Italian Regulatory Authority
|
16
|
+
for Electricity and Gas (AEEG) and other support methods.
|
17
|
+
email: iwan.buetti@gmail.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- lib/aeeg_time.rb
|
23
|
+
- lib/aeeg_time/core_ext/date.rb
|
24
|
+
- lib/aeeg_time/core_ext/time.rb
|
25
|
+
- lib/aeeg_time/easter_dates.rb
|
26
|
+
- lib/aeeg_time/energy_time.rb
|
27
|
+
- lib/aeeg_time/italian_holidays.rb
|
28
|
+
homepage: https://github.com/iwan/aeeg_time
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project:
|
48
|
+
rubygems_version: 1.8.24
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: A small gem used to generate AEEG Time Slot
|
52
|
+
test_files: []
|
53
|
+
has_rdoc:
|