cotcube-bardata 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/VERSION +1 -1
- data/cotcube-bardata.gemspec +3 -2
- data/lib/cotcube-bardata/cached.rb +6 -2
- data/lib/cotcube-bardata/daily.rb +93 -0
- data/lib/cotcube-bardata/helpers.rb +2 -2
- data/lib/cotcube-bardata/range_matrix.rb +42 -33
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a701303a258aaaf6050922e35eaacf53ce09fc43fc25778492ebb0b11fb9890c
|
4
|
+
data.tar.gz: 389709153f639e14638832e701f19a295181e1b81e26a8aa2ba2baf5c0587ee9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee32360405d9597e82c6eb9d7678895ecd1c7db9872ed2ecdd8efbd4fc0cd2ec4cea21d2546e867a45af3655ab251a34d39855d7b7d7865458ea60ff8ba65811
|
7
|
+
data.tar.gz: 7a4387b1834d811a61e9bd04fbe0a263f7f4a730b2a15cb928fb956929acefa5097a502fa548c26356f5ccac051d7f037344c42e320400a8a5eab55266119b81
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
## 0.1.8 (January 27, 2021)
|
2
|
+
- in helpers, #extended_range_for_date: fixed comparison signs
|
3
|
+
- range_matrix: applied cops, noted appearance of Cotcube::Helpers.simple_series_stats
|
4
|
+
- cached: Fixing wrong comparison sign
|
5
|
+
- daily: slimmed down results for #continuous_overview
|
6
|
+
|
1
7
|
## 0.1.7 (January 14, 2021)
|
2
8
|
- added :range parameter to :provide, hence to :provide_cached, :provide_daily
|
3
9
|
- added forgotten module_functions
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.8
|
data/cotcube-bardata.gemspec
CHANGED
@@ -34,7 +34,8 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_dependency 'parallel', '~> 1'
|
35
35
|
spec.add_dependency 'yaml', '~> 0.1'
|
36
36
|
|
37
|
-
|
37
|
+
# using ~> in favor of >= to overcome warning
|
38
|
+
spec.add_development_dependency 'rake', '~> 13'
|
38
39
|
spec.add_development_dependency 'rspec', '~>3.6'
|
39
|
-
spec.add_development_dependency 'yard',
|
40
|
+
spec.add_development_dependency 'yard', '~>0.9'
|
40
41
|
end
|
@@ -59,7 +59,9 @@ module Cotcube
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
return result
|
62
|
-
elsif File.mtime(file)
|
62
|
+
elsif File.mtime(file) + 1.day > File.mtime(quarters_file)
|
63
|
+
puts "CACHE #{File.mtime(file)}\t#{file}"
|
64
|
+
puts "QUART #{File.mtime(quarters_file)}\t#{quarters_file}"
|
63
65
|
result = if range.nil?
|
64
66
|
base
|
65
67
|
else
|
@@ -71,7 +73,9 @@ module Cotcube
|
|
71
73
|
# rubocop:enable Metrics/BlockNesting
|
72
74
|
return result
|
73
75
|
else
|
74
|
-
|
76
|
+
# write a (positive warning, that the cache needs to be updated, as cached value is older
|
77
|
+
# than one day but not closed
|
78
|
+
puts "File #{file} exists, but is neither closed nor current. Running update...".colorize(:light_green)
|
75
79
|
end
|
76
80
|
end
|
77
81
|
begin
|
@@ -132,6 +132,13 @@ module Cotcube
|
|
132
132
|
end
|
133
133
|
data.reject! { |x| x[selector].empty? }
|
134
134
|
result = data.group_by { |x| x[selector].first[:contract] }
|
135
|
+
result.each_key do |key|
|
136
|
+
result[key].map! do |x|
|
137
|
+
x[:volume].select! { |z| z[:contract] == key }
|
138
|
+
x[:oi].select! { |z| z[:contract] == key }
|
139
|
+
x
|
140
|
+
end
|
141
|
+
end
|
135
142
|
if human
|
136
143
|
result.each do |k, v|
|
137
144
|
next unless filter.nil? || v.first[selector].first[:contract][2..4] =~ (/#{filter}/)
|
@@ -152,5 +159,91 @@ module Cotcube
|
|
152
159
|
end
|
153
160
|
result
|
154
161
|
end
|
162
|
+
|
163
|
+
def continuous_table(symbol: nil, id: nil,
|
164
|
+
selector: :volume,
|
165
|
+
filter: nil,
|
166
|
+
debug: false)
|
167
|
+
raise ArgumentError, 'Selector must be either :volume or :oi' unless selector.is_a?(Symbol) &&
|
168
|
+
%i[volume oi].include?(selector)
|
169
|
+
|
170
|
+
sym = get_id_set(symbol: symbol, id: id)
|
171
|
+
if %w[R6 BJ GE].include? sym[:symbol]
|
172
|
+
puts "Rejecting to process symbol '#{sym[:symbol]}'."
|
173
|
+
return
|
174
|
+
end
|
175
|
+
id = sym[:id]
|
176
|
+
dfm = lambda do |x, y = Date.today.year|
|
177
|
+
k = Date.strptime("#{y} #{x.negative? ? x + 366 : x}", '%Y %j')
|
178
|
+
k -= 1 while [0, 6].include?(k.wday)
|
179
|
+
k.strftime('%a, %Y-%m-%d')
|
180
|
+
rescue StandardError
|
181
|
+
puts "#{sym[:symbol]}\t#{x}\t#{y}"
|
182
|
+
end
|
183
|
+
|
184
|
+
ytoday = Date.today.yday
|
185
|
+
data = continuous_overview(id: id, selector: selector, filter: filter, human: false, config: init)
|
186
|
+
.reject { |k, _| k[-2..].to_i == Date.today.year % 2000 }
|
187
|
+
.group_by { |k, _| k[2] }
|
188
|
+
output_sent = 0
|
189
|
+
data.keys.sort.each do |month|
|
190
|
+
puts "Processing #{sym[:symbol]}#{month}" if debug
|
191
|
+
v0 = data[month]
|
192
|
+
ydays = v0.map { |_, v1| Date.parse(v1.last[:date]).yday }
|
193
|
+
fdays = v0.map { |_, v1| Date.parse(v1.first[:date]).yday }.sort
|
194
|
+
# if the last ml day nears the end of the year, we must fix
|
195
|
+
ydays.map! { |x| x > 350 ? x - 366 : x } if ydays.min < 50
|
196
|
+
fday = fdays[fdays.size / 2]
|
197
|
+
yavg = ydays.reduce(:+) / ydays.size
|
198
|
+
# a contract is proposed to use after fday - 1, but before ydays.min (green)
|
199
|
+
# it is warned to user after fday - 1 but before yavg - 1 (red)
|
200
|
+
# it is warned red >= yavg - 1 and <= yavg + 1
|
201
|
+
color = if (ytoday >= yavg - 1) && (ytoday <= yavg + 1)
|
202
|
+
:light_red
|
203
|
+
elsif (ytoday > ydays.min) && (ytoday < yavg - 1)
|
204
|
+
:light_yellow
|
205
|
+
elsif (ytoday >= (fday > yavg ? 0 : fday - 5)) && (ytoday <= ydays.min)
|
206
|
+
:light_green
|
207
|
+
else
|
208
|
+
:white
|
209
|
+
end
|
210
|
+
if debug || (color != :white)
|
211
|
+
# rubocop:disable Layout/ClosingParenthesisIndentation
|
212
|
+
puts "#{sym[:symbol]
|
213
|
+
}#{month
|
214
|
+
}\t#{format '%12s', sym[:type]
|
215
|
+
}\t#{ytoday
|
216
|
+
}/#{fday
|
217
|
+
}\t#{format '%5d', ydays.min
|
218
|
+
}: #{dfm.call(ydays.min)
|
219
|
+
}\t#{format '%5d', yavg
|
220
|
+
}: #{dfm.call(yavg)
|
221
|
+
}\t#{format '%5d', ydays.max
|
222
|
+
}: #{dfm.call(ydays.max)}".colorize(color)
|
223
|
+
output_sent += 1
|
224
|
+
end
|
225
|
+
next unless debug
|
226
|
+
|
227
|
+
v0.each do |contract, v1|
|
228
|
+
puts "\t#{contract
|
229
|
+
}\t#{v1.first[:date]
|
230
|
+
}\t#{Date.parse(v1.last[:date]).strftime('%a')
|
231
|
+
}, #{v1.last[:date]
|
232
|
+
} (#{Date.parse(v1.last[:date]).yday}"
|
233
|
+
# rubocop:enable Layout/ClosingParenthesisIndentation
|
234
|
+
end
|
235
|
+
end
|
236
|
+
case output_sent
|
237
|
+
when 0
|
238
|
+
puts "WARNING: No output was sent for symbol '#{sym[:symbol]}'.".colorize(:light_yellow)
|
239
|
+
when 1
|
240
|
+
# all ok
|
241
|
+
true
|
242
|
+
else
|
243
|
+
puts "---- #{output_sent} for #{sym[:symbol]} ---------------"
|
244
|
+
|
245
|
+
end
|
246
|
+
nil
|
247
|
+
end
|
155
248
|
end
|
156
249
|
end
|
@@ -36,11 +36,11 @@ module Cotcube
|
|
36
36
|
' is assumed (starting 5 pm CT yesterday, ending 4 pm CT today)'.colorize(:light_yellow)
|
37
37
|
end
|
38
38
|
result = select_specific_date(date: starting, base: base)
|
39
|
-
result += base.select { |d| d[:datetime]
|
39
|
+
result += base.select { |d| d[:datetime] >= starting and d[:datetime] < ending.to_date }
|
40
40
|
result += select_specific_date(date: ending, base: base)
|
41
41
|
result.uniq!
|
42
42
|
else
|
43
|
-
result = base.select { |x| x[:datetime] >= starting and x[:datetime]
|
43
|
+
result = base.select { |x| x[:datetime] >= starting and x[:datetime] <= ending }
|
44
44
|
end
|
45
45
|
result
|
46
46
|
end
|
@@ -12,7 +12,7 @@ module Cotcube
|
|
12
12
|
# 2. avg:
|
13
13
|
# 3. lower: like median, but not at 1/2 but 1/4
|
14
14
|
# 4. median:
|
15
|
-
# 5. upper: like median,
|
15
|
+
# 5. upper: like median, but not at 1/2 but 3/4
|
16
16
|
# 6. max:
|
17
17
|
# and columns:
|
18
18
|
# 1.a) all days os the series
|
@@ -20,6 +20,8 @@ module Cotcube
|
|
20
20
|
# 1.c) the last 200 days
|
21
21
|
# 2.a-c) same with days reduced to weeks (c: 52 weeks)
|
22
22
|
# 3.a-c) same with days reduced to months (c: 12 months)
|
23
|
+
#
|
24
|
+
# NOTE: there is now a new method Cotcube::Helpers.simple_series_stats, that should be used in favor.
|
23
25
|
def range_matrix(symbol: nil, id: nil, print: false, dim: 0.05)
|
24
26
|
# rubocop:disable Style/MultilineBlockChain
|
25
27
|
sym = get_id_set(symbol: symbol, id: id)
|
@@ -38,36 +40,43 @@ module Cotcube
|
|
38
40
|
target[period][:all_size] = source[period].size
|
39
41
|
target[period][:all_avg] = (source[period].map { |x| x[:range] }.reduce(:+) / source[period].size).round
|
40
42
|
target[period][:all_lower] = source[period].sort_by do |x|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
43
|
+
x[:range]
|
44
|
+
end.map { |x| x[:range] }[ (source[period].size * 1 / 4).round ]
|
45
|
+
|
46
|
+
target[period][:all_median] = source[period].sort_by do |x|
|
47
|
+
x[:range]
|
48
|
+
end.map { |x| x[:range] }[ (source[period].size * 2 / 4).round ]
|
49
|
+
|
50
|
+
target[period][:all_upper] = source[period].sort_by do |x|
|
51
|
+
x[:range]
|
52
|
+
end.map { |x| x[:range] }[ (source[period].size * 3 / 4).round ]
|
53
|
+
|
49
54
|
target[period][:all_max] = source[period].map { |x| x[:range] }.max
|
50
55
|
target[period][:all_records] = source[period].sort_by do |x|
|
51
|
-
|
52
|
-
|
56
|
+
-x[:range]
|
57
|
+
end.map { |x| { contract: x[:contract], range: x[:range] } }.take(5)
|
53
58
|
|
54
59
|
tenth = (source[period].size * dim).round
|
55
60
|
custom = source[period].sort_by { |x| x[:range] }[tenth..source[period].size - tenth]
|
61
|
+
|
56
62
|
target[period][:dim_size] = custom.size
|
57
63
|
target[period][:dim_avg] = (custom.map { |x| x[:range] }.reduce(:+) / custom.size).round
|
58
64
|
target[period][:dim_lower] = custom.sort_by do |x|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
x[:range]
|
66
|
+
end.map { |x| x[:range] }[ (custom.size * 1 / 4).round ]
|
67
|
+
|
68
|
+
target[period][:dim_median] = custom.sort_by do |x|
|
69
|
+
x[:range]
|
70
|
+
end.map { |x| x[:range] }[ (custom.size * 2 / 4).round ]
|
71
|
+
|
72
|
+
target[period][:dim_upper] = custom.sort_by do |x|
|
73
|
+
x[:range]
|
74
|
+
end.map { |x| x[:range] }[ (custom.size * 3 / 4).round ]
|
75
|
+
|
76
|
+
target[period][:dim_max] = custom.map { |x| x[:range] }.max
|
68
77
|
target[period][:dim_records] = custom.sort_by do |x|
|
69
|
-
|
70
|
-
|
78
|
+
-x[:range]
|
79
|
+
end.map { |x| { contract: x[:contract], range: x[:range] } }.take(5)
|
71
80
|
|
72
81
|
range = case period
|
73
82
|
when :months
|
@@ -83,18 +92,18 @@ module Cotcube
|
|
83
92
|
target[period][:rec_size] = custom.size
|
84
93
|
target[period][:rec_avg] = (custom.map { |x| x[:range] }.reduce(:+) / custom.size).round
|
85
94
|
target[period][:rec_lower] = custom.sort_by do |x|
|
86
|
-
|
87
|
-
|
88
|
-
target[period][:rec_median] =
|
89
|
-
|
90
|
-
|
91
|
-
target[period][:rec_upper]
|
92
|
-
|
93
|
-
|
94
|
-
target[period][:rec_max]
|
95
|
+
x[:range]
|
96
|
+
end.map { |x| x[:range] }[ (custom.size * 1 / 4).round ]
|
97
|
+
target[period][:rec_median] = custom.sort_by do |x|
|
98
|
+
x[:range]
|
99
|
+
end.map { |x| x[:range] }[ (custom.size * 2 / 4).round ]
|
100
|
+
target[period][:rec_upper] = custom.sort_by do |x|
|
101
|
+
x[:range]
|
102
|
+
end.map { |x| x[:range] }[ (custom.size * 3 / 4).round ]
|
103
|
+
target[period][:rec_max] = custom.map { |x| x[:range] }.max
|
95
104
|
target[period][:rec_records] = custom.sort_by do |x|
|
96
|
-
|
97
|
-
|
105
|
+
-x[:range]
|
106
|
+
end.map { |x| { contract: x[:contract], range: x[:range] } }.take(5)
|
98
107
|
end
|
99
108
|
|
100
109
|
if print
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotcube-bardata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin L. Tischendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -112,16 +112,16 @@ dependencies:
|
|
112
112
|
name: rake
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '13'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '13'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: rspec
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|