cotcube-helpers 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32c7ba958cf4ee90e698fbc9b09332917a8fb085234612440f4fe5d013776767
4
- data.tar.gz: ac8f2b8aac6e5b337f2cc2a3bc1d00c5573c67c8ddfe22fadd8dfeaee4be8a18
3
+ metadata.gz: e00fe82276d1be8a2f034759240a0bf820574f6c99de4ec6126bf436bf6a149b
4
+ data.tar.gz: e512de0546fd46dcdb356a55265bb8bc874999447c98df67c77b1289a8e2cee4
5
5
  SHA512:
6
- metadata.gz: 066b9a5f15172a43f8fb7bba7384a26d930e3ae0cb936103cdae3865331e8670eeff26f2d7a80f84feebfd393c070fb5bc37738d7faa3b1556a6cc3c7b82cbee
7
- data.tar.gz: ea7b4c464252c118e68cf7e220a60f36d2541e32f3e478a49b921dbbc03d84de34a5d8ca0a33c29e5c7351fec019e284f9fffc3ac133795a36da1d2c7ec2af60
6
+ metadata.gz: 5c0474d0638810ecf7af38f662c80c9a91ac531e5d38e71ff03e7872b559a4add577437c91c435ace0a8b1afc2adb1c1b686272426b6404d138d9d7b3fdfa8af
7
+ data.tar.gz: 94b42e991e539ac38e672c0fea5aba4a052e9c5a2b3899bc48d3e855ce23541f04f3b8a8640bb9bb76bd144476e4110d226e4a28298c66ad45480b3d80031a51
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## 0.1.10 (October 28, 2021)
2
+ - added script cron_ruby_wrapper.sh (linkable as /usr/local/bin/cruw.sh)
3
+ - added numeric ext .with_delimiter to support printing like 123_456_789.00121
4
+ - added micros to module
5
+ - added Helpers.micros to symbols.rb
6
+ - subpattern: excaping regex pattern to avoid ESC errors
7
+ - minor change
8
+
9
+ ## 0.1.9.2 (July 24, 2021)
10
+ - added missing module_functions
11
+ - init: minor fix
12
+ - datetime_ext: added warning comment / TODO, as switch from to daylight time will produce erroneous results
13
+ - constants: minor fix (typo)
14
+ - array_ext: added param to provide a default return value if result is an empty array
15
+
16
+ ## 0.1.9.1 (May 07, 2021)
17
+ - moved 'get_id_set' to Cotcube::Helpers
18
+ - minor fix to suppress some warning during build
19
+
20
+ ## 0.1.9 (May 07, 2021)
21
+ - added constants, init and symbols to helpers
22
+
1
23
  ## 0.1.8 (April 18, 2021)
2
24
  - datetime_ext: Date.cw provides a range of (Date..Date) representing the according calendar week
3
25
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.8
1
+ 0.1.10
@@ -26,9 +26,11 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_dependency 'activesupport'
29
+ spec.add_dependency 'activesupport', '~> 6'
30
+ spec.add_dependency 'colorize', '~> 0.8'
30
31
 
31
- spec.add_development_dependency 'rake'
32
+
33
+ spec.add_development_dependency 'rake', '~> 13'
32
34
  spec.add_development_dependency 'rspec', '~>3.6'
33
35
  spec.add_development_dependency 'yard', '~>0.9'
34
36
  end
@@ -29,10 +29,10 @@ class Array
29
29
  # This method iterates over an Array by calling the given block on all 2 consecutive elements
30
30
  # it returns a Array of self.size - 1
31
31
  #
32
- def pairwise(ret=nil, &block)
32
+ def pairwise(ret=nil, empty: nil, &block)
33
33
  raise ArgumentError, 'Array.one_by_one needs an arity of 2 (i.e. |a, b|)' unless block.arity == 2
34
- raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' unless self.last.respond_to?(:[]=)
35
- return [] if size <= 1
34
+ raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' if not ret.nil? and not self.last.respond_to?(:[]=)
35
+ return empty ||= [] if size <= 1
36
36
 
37
37
  each_index.map do |i|
38
38
  next if i.zero?
@@ -47,7 +47,7 @@ class Array
47
47
  # same as pairwise, but with arity of three
48
48
  def triplewise(ret=nil, &block)
49
49
  raise ArgumentError, 'Array.triplewise needs an arity of 3 (i.e. |a, b, c|)' unless block.arity == 3
50
- raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' unless self.last.respond_to?(:[]=)
50
+ raise ArgumentError, 'Each element of Array should respond to []=, at least the last one fails.' if not ret.nil? and not self.last.respond_to?(:[]=)
51
51
  return [] if size <= 2
52
52
 
53
53
  each_index.map do |i|
@@ -0,0 +1,38 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ module Helpers
5
+ SYMBOL_EXAMPLES = [
6
+ { id: '13874U', symbol: 'ES', ticksize: 0.25, power: 12.5, months: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'S&P 500 MICRO' },
7
+ { id: '209747', symbol: 'NQ', ticksize: 0.25, power: 5.0, monhts: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'NASDAQ 100 MICRO' }
8
+ ].freeze
9
+
10
+ MICRO_EXAMPLES = [
11
+ { id: '13874U', symbol: 'ET', ticksize: 0.25, power: 1.25, months: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'MICRO S&P 500 MICRO' },
12
+ { id: '209747', symbol: 'NM', ticksize: 0.25, power: 0.5, monhts: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'MICRO NASDAQ 100 MICRO' }
13
+ ].freeze
14
+
15
+ COLORS = %i[light_red light_yellow light_green red yellow green cyan magenta blue].freeze
16
+
17
+ MONTH_COLOURS = { 'F' => :cyan, 'G' => :green, 'H' => :light_green,
18
+ 'J' => :blue, 'K' => :yellow, 'M' => :light_yellow,
19
+ 'N' => :cyan, 'Q' => :magenta, 'U' => :light_magenta,
20
+ 'V' => :blue, 'X' => :red, 'Z' => :light_red }.freeze
21
+
22
+ MONTHS = { 'F' => 1, 'G' => 2, 'H' => 3,
23
+ 'J' => 4, 'K' => 5, 'M' => 6,
24
+ 'N' => 7, 'Q' => 8, 'U' => 9,
25
+ 'V' => 10, 'X' => 11, 'Z' => 12,
26
+ 1 => 'F', 2 => 'G', 3 => 'H',
27
+ 4 => 'J', 5 => 'K', 6 => 'M',
28
+ 7 => 'N', 8 => 'Q', 9 => 'U',
29
+ 10 => 'V', 11 => 'X', 12 => 'Z' }.freeze
30
+
31
+
32
+ CHICAGO = Time.find_zone('America/Chicago')
33
+
34
+ DATE_FMT = '%Y-%m-%d'
35
+
36
+ end
37
+ end
38
+
@@ -4,6 +4,9 @@
4
4
  class DateTime
5
5
  # based on the fact that sunday is 'wday 0' plus that trading week starts
6
6
  # sunday 0:00 (as trading starts sunday 5pm CT to fit tokyo monday morning)
7
+ #
8
+ # TODO: there is a slight flaw, that 1 sunday per year is 1 hour too short and another is 1 hour too long
9
+ #
7
10
  def to_seconds_since_sunday_morning
8
11
  wday * 86_400 + hour * 3600 + min * 60 + sec
9
12
  end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ module Helpers
5
+
6
+ def get_id_set(symbol: nil, id: nil, contract: nil, config: init, mini: false, micro: false)
7
+ micro = mini || micro
8
+ contract = contract.to_s.upcase if contract.is_a? Symbol
9
+ id = id.to_s.upcase if id.is_a? Symbol
10
+ symbol = symbol.to_s.upcase if symbol.is_a? Symbol
11
+
12
+ if contract.is_a?(String) && ([2,3,4,5].include? contract.length)
13
+ c_symbol = contract[0..1]
14
+ if (not symbol.nil?) && (symbol != c_symbol)
15
+ raise ArgumentError,
16
+ "Mismatch between given symbol #{symbol} and contract #{contract}"
17
+ end
18
+
19
+ symbol = c_symbol
20
+ end
21
+
22
+ unless symbol.nil?
23
+ sym = symbols(symbol: symbol)
24
+ if sym.nil? || sym[:id].nil?
25
+ raise ArgumentError,
26
+ "Could not find match in #{config[:symbols_file]} for given symbol #{symbol}"
27
+ end
28
+ raise ArgumentError, "Mismatching symbol #{symbol} and given id #{id}" if (not id.nil?) && (sym[:id] != id)
29
+
30
+ return micro ? micros(id: sym[:id]) : sym
31
+ end
32
+ unless id.nil?
33
+ sym = symbols(id: id)
34
+ if sym.nil? || sym[:id].nil?
35
+ raise ArgumentError,
36
+ "Could not find match in #{config[:symbols_file]} for given id #{id}"
37
+ end
38
+ return micro ? micros(id: sym[:id]) : sym
39
+ end
40
+ raise ArgumentError, 'Need :id, :symbol or valid :contract '
41
+ end
42
+ end
43
+ end
44
+
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ module Helpers
5
+
6
+ def config_prefix
7
+ os = Gem::Platform.local.os
8
+ case os
9
+ when 'linux'
10
+ ''
11
+ when 'freebsd'
12
+ '/usr/local'
13
+ else
14
+ raise RuntimeError, "Unsupported architecture: #{os}"
15
+ end
16
+ end
17
+
18
+ def config_path
19
+ config_prefix + '/etc/cotcube'
20
+ end
21
+
22
+ def init(config_file_name: nil,
23
+ gem_name: nil,
24
+ debug: false)
25
+ gem_name ||= self.ancestors.first.to_s
26
+ config_file_name = "#{gem_name.downcase.split('::').last}.yml"
27
+ config_file = config_path + "/#{config_file_name}"
28
+
29
+ if File.exist?(config_file)
30
+ require 'yaml'
31
+ config = YAML.load(File.read config_file).transform_keys(&:to_sym)
32
+ else
33
+ config = {}
34
+ end
35
+
36
+ defaults = {
37
+ data_path: '/var/cotcube/' + name,
38
+ }
39
+
40
+ config = defaults.merge(config)
41
+ puts "CONFIG is '#{config}'" if debug
42
+
43
+ config
44
+ end
45
+ end
46
+ end
47
+
@@ -0,0 +1,8 @@
1
+ class Numeric
2
+ def with_delimiter(deli=nil)
3
+ raise ArgumentError, "Param delimiter can't be nil" if deli.nil?
4
+ pre, post = self.to_s.split('.')
5
+ pre = pre.chars.to_a.reverse.each_slice(3).map(&:join).join(deli).reverse
6
+ post.nil? ? pre : [pre,post].join('.')
7
+ end
8
+ end
@@ -22,12 +22,12 @@ module Cotcube
22
22
  lambda do |x|
23
23
  return false if x.nil? || (x.size < minimum)
24
24
 
25
- return ((pattern =~ /^#{x}/i).nil? ? false : true)
25
+ return ((pattern =~ /^#{Regexp.escape x}/i).nil? ? false : true)
26
26
  end
27
27
  when Array
28
28
  pattern.map do |x|
29
29
  unless [String, Symbol, NilClass].include? x.class
30
- raise TypeError, "Unsupported class '#{x.class}' for '#{x}'in pattern '#{pattern}'."
30
+ raise TypeError, "Unsupported class '#{x.class}' for '#{x}' in pattern '#{pattern}'."
31
31
  end
32
32
  end
33
33
  lambda do |x|
@@ -35,13 +35,13 @@ module Cotcube
35
35
  sub = sub.to_s
36
36
  return false if x.size < minimum
37
37
 
38
- result = ((sub =~ /^#{x}/i).nil? ? false : true)
38
+ result = ((sub =~ /^#{Regexp.escape x}/i).nil? ? false : true)
39
39
  return true if result
40
40
  end
41
41
  return false
42
42
  end
43
43
  else
44
- raise TypeError, "Unsupported class #{pattern.class} in Cotcube::Core::sub"
44
+ raise TypeError, "Unsupported class #{pattern.class} in Cotcube::Helpers::sub"
45
45
  end
46
46
  end
47
47
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ # Missing top level documentation
5
+ module Helpers
6
+
7
+ def symbols(config: init, type: nil, symbol: nil, id: nil)
8
+ if config[:symbols_file].nil?
9
+ SYMBOL_EXAMPLES
10
+ else
11
+ CSV
12
+ .read(config[:symbols_file], headers: %i{ id symbol ticksize power months type bcf reports format name})
13
+ .map{|row| row.to_h }
14
+ .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row[:format] = "%#{row[:format]}f"; row }
15
+ .reject{|row| row[:id].nil? }
16
+ .tap { |all| all.select!{|x| x[:type] == type} unless type.nil? }
17
+ .tap { |all| (return all.select { |x| x[:symbol] == symbol }.first ) unless symbol.nil? }
18
+ .tap{ |all| (return all.select { |x| x[:id] == id }.first) unless id.nil? }
19
+ end
20
+ end
21
+
22
+ def micros(config: init, symbol: nil, id: nil)
23
+ if config[:micros_file].nil?
24
+ MICRO_EXAMPLES
25
+ else
26
+ CSV
27
+ .read(config[:micros_file], headers: %i{ id symbol ticksize power months type bcf reports format name})
28
+ .map{|row| row.to_h }
29
+ .map{|row| [ :ticksize, :power, :bcf ].each {|z| row[z] = row[z].to_f}; row[:format] = "%#{row[:format]}f"; row }
30
+ .reject{|row| row[:id].nil? }
31
+ .tap{ |all| (return all.select { |x| x[:symbol] == symbol }.first) unless symbol.nil? }
32
+ .tap{ |all| (return all.select { |x| x[:id] == id }.first) unless id.nil? }
33
+ end
34
+ end
35
+ end
36
+
37
+ end
@@ -6,6 +6,7 @@ require 'active_support'
6
6
  require 'active_support/core_ext/time'
7
7
  require 'active_support/core_ext/numeric'
8
8
  require 'parallel'
9
+ require 'csv'
9
10
 
10
11
  require_relative 'cotcube-helpers/array_ext'
11
12
  require_relative 'cotcube-helpers/enum_ext'
@@ -13,20 +14,31 @@ require_relative 'cotcube-helpers/hash_ext'
13
14
  require_relative 'cotcube-helpers/range_ext'
14
15
  require_relative 'cotcube-helpers/string_ext'
15
16
  require_relative 'cotcube-helpers/datetime_ext'
17
+ require_relative 'cotcube-helpers/numeric_ext'
16
18
  require_relative 'cotcube-helpers/subpattern'
17
19
  require_relative 'cotcube-helpers/parallelize'
18
20
  require_relative 'cotcube-helpers/simple_output'
19
21
  require_relative 'cotcube-helpers/simple_series_stats'
22
+ require_relative 'cotcube-helpers/constants'
20
23
  require_relative 'cotcube-helpers/input'
21
24
  require_relative 'cotcube-helpers/reduce'
25
+ require_relative 'cotcube-helpers/symbols'
26
+ require_relative 'cotcube-helpers/init'
27
+ require_relative 'cotcube-helpers/get_id_set'
22
28
 
23
29
  module Cotcube
24
30
  module Helpers
25
31
  module_function :sub,
26
32
  :parallelize,
33
+ :config_path,
34
+ :config_prefix,
27
35
  :reduce,
28
36
  :simple_series_stats,
29
- :keystroke
37
+ :keystroke,
38
+ :symbols,
39
+ :micros,
40
+ :get_id_set,
41
+ :init
30
42
 
31
43
  # please not that module_functions of source provided in private files must be published there
32
44
  end
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+
3
+ export rubyenv=/home/pepe/.rvm/environments/default
4
+
5
+ . $rubyenv
6
+ cd /home/pepe/GEMS/${1}
7
+ export LC_ALL="en_US.utf8"
8
+
9
+ ruby ${2} ${3} ${4} ${5} ${6}
10
+
11
+
12
+ exit
13
+ for testing run
14
+ env - `cat /home/pepe/bin/cron_ruby_wrapper.sh | tail -n 6` /bin/bash
15
+
16
+ HOME=/home/pepe
17
+ LOGNAME=pepe
18
+ PATH=/usr/bin:/bin
19
+ LANG=en_US.UTF-8
20
+ SHELL=/bin/sh
21
+ PWD=/home/pepe
22
+
23
+
24
+
25
+
metadata CHANGED
@@ -1,43 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cotcube-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
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-04-18 00:00:00.000000000 Z
11
+ date: 2021-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '13'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
- version: '0'
54
+ version: '13'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rspec
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -82,10 +96,14 @@ files:
82
96
  - cotcube-helpers.gemspec
83
97
  - lib/cotcube-helpers.rb
84
98
  - lib/cotcube-helpers/array_ext.rb
99
+ - lib/cotcube-helpers/constants.rb
85
100
  - lib/cotcube-helpers/datetime_ext.rb
86
101
  - lib/cotcube-helpers/enum_ext.rb
102
+ - lib/cotcube-helpers/get_id_set.rb
87
103
  - lib/cotcube-helpers/hash_ext.rb
104
+ - lib/cotcube-helpers/init.rb
88
105
  - lib/cotcube-helpers/input.rb
106
+ - lib/cotcube-helpers/numeric_ext.rb
89
107
  - lib/cotcube-helpers/parallelize.rb
90
108
  - lib/cotcube-helpers/range_ext.rb
91
109
  - lib/cotcube-helpers/reduce.rb
@@ -96,6 +114,8 @@ files:
96
114
  - lib/cotcube-helpers/swig/date.rb
97
115
  - lib/cotcube-helpers/swig/fill_x.rb
98
116
  - lib/cotcube-helpers/swig/recognition.rb
117
+ - lib/cotcube-helpers/symbols.rb
118
+ - scripts/cron_ruby_wrapper.sh
99
119
  homepage: https://github.com/donkeybridge/cotcube-helpers
100
120
  licenses:
101
121
  - BSD-4-Clause