cotcube-bardata 0.1.9.3 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bf0d80a7c81bd75a4d9ca26c5571a57938a73fdfd47543ab82e9ea93f42e3f0
4
- data.tar.gz: 9c53d62b2fbcb17700a2f1f4c08586ed218098ad80a9247b6b839486d46829ce
3
+ metadata.gz: 2b80704cc4d7c8f63dc458e63d4e9c275726c1a37cf4671e0a2d57d5cf7d616f
4
+ data.tar.gz: d46691cd8c9272c608c3d596f63ca449df989bfc5a6cb95ad07301a63a1acba2
5
5
  SHA512:
6
- metadata.gz: ac6600a7a6f7791df53e631e49f3a4f56e8f2c95801b699dd06510f0b072f7a20d22a8edefbc2b53ef183954c4c13e0889442af2b06911e1ddd3c339217daa3b
7
- data.tar.gz: c30e7df2409407c08433baf345660d1dcaeb24b85a035bc2344d2c401303b0961b7dcf901d6e2c5f98f34f273228df2588a8fd83a4e50b0fbbff61d4b541c7c3
6
+ metadata.gz: 2abe99e7c0f94bc26246817d1dcc3e40a52eb1bd32a8240cc54190b0c90ce56f2e4301e59d1756cf691e291dcd10cec720ee6c231e9dd23bf354082d8be25bb7
7
+ data.tar.gz: 4e23f62c7b1a570d9d6a42ddcffc5d67917b53438ab3f8012687acc041a2ed511ecdddc8c0ce26cd46681f5c93d94b9540b2df35f6954771a5af8e7f94e91c43
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.1.10 (February 11, 2021)
2
+ - Daily.rb: Added measure parameters to continous_suite
3
+ - cached.rb: Minor fix in comparison
4
+
1
5
  ## 0.1.9.3 (February 08, 2021)
2
6
  - cached: minor change fixing problem to get yesterday in rth subsets
3
7
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.9.3
1
+ 0.1.10
@@ -60,7 +60,7 @@ module Cotcube
60
60
  end
61
61
  end
62
62
  return result
63
- elsif File.mtime(file) + 1.day > File.mtime(quarters_file)
63
+ elsif File.mtime(file) - Time.now.beginning_of_day >= 0
64
64
  puts "CACHE #{File.mtime(file)}\t#{file}" if debug
65
65
  puts "QUART #{File.mtime(quarters_file)}\t#{quarters_file}" if debug
66
66
  result = if range.nil?
@@ -61,20 +61,33 @@ module Cotcube
61
61
 
62
62
  # reads all files in bardata/daily/<id> and aggregates by date
63
63
  # (what is a pre-stage of a continuous based on daily bars)
64
- def continuous(symbol: nil, id: nil, config: init, date: nil)
64
+ def continuous(symbol: nil, id: nil, config: init, date: nil, measure: nil, force_rewrite: false)
65
+ raise ArgumentError, ':measure, if given, must be a Time object (e.g. Time.now)' unless [NilClass, Time].include? measure.class
66
+ measuring = lambda {|c| puts "[continuous] Time measured until '#{c}': #{(Time.now.to_f - measure.to_f).round(2)}sec" unless measure.nil? }
67
+
68
+ measuring.call("Starting")
65
69
  sym = get_id_set(symbol: symbol, id: id)
66
70
  id = sym[:id]
67
71
  id_path = "#{config[:data_path]}/daily/#{id}"
68
- available_contracts = Dir["#{id_path}/*.csv"].map { |x| x.split('/').last.split('.').first }
69
- available_contracts.sort_by! { |x| x[-7] }.sort_by! { |x| x[-6..-5] }
70
- data = []
71
- available_contracts.each do |c|
72
- provide_daily(id: id, config: config, contract: c).each do |x|
73
- data << x
74
- end
72
+ c_file = "#{id_path}/continuous.csv"
73
+
74
+ # instead of using the provide_daily methods above, for this bulk operation a 'continuous.csv' is created
75
+ # this boosts from 4.5sec to 0.3sec
76
+ if not File.exist?(c_file) or Time.now - File.mtime(c_file) > 8.days or force_rewrite
77
+ puts "In daily+continuous: Rewriting #{c_file} #{force_rewrite ? "forcibly" : "due to fileage"}.".light_yellow
78
+ `rm #{c_file}; find #{id_path} | xargs cat 2>/dev/null | grep -v '0,0,0,0' | sort -t, -k2 | cut -d, -f1,2,7,8 > #{c_file}`
75
79
  end
80
+ data = CSV.read(c_file).map do |row|
81
+ r = { contract: row[0],
82
+ date: row[1],
83
+ volume: row[2].to_i,
84
+ oi: row[3].to_i
85
+ }
86
+ end
87
+
88
+ measuring.call("Finished retrieving dailies.")
76
89
  result = []
77
- data.sort_by { |x| x[:date] }.group_by { |x| x[:date] }.map do |k, v|
90
+ data.group_by { |x| x[:date] }.map do |k, v|
78
91
  v.map { |x| x.delete(:date) }
79
92
  result << {
80
93
  date: k,
@@ -83,6 +96,7 @@ module Cotcube
83
96
  }
84
97
  result.last[:contracts] = v
85
98
  end
99
+ measuring.call("Finished processing")
86
100
  date.nil? ? result : result.select { |x| x[:date] == date }.first
87
101
  end
88
102
 
@@ -116,20 +130,27 @@ module Cotcube
116
130
  config: init,
117
131
  selector: :volume,
118
132
  human: false,
133
+ measure: nil,
119
134
  filter: nil)
135
+
136
+ raise ArgumentError, ':measure, if given, must be a Time object (e.g. Time.now)' unless [NilClass, Time].include? measure.class
137
+ measuring = lambda {|c| puts "[continuous_overview] Time measured until '#{c}': #{(Time.now.to_f - measure.to_f).round(2)}sec" unless measure.nil? }
138
+
120
139
  raise ArgumentError, 'Selector must be either :volume or :oi' unless selector.is_a?(Symbol) &&
121
- %i[volume oi].include?(selector)
140
+ %i[volume oi].include?(selector)
122
141
 
142
+ measuring.call("Starting")
123
143
  sym = get_id_set(symbol: symbol, id: id)
124
144
  id = sym[:id]
125
145
  # noinspection RubyNilAnalysis
126
- data = continuous(id: id, config: config).map do |x|
146
+ data = continuous(id: id, config: config, measure: measure).map do |x|
127
147
  {
128
148
  date: x[:date],
129
149
  volume: x[:contracts].sort_by { |z| - z[:volume] }[0..4].compact.reject { |z| z[:volume].zero? },
130
150
  oi: x[:contracts].sort_by { |z| - z[:oi] }[0..4].compact.reject { |z| z[:oi].zero? }
131
151
  }
132
152
  end
153
+ measuring.call("Retrieved continuous")
133
154
  data.reject! { |x| x[selector].empty? }
134
155
  result = data.group_by { |x| x[selector].first[:contract] }
135
156
  result.each_key do |key|
@@ -149,14 +170,15 @@ module Cotcube
149
170
  }\t#{v.last[:date]
150
171
  }\t#{format('%4d', (Date.parse(v.last[:date]) - Date.parse(v.first[:date])))
151
172
  }\t#{result[k].map do |x|
152
- x[:volume].select do
153
- x[:contract] == k
154
- end
155
- end.size
173
+ x[:volume].select do
174
+ x[:contract] == k
175
+ end
176
+ end.size
156
177
  }"
157
178
  # rubocop:enable Layout/ClosingParenthesisIndentation
158
179
  end
159
180
  end
181
+ measuring.call("Finished processing")
160
182
  result
161
183
  end
162
184
 
@@ -164,19 +186,25 @@ module Cotcube
164
186
  selector: :volume,
165
187
  filter: nil,
166
188
  date: Date.today,
189
+ measure: nil,
167
190
  debuglevel: 1,
168
191
  debug: false)
169
192
  if debug.is_a?(Integer)
170
193
  debuglevel = debug
171
194
  debug = debuglevel > 0 ? true : false
172
195
  end
196
+
197
+ raise ArgumentError, ':measure, if given, must be a Time object (e.g. Time.now)' unless [NilClass, Time].include? measure.class
198
+ measuring = lambda {|c| puts "[continuous_table] Time measured until '#{c}': #{(Time.now.to_f - measure.to_f).round(2)}sec" unless measure.nil? }
199
+
173
200
  raise ArgumentError, 'Selector must be either :volume or :oi' unless selector.is_a?(Symbol) &&
174
- %i[volume oi].include?(selector)
201
+ %i[volume oi].include?(selector)
175
202
 
203
+ measuring.call("Entering function")
176
204
  sym = get_id_set(symbol: symbol, id: id)
177
205
  if %w[R6 BJ GE].include? sym[:symbol]
178
- puts "Rejecting to process symbol '#{sym[:symbol]}'."
179
- return
206
+ puts "Rejecting to process symbol '#{sym[:symbol]}'.".light_red
207
+ return []
180
208
  end
181
209
  id = sym[:id]
182
210
  dfm = lambda do |x, y = date.year|
@@ -188,9 +216,10 @@ module Cotcube
188
216
  end
189
217
 
190
218
  ytoday = date.yday
191
- data = continuous_overview(id: id, selector: selector, filter: filter, human: false, config: init)
219
+ data = continuous_overview(id: id, selector: selector, filter: filter, human: false, config: init, measure: measure)
192
220
  .reject { |k, _| k[-2..].to_i == date.year % 2000 }
193
- .group_by { |k, _| k[2] }
221
+ .group_by { |k, _| k[2] }
222
+ measuring.call("Retrieved continous_overview")
194
223
  output_sent = []
195
224
  early_year=nil
196
225
  data.keys.sort.each do |month|
@@ -226,21 +255,21 @@ module Cotcube
226
255
  }: #{dfm.call(yavg)
227
256
  }\t#{format '%5d', ydays.max
228
257
  }: #{dfm.call(ydays.max)}".colorize(color)
229
- if debug || (color != :white)
230
- puts output
231
- output_sent << "#{sym[:symbol]}#{month}" unless color == :white
232
- end
233
- early_year ||= output
234
- next unless (debug and debuglevel >= 2)
258
+ if debug || (color != :white)
259
+ puts output
260
+ output_sent << "#{sym[:symbol]}#{month}" unless color == :white
261
+ end
262
+ early_year ||= output
263
+ next unless (debug and debuglevel >= 2)
235
264
 
236
- v0.each do |contract, v1|
237
- puts "\t#{contract
265
+ v0.each do |contract, v1|
266
+ puts "\t#{contract
238
267
  }\t#{v1.first[:date]
239
268
  }\t#{Date.parse(v1.last[:date]).strftime('%a')
240
269
  }, #{v1.last[:date]
241
270
  } (#{Date.parse(v1.last[:date]).yday}"
242
271
  # rubocop:enable Layout/ClosingParenthesisIndentation
243
- end
272
+ end
244
273
  end
245
274
  case output_sent.size
246
275
  when 0
@@ -254,6 +283,7 @@ module Cotcube
254
283
  puts "---- #{output_sent} for #{sym[:symbol]} ---------------"
255
284
 
256
285
  end
286
+ measuring.call("Finished processing")
257
287
  output_sent
258
288
  end
259
289
  end
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.9.3
4
+ version: 0.1.10
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-02-08 00:00:00.000000000 Z
11
+ date: 2021-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport