-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathree.rb
72 lines (68 loc) · 1.86 KB
/
ree.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require 'httparty'
class Ree
class Generation
include SemanticLogger::Loggable
include Out::Generation
TZ = TZInfo::Timezone.get('Atlantic/Canary')
def self.source_id
"ree"
end
def initialize(date)
@from = date - 6.hours
@to = date + 1.day
@options = {}
@options[:curva] = "LZ_FV5M"
@options[:fecha] = date.strftime('%Y-%m-%d')
@system = "Canarias"
url = "https://demanda.ree.es/WSvisionaMoviles#{@system}Rest/resources/demandaGeneracion#{@system}"
@res = logger.benchmark_info(url) do
HTTParty.get(
url,
query: @options,
#debug_output: $stdout
)
end
#require 'pry' ; binding.pry
end
PRODUCTION_TYPES = {
"die" => "fossil_oil",
"gas" => "fossil_gas",
"eol" => "wind_onshore",
"cc" => "fossil_gas",
"vap" => "fossil_oil",
"fot" => "solar",
"hid" => "hydro_pumped_storage"
}
def points_generation
r = []
json = JSON.parse(@res.body.gsub(/^\w+\(|[^}]+$/,'\1'))
raise @res.body unless json["valoresHorariosGeneracion"]
json["valoresHorariosGeneracion"].each do |row|
leap = 0
time = row.delete("ts")
if time.include?('1A')
leap = 0
time.gsub!(/1A/,'01')
elsif time.include?('1B')
leap = 1
time.gsub!(/1B/,'01')
end
time = Time.strptime(time, '%Y-%m-%d %H:%M')
time = TZ.local_to_utc(time) { |periods| periods[leap] }
row.delete "dem" #FIXME demand
row.delete "vap"
row.delete "cc"
row.each do |k,value|
r << {
time: time,
country: 'ES-CN-FVLZ',
production_type: PRODUCTION_TYPES[k],
value: (value*1000).to_i
}
end
end
#require 'pry' ; binding.pry
r
end
end
end