cotcube-helpers 0.1.7.4 → 0.1.9.2

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: a685d90173074f0ee3490602a9108cec0f8a8ff6e616fce2db1ef3566d0f2ef6
4
- data.tar.gz: b08e52e6e47a233658765b4fdb3aab72d649aefff91eabb46e8cbcef6542e84e
3
+ metadata.gz: 2bfb21e47e19a7dfd33125d42d4d049d8654fbf84e36edfe081a3878e751439e
4
+ data.tar.gz: 847d6eb7b98df85dc11aadc294147542071fdb4ff83d86faac3e0ef14d204d47
5
5
  SHA512:
6
- metadata.gz: b8ced4fffb8f219416f05fe6daf3e891499e788d58d1ca4ea233cfff18998972b3aa9f0be10abdda3081671e534d0346201cfa7f5442b0bc996b75a6f3b1208b
7
- data.tar.gz: 853ae393f9f3ba54321d82d2dba17e61fd6f85a4609029dee619ddcab10b2c2e5aa5dd6e7105f3f88e1e072b60034f7657a4cb53baed8188ddb67347326bce7a
6
+ metadata.gz: b2a0020f5c8277b6882dbe7a00e2c885c1e86eb56b22529236b086554b7b69b398afaa1b013bb02b8f4d23f7a7444000dac77e283c7c92ecaa8e2e255e44c6f9
7
+ data.tar.gz: b8638126b407e5c4e74a0866fa7497d1c3f29af6f143b94fbca775987de78f350df75b239fd68dcc339aaa4858254b5957c3b9a1e4a4aff40d8c3b487a84a5b4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## 0.1.9.2 (July 24, 2021)
2
+ - added missing module_functions
3
+ - init: minor fix
4
+ - datetime_ext: added warning comment / TODO, as switch from to daylight time will produce erroneous results
5
+ - constants: minor fix (typo)
6
+ - array_ext: added param to provide a default return value if result is an empty array
7
+
8
+ ## 0.1.9.1 (May 07, 2021)
9
+ - moved 'get_id_set' to Cotcube::Helpers
10
+ - minor fix to suppress some warning during build
11
+
12
+ ## 0.1.9 (May 07, 2021)
13
+ - added constants, init and symbols to helpers
14
+
15
+ ## 0.1.8 (April 18, 2021)
16
+ - datetime_ext: Date.cw provides a range of (Date..Date) representing the according calendar week
17
+
1
18
  ## 0.1.7.4 (March 13, 2021)
2
19
  - hotfix on 0.1.7.3
3
20
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7.4
1
+ 0.1.9.2
@@ -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
@@ -17,16 +17,25 @@ require_relative 'cotcube-helpers/subpattern'
17
17
  require_relative 'cotcube-helpers/parallelize'
18
18
  require_relative 'cotcube-helpers/simple_output'
19
19
  require_relative 'cotcube-helpers/simple_series_stats'
20
+ require_relative 'cotcube-helpers/constants'
20
21
  require_relative 'cotcube-helpers/input'
21
22
  require_relative 'cotcube-helpers/reduce'
23
+ require_relative 'cotcube-helpers/symbols'
24
+ require_relative 'cotcube-helpers/init'
25
+ require_relative 'cotcube-helpers/get_id_set'
22
26
 
23
27
  module Cotcube
24
28
  module Helpers
25
29
  module_function :sub,
26
30
  :parallelize,
31
+ :config_path,
32
+ :config_prefix,
27
33
  :reduce,
28
34
  :simple_series_stats,
29
- :keystroke
35
+ :keystroke,
36
+ :symbols,
37
+ :get_id_set,
38
+ :init
30
39
 
31
40
  # please not that module_functions of source provided in private files must be published there
32
41
  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,33 @@
1
+ #frozen_string_literal: true
2
+
3
+ module Cotcube
4
+ module Helpers
5
+ SYMBOL_EXAMPLES = [
6
+ { id: '13874U', symbol: 'ET', ticksize: 0.25, power: 1.25, months: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'S&P 500 MICRO' },
7
+ { id: '209747', symbol: 'NM', ticksize: 0.25, power: 0.5, monhts: 'HMUZ', bcf: 1.0, reports: 'LF', format: '8.2f', name: 'NASDAQ 100 MICRO' }
8
+ ].freeze
9
+
10
+ COLORS = %i[light_red light_yellow light_green red yellow green cyan magenta blue].freeze
11
+
12
+ MONTH_COLOURS = { 'F' => :cyan, 'G' => :green, 'H' => :light_green,
13
+ 'J' => :blue, 'K' => :yellow, 'M' => :light_yellow,
14
+ 'N' => :cyan, 'Q' => :magenta, 'U' => :light_magenta,
15
+ 'V' => :blue, 'X' => :red, 'Z' => :light_red }.freeze
16
+
17
+ MONTHS = { 'F' => 1, 'G' => 2, 'H' => 3,
18
+ 'J' => 4, 'K' => 5, 'M' => 6,
19
+ 'N' => 7, 'Q' => 8, 'U' => 9,
20
+ 'V' => 10, 'X' => 11, 'Z' => 12,
21
+ 1 => 'F', 2 => 'G', 3 => 'H',
22
+ 4 => 'J', 5 => 'K', 6 => 'M',
23
+ 7 => 'N', 8 => 'Q', 9 => 'U',
24
+ 10 => 'V', 11 => 'X', 12 => 'Z' }.freeze
25
+
26
+
27
+ CHICAGO = Time.find_zone('America/Chicago')
28
+
29
+ DATE_FMT = '%Y-%m-%d'
30
+
31
+ end
32
+ end
33
+
@@ -4,9 +4,42 @@
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
10
13
 
11
14
  alias to_sssm to_seconds_since_sunday_morning
12
15
  end
16
+
17
+ class Date
18
+
19
+ # creates a range of 2 dates, of the given calendar week, Monday to Sunday
20
+ def self.cw( week: , year: Date.today.year )
21
+ form = '%Y %W %w'
22
+ build_range = lambda {|w|
23
+ begin
24
+ ( DateTime.strptime("#{year} #{w} 1", form).to_date..
25
+ DateTime.strptime("#{year} #{w} 0", form).to_date)
26
+ rescue
27
+ # beyond Dec 31st #strptime must be called with cw:0 to keep it working
28
+ ( DateTime.strptime("#{year} #{w} 1", form).to_date..
29
+ DateTime.strptime("#{year+1} 0 0", form).to_date)
30
+ end
31
+ }
32
+ case week
33
+ when :current
34
+ build_range.call(Date.today.cweek)
35
+ when :last
36
+ wday = Date.today.wday
37
+ build_range.call((Date.today - (wday.zero? ? 7 : wday)).cweek)
38
+ when Integer
39
+ raise ArgumentError, "'#{week}' is not supported as calendar week, choose from (1..53)" if week <= 0 or week > 53
40
+ build_range.call(week)
41
+ else
42
+ raise ArgumentError, "'#{week}' is not a supported format for calendar week"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,43 @@
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)
7
+ contract = contract.to_s.upcase if contract.is_a? Symbol
8
+ id = id.to_s.upcase if id.is_a? Symbol
9
+ symbol = symbol.to_s.upcase if symbol.is_a? Symbol
10
+
11
+ if contract.is_a?(String) && (contract.length == 5)
12
+ c_symbol = contract[0..1]
13
+ if (not symbol.nil?) && (symbol != c_symbol)
14
+ raise ArgumentError,
15
+ "Mismatch between given symbol #{symbol} and contract #{contract}"
16
+ end
17
+
18
+ symbol = c_symbol
19
+ end
20
+
21
+ unless symbol.nil?
22
+ sym = symbols.select { |s| s[:symbol] == symbol.to_s.upcase }.first
23
+ if sym.nil? || sym[:id].nil?
24
+ raise ArgumentError,
25
+ "Could not find match in #{config[:symbols_file]} for given symbol #{symbol}"
26
+ end
27
+ raise ArgumentError, "Mismatching symbol #{symbol} and given id #{id}" if (not id.nil?) && (sym[:id] != id)
28
+
29
+ return sym
30
+ end
31
+ unless id.nil?
32
+ sym = symbols.select { |s| s[:id] == id.to_s }.first
33
+ if sym.nil? || sym[:id].nil?
34
+ raise ArgumentError,
35
+ "Could not find match in #{config[:symbols_file]} for given id #{id}"
36
+ end
37
+ return sym
38
+ end
39
+ raise ArgumentError, 'Need :id, :symbol or valid :contract '
40
+ end
41
+ end
42
+ end
43
+
@@ -0,0 +1,46 @@
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}.yml"
27
+ config_file = config_path + "/#{config_file_name}"
28
+
29
+ if File.exist?(config_file)
30
+ config = YAML.load(File.read config_file).transform_keys(&:to_sym)
31
+ else
32
+ config = {}
33
+ end
34
+
35
+ defaults = {
36
+ data_path: '/var/cotcube/' + name,
37
+ }
38
+
39
+ config = defaults.merge(config)
40
+ puts "CONFIG is '#{config}'" if debug
41
+
42
+ config
43
+ end
44
+ end
45
+ end
46
+
@@ -0,0 +1,22 @@
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)
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| all.select! { |x| x[:symbol] == symbol } unless symbol.nil? }
18
+ end
19
+ end
20
+
21
+ end
22
+ end
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.7.4
4
+ version: 0.1.9.2
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-03-13 00:00:00.000000000 Z
11
+ date: 2021-07-24 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,9 +96,12 @@ 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
89
106
  - lib/cotcube-helpers/parallelize.rb
90
107
  - lib/cotcube-helpers/range_ext.rb
@@ -96,6 +113,7 @@ files:
96
113
  - lib/cotcube-helpers/swig/date.rb
97
114
  - lib/cotcube-helpers/swig/fill_x.rb
98
115
  - lib/cotcube-helpers/swig/recognition.rb
116
+ - lib/cotcube-helpers/symbols.rb
99
117
  homepage: https://github.com/donkeybridge/cotcube-helpers
100
118
  licenses:
101
119
  - BSD-4-Clause