eba 1.3.3 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eba/bcb.rb +59 -33
- data/lib/eba/version.rb +5 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12867683eab5685d635272ce08a2857c4714adc6
|
4
|
+
data.tar.gz: '009c7d7fe4cb54f729406f61cf0351e8cc2d5660'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52e3078553a8edfa92b3de8b953fee15715aa2e489a1c9ea7f76e11b64cf5f4f8c7fe6fc34fc7ff969f246a394901163a392ea93629bbd12a80088dd6fcad71d
|
7
|
+
data.tar.gz: fe4844fd3f732e39d8f77eb416bf99bfca6e3f1480d17933d3267d15bb99ae44864bc36b99165facd62038b6ba1be7bd59743a0ef4c0a0951c2a8cadb19bcaec
|
data/lib/eba/bcb.rb
CHANGED
@@ -59,6 +59,23 @@ class BCB < Encoder
|
|
59
59
|
return result
|
60
60
|
end
|
61
61
|
|
62
|
+
def hash_by_periodicity(array_of_codes)
|
63
|
+
purged_array_of_codes = purge_invalid_series(array_of_codes)
|
64
|
+
result = {}
|
65
|
+
|
66
|
+
purged_array_of_codes.each do |code|
|
67
|
+
dado = get_last_value(code)
|
68
|
+
|
69
|
+
if not result.key? dado.periodicity then
|
70
|
+
result[dado.periodicity] = []
|
71
|
+
end
|
72
|
+
|
73
|
+
result[dado.periodicity] << dado
|
74
|
+
end
|
75
|
+
|
76
|
+
return result
|
77
|
+
end
|
78
|
+
|
62
79
|
def get_last_value(series_code)
|
63
80
|
begin
|
64
81
|
response = @service.call(:get_ultimo_valor_xml, message: {in0: "#{series_code}"})
|
@@ -89,7 +106,6 @@ class BCB < Encoder
|
|
89
106
|
# Ensure that date is in the format dd/MM/YYY
|
90
107
|
def get_all_data_for_array(array_of_codes, date)
|
91
108
|
result = nil
|
92
|
-
codes = Array.new()
|
93
109
|
data_collection = Array.new()
|
94
110
|
|
95
111
|
# This request has a limit of series he can get at a time, thus
|
@@ -98,46 +114,56 @@ class BCB < Encoder
|
|
98
114
|
# and allow the developer to easily identify which series each data
|
99
115
|
# object pertains.
|
100
116
|
array_of_codes.each_slice(50).to_a.each do |array|
|
101
|
-
|
117
|
+
hash = hash_by_periodicity(array)
|
102
118
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
in2: Time.now.strftime('%d/%m/%Y').to_s}
|
119
|
+
hash.each do |periodicity, array|
|
120
|
+
codes = []
|
121
|
+
data_array = []
|
107
122
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
[:get_valores_series_xml_return])
|
123
|
+
array.each do |data|
|
124
|
+
data_array << data
|
125
|
+
codes << data.pk
|
126
|
+
end
|
113
127
|
|
114
|
-
|
115
|
-
|
116
|
-
|
128
|
+
# Build the message from the start of the historical series
|
129
|
+
message = { in0: {long: codes},
|
130
|
+
in1: date,
|
131
|
+
in2: Time.now.strftime('%d/%m/%Y').to_s}
|
132
|
+
|
133
|
+
# try and catch, as some series can be discontinued or a code may be broken
|
134
|
+
begin
|
135
|
+
response = @service.call(:get_valores_series_xml, message: message)
|
136
|
+
result = Nokogiri::XML(response.to_hash[:get_valores_series_xml_response] \
|
137
|
+
[:get_valores_series_xml_return])
|
138
|
+
|
139
|
+
rescue Exception => erro
|
140
|
+
puts "Error requesting! #{erro}"
|
141
|
+
end
|
117
142
|
|
118
|
-
|
143
|
+
i = 0
|
119
144
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
145
|
+
result.css("SERIE").each do |serie|
|
146
|
+
# recover identifying data from the getLastValue method,
|
147
|
+
# as the get_valores_series_xml desn't have identifying data
|
148
|
+
# as series name, periodicity, etc.
|
149
|
+
base_data = data_array[i]
|
150
|
+
comp = 'name="ID" value="' + codes[i].to_s + '"'
|
126
151
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
152
|
+
if serie.inspect.include? comp
|
153
|
+
serie.css("ITEM").each do |item|
|
154
|
+
data_collection << Data_bcb.new(encode(base_data.name),
|
155
|
+
array[i],
|
156
|
+
base_data.periodicity,
|
157
|
+
encode(base_data.unit),
|
158
|
+
"1",
|
159
|
+
item.css("DATA").text.split("/")[0],
|
160
|
+
item.css("DATA").text.split("/")[1],
|
161
|
+
item.css("VALOR").text)
|
162
|
+
end
|
137
163
|
end
|
138
|
-
end
|
139
164
|
|
140
|
-
|
165
|
+
i = i + 1
|
166
|
+
end
|
141
167
|
end
|
142
168
|
end
|
143
169
|
|
data/lib/eba/version.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Eba
|
2
2
|
# For documentation purposes:
|
3
3
|
# VERSION = mm.dd.ff.hh
|
4
|
-
# mm -
|
4
|
+
# mm - major change
|
5
5
|
# ff - commits on feature
|
6
6
|
# hh - commits on hotfix
|
7
7
|
|
8
|
-
VERSION = "1.
|
8
|
+
VERSION = "1.4.3"
|
9
9
|
|
10
10
|
#Version 1.0.1
|
11
11
|
#
|
@@ -33,4 +33,7 @@ module Eba
|
|
33
33
|
|
34
34
|
#Version 1.3.3
|
35
35
|
# get_all_data_for_array extracts data now as bulk, in order to make better use of the compression.
|
36
|
+
|
37
|
+
#Version 1.4.3
|
38
|
+
# get_all_data_for_array now handles different periodicities for any ammount of codes.
|
36
39
|
end
|