eba 2.0.2 → 2.1.0
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 +50 -31
- data/lib/eba/data.rb +33 -17
- data/lib/eba/helper.rb +18 -21
- data/lib/eba/version.rb +4 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f04a70c1137e9cac4b3d1d0ed11cc96a1b6b38b
|
4
|
+
data.tar.gz: f1a9fea0d47d4b88ed2052684b46f480f50b3a7a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94a9d22b5394f400e9279f670fa75e42abb52070465e92a48d788befc53bee0e95fa67b5c1547359448a26efc8c0dbece52584625b708b4cd679198afb38321f
|
7
|
+
data.tar.gz: f6468f3cd7cfd3d2a73a4e0bdae468465097d23cf5a93f6ef85bb4b15e8bf10d43110bc3b90cbf2c95de5d93066d99318661fc9e8991707231e76adb53417c38
|
data/lib/eba/bcb.rb
CHANGED
@@ -69,13 +69,25 @@ class BCB < Helper
|
|
69
69
|
def get_last_value(series_code)
|
70
70
|
begin
|
71
71
|
response = @service.call(:get_ultimo_valor_xml, message: {in0: "#{series_code}"})
|
72
|
+
rescue HTTP::ConnectionError => e
|
73
|
+
puts "BCB Warning: hangup from source trying to get last value. Waiting and trying again."
|
74
|
+
sleep(1)
|
75
|
+
|
76
|
+
return get_last_value(series_code)
|
77
|
+
|
78
|
+
rescue OpenSSL::SSL::SSLError => e
|
79
|
+
puts "BCB Warning: hangup from source trying to get last value. Waiting and trying again."
|
80
|
+
sleep(1)
|
81
|
+
|
82
|
+
return get_last_value(series_code)
|
83
|
+
|
72
84
|
rescue Exception => e
|
85
|
+
puts "BCB ERROR: #{e.message}\n#{e.backtrace}\n#{e.class}"
|
73
86
|
return Data_bcb.invalid_data()
|
74
87
|
end
|
75
88
|
|
76
89
|
response = response.to_hash[:get_ultimo_valor_xml_response][:get_ultimo_valor_xml_return].sub("&",
|
77
90
|
"-_1532_-")
|
78
|
-
|
79
91
|
xmlResult = Nokogiri::XML(response)
|
80
92
|
|
81
93
|
# As it's a brazillian database it's column identifications are in portuguese,
|
@@ -87,15 +99,7 @@ class BCB < Helper
|
|
87
99
|
# MES = MONTH
|
88
100
|
# ANO = YEAR
|
89
101
|
# VALOR = VALUe
|
90
|
-
|
91
|
-
return build_bcb_data(xmlResult.search("NOME").text.sub("-_1532_-", "&"),
|
92
|
-
series_code,
|
93
|
-
xmlResult.search("PERIODICIDADE").text,
|
94
|
-
xmlResult.search("UNIDADE").text.sub("-_1532_-", "&"),
|
95
|
-
xmlResult.search("DIA").text,
|
96
|
-
xmlResult.search("MES").text,
|
97
|
-
xmlResult.search("ANO").text,
|
98
|
-
xmlResult.search("VALOR").text, false)
|
102
|
+
build_bcb_data(xmlResult)
|
99
103
|
end
|
100
104
|
|
101
105
|
# Ensure that date is in the format dd/MM/YYY
|
@@ -123,35 +127,38 @@ class BCB < Helper
|
|
123
127
|
code_x_data[data.pk] = data
|
124
128
|
end
|
125
129
|
|
126
|
-
|
127
|
-
|
128
|
-
in1: min_date,
|
129
|
-
in2: max_date}
|
130
|
-
|
131
|
-
result = send_message(message)
|
132
|
-
|
133
|
-
if result != nil then
|
134
|
-
i = 0
|
135
|
-
|
136
|
-
result.css("SERIE").each do |serie|
|
137
|
-
extract_an_item(serie, code_x_data, data_collection)
|
138
|
-
i = i + 1
|
139
|
-
end
|
130
|
+
scry_for_interval(min_date, max_date, code_x_data).each do |data|
|
131
|
+
data_collection << data
|
140
132
|
end
|
141
133
|
end
|
142
134
|
end
|
143
135
|
|
144
|
-
|
145
|
-
|
136
|
+
data_collection
|
137
|
+
end
|
138
|
+
|
139
|
+
def scry_for_interval(min_date, max_date, code_x_data)
|
140
|
+
dc = []
|
141
|
+
|
142
|
+
# Build the message from the start of the historical series
|
143
|
+
message = {in0: {long: code_x_data.keys},
|
144
|
+
in1: min_date,
|
145
|
+
in2: max_date}
|
146
|
+
|
147
|
+
result = send_message(message)
|
146
148
|
|
147
|
-
|
148
|
-
|
149
|
+
if result != nil then
|
150
|
+
result.css("SERIE").each do |serie|
|
151
|
+
extract_an_item(serie, code_x_data, dc)
|
152
|
+
end
|
149
153
|
|
150
|
-
|
151
|
-
|
154
|
+
if dc.size == 0 && code_x_data.keys.size > 0 then
|
155
|
+
result.css("SERIE").each do |serie|
|
156
|
+
extract_an_item(serie, code_x_data, dc)
|
157
|
+
end
|
158
|
+
end
|
152
159
|
end
|
153
160
|
|
154
|
-
|
161
|
+
dc
|
155
162
|
end
|
156
163
|
|
157
164
|
def send_message(message)
|
@@ -161,6 +168,18 @@ class BCB < Helper
|
|
161
168
|
begin
|
162
169
|
response = @service.call(:get_valores_series_xml, message: message)
|
163
170
|
result = Nokogiri::XML(response.to_hash[:get_valores_series_xml_response][:get_valores_series_xml_return])
|
171
|
+
rescue HTTP::ConnectionError => e
|
172
|
+
puts "BCB Warning: hangup from source trying to get all data. Waiting and trying again."
|
173
|
+
sleep(1)
|
174
|
+
|
175
|
+
result = send_message(message)
|
176
|
+
|
177
|
+
rescue OpenSSL::SSL::SSLError => e
|
178
|
+
puts "BCB Warning: hangup from source trying to get last value. Waiting and trying again."
|
179
|
+
sleep(1)
|
180
|
+
|
181
|
+
result = sent_message(message)
|
182
|
+
|
164
183
|
rescue Exception => erro
|
165
184
|
result = nil
|
166
185
|
end
|
data/lib/eba/data.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
# making it easier to group lots of data in a coese way, without lost of
|
3
3
|
# information.
|
4
4
|
class Data_bcb
|
5
|
+
attr_accessor :seasonally_adjusted, :name, :unit, :value, :periodicity
|
6
|
+
|
5
7
|
@name = ""
|
6
8
|
@periodicity = ""
|
7
9
|
@unit = ""
|
@@ -12,17 +14,36 @@ class Data_bcb
|
|
12
14
|
|
13
15
|
# Initialization is expected to express the state of a single row of
|
14
16
|
# data inside the BCB's Database.
|
15
|
-
def initialize(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
17
|
+
def initialize(xmlResult)
|
18
|
+
if xmlResult.class.to_s.eql? 'Array' then
|
19
|
+
series_name, series_code, series_periodicity, series_unit,
|
20
|
+
series_day, series_month, series_year, series_value, seasonally_adjusted = xmlResult
|
21
|
+
|
22
|
+
@name = series_name
|
23
|
+
@pk = series_code
|
24
|
+
@periodicity = series_periodicity.to_s
|
25
|
+
@unit = series_unit
|
26
|
+
@date = standardizes_date(series_day, series_month, series_year)
|
27
|
+
@value = series_value.to_f
|
28
|
+
@seasonally_adjusted = seasonally_adjusted
|
29
|
+
|
30
|
+
else
|
31
|
+
begin
|
32
|
+
@name = xmlResult.search("NOME").text.sub("-_1532_-", "&")
|
33
|
+
@pk = xmlResult.search("CODIGO").text.to_i
|
34
|
+
@periodicity = xmlResult.search("PERIODICIDADE").text
|
35
|
+
@unit = xmlResult.search("UNIDADE").text.sub("-_1532_-", "&")
|
36
|
+
@date = standardizes_date(xmlResult.search("DIA").text,
|
37
|
+
xmlResult.search("MES").text,
|
38
|
+
xmlResult.search("ANO").text)
|
39
|
+
@value = xmlResult.search("VALOR").text
|
40
|
+
@seasonally_adjusted = false
|
41
|
+
rescue => e
|
42
|
+
puts e.message
|
43
|
+
puts e.backtrace
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
26
47
|
|
27
48
|
# Return an "identification key" with data which should
|
28
49
|
# be unique to a series (grouped).
|
@@ -31,7 +52,7 @@ class Data_bcb
|
|
31
52
|
end
|
32
53
|
|
33
54
|
def self.invalid_data()
|
34
|
-
Data_bcb.new(nil, nil, nil, nil, 1, 1, 1900, 0, false)
|
55
|
+
Data_bcb.new([nil, nil, nil, nil, 1, 1, 1900, 0, false])
|
35
56
|
end
|
36
57
|
|
37
58
|
def is_valid?
|
@@ -77,7 +98,6 @@ class Data_bcb
|
|
77
98
|
|
78
99
|
return true
|
79
100
|
end
|
80
|
-
|
81
101
|
|
82
102
|
# Note that there are no set methods in this class,
|
83
103
|
# I built it in such a way that you are only intended
|
@@ -107,10 +127,6 @@ class Data_bcb
|
|
107
127
|
return @value
|
108
128
|
end
|
109
129
|
|
110
|
-
def seasonally_adjusted
|
111
|
-
return @seasonally_adjusted
|
112
|
-
end
|
113
|
-
|
114
130
|
# The Webservice will always supply the date in three separate fields,
|
115
131
|
# this methods aim to convert it to a standard dd.mm.YYYY string.
|
116
132
|
def standardizes_date(day, month, year)
|
data/lib/eba/helper.rb
CHANGED
@@ -5,26 +5,23 @@ class Helper < Encoder
|
|
5
5
|
def initialize()
|
6
6
|
end
|
7
7
|
|
8
|
-
def build_bcb_data(
|
9
|
-
|
10
|
-
is_unseasoned = true
|
8
|
+
def build_bcb_data(xml_result)
|
9
|
+
d = Data_bcb.new(xml_result)
|
11
10
|
|
12
|
-
|
13
|
-
|
11
|
+
if d.name[" - com ajuste sazonal"] != nil then
|
12
|
+
d.seasonally_adjusted = true
|
13
|
+
|
14
|
+
if d.seasonally_adjusted then
|
15
|
+
d.name.slice!(" - com ajuste sazonal")
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
encoded_month = month
|
22
|
-
encoded_year = year
|
23
|
-
encoded_value = encode(value)
|
19
|
+
d.name = encode(d.name)
|
20
|
+
d.periodicity = encode(d.periodicity)
|
21
|
+
d.unit = encode(d.unit)
|
22
|
+
d.value = encode(d.value)
|
24
23
|
|
25
|
-
return
|
26
|
-
encoded_unit, encoded_day, encoded_month,
|
27
|
-
encoded_year, encoded_value, is_unseasoned)
|
24
|
+
return d
|
28
25
|
end
|
29
26
|
|
30
27
|
# Removes all invalid series from an array.
|
@@ -66,12 +63,12 @@ class Helper < Encoder
|
|
66
63
|
ano = data[1]
|
67
64
|
end
|
68
65
|
|
69
|
-
collection <<
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
collection << Data_bcb.new([base_data.name, code,
|
67
|
+
base_data.periodicity,
|
68
|
+
base_data.unit,
|
69
|
+
dia, mes, ano,
|
70
|
+
item.css("VALOR").text,
|
71
|
+
base_data.seasonally_adjusted])
|
75
72
|
end
|
76
73
|
else
|
77
74
|
puts "ERROR BCB: Failure do locate #{code} in the data collection #{code_x_data_hash.keys}"
|
data/lib/eba/version.rb
CHANGED
@@ -5,7 +5,7 @@ module Eba
|
|
5
5
|
# ff - commits on feature
|
6
6
|
# hh - commits on hotfix
|
7
7
|
|
8
|
-
VERSION = "2.0
|
8
|
+
VERSION = "2.1.0"
|
9
9
|
|
10
10
|
#Version 1.0.1
|
11
11
|
#
|
@@ -92,4 +92,7 @@ module Eba
|
|
92
92
|
|
93
93
|
#Version 2.0.2
|
94
94
|
# Improves reliability for getting data and identifying it.
|
95
|
+
|
96
|
+
#Version 2.1.0
|
97
|
+
# Implements handling of disconnects caused by the BCB webservice, getting data again and logging the event.
|
95
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafael Campos Cruz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|