eost 0.1.6 → 0.1.12

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: b04e7a8105407a676d58e6175f5823ed7338b56cf0ea5898b9d15fbd599413e3
4
- data.tar.gz: 99a8578ca355c1f14c2c022c704f1e0006775475f334d34364487d638399c96d
3
+ metadata.gz: be7d70b618fddb95b02c9dd5ff455d7526b36567bba0e151c0ce4afeb440b027
4
+ data.tar.gz: 3873e64666eff51a35c411015f4ce80f93a2d5fe6ddbda038dcb540ef37a61cc
5
5
  SHA512:
6
- metadata.gz: 6f0320676e378a2f14ad917e820cad76bc8ff8d79d9ca2db2e47ce371704a090c03090b8295bbe98759f524ad073c77068399564919f372cbb87b5e96f896b77
7
- data.tar.gz: a7f451fbaff9f14db7f1a1dcd3f7d3cba9beb4e55a3f201679a2433ff5906ccd67633ad652bff2fcab57e67835ec33579413a5e8f5ac52eaf5ebaa0bf2e4c37f
6
+ metadata.gz: 7a7cae34b7aa87c663600f4beab3e0dc6ce216fc65d4f6e5c5ac3881438b6c241395764c393b3b951bf21505ca70bc8e4b651a7d5837430dd4f6b014a76ed181
7
+ data.tar.gz: f761ddf3ea9d771dbdb2d756a20c3d37fd5b3a4d86fcfbff3d9581d4ae82bcff7c2ffd1d708424b9984c8a833e4e6c63aa19b1e2c266538e721f17a1e4240d7c
@@ -0,0 +1,12 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ EnabledByDefault: true
4
+
5
+ Style/Copyright:
6
+ Enabled: false
7
+
8
+ Lint/ConstantResolution:
9
+ Enabled: false
10
+
11
+ Style/ConstantVisibility:
12
+ Enabled: false
@@ -2,4 +2,4 @@
2
2
  sudo: false
3
3
  language: ruby
4
4
  rvm:
5
- - 2.6.3
5
+ - 2.7.0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eost (0.1.6)
4
+ eost (0.1.12)
5
5
  google-cloud-bigquery
6
6
  roo
7
7
  thor
@@ -12,12 +12,12 @@ GEM
12
12
  specs:
13
13
  addressable (2.7.0)
14
14
  public_suffix (>= 2.0.2, < 5.0)
15
- concurrent-ruby (1.1.6)
16
- declarative (0.0.10)
15
+ concurrent-ruby (1.1.7)
16
+ declarative (0.0.20)
17
17
  declarative-option (0.1.0)
18
18
  faraday (1.0.1)
19
19
  multipart-post (>= 1.2, < 3)
20
- google-api-client (0.38.0)
20
+ google-api-client (0.44.0)
21
21
  addressable (~> 2.5, >= 2.5.1)
22
22
  googleauth (~> 0.9)
23
23
  httpclient (>= 2.8.1, < 3.0)
@@ -25,7 +25,7 @@ GEM
25
25
  representable (~> 3.0)
26
26
  retriable (>= 2.0, < 4.0)
27
27
  signet (~> 0.12)
28
- google-cloud-bigquery (1.21.0)
28
+ google-cloud-bigquery (1.21.2)
29
29
  concurrent-ruby (~> 1.0)
30
30
  google-api-client (~> 0.33)
31
31
  google-cloud-core (~> 1.2)
@@ -34,10 +34,10 @@ GEM
34
34
  google-cloud-core (1.5.0)
35
35
  google-cloud-env (~> 1.0)
36
36
  google-cloud-errors (~> 1.0)
37
- google-cloud-env (1.3.1)
37
+ google-cloud-env (1.3.3)
38
38
  faraday (>= 0.17.3, < 2.0)
39
- google-cloud-errors (1.0.0)
40
- googleauth (0.12.0)
39
+ google-cloud-errors (1.0.1)
40
+ googleauth (0.13.1)
41
41
  faraday (>= 0.17.3, < 2.0)
42
42
  jwt (>= 1.4, < 3.0)
43
43
  memoist (~> 0.16)
@@ -45,16 +45,16 @@ GEM
45
45
  os (>= 0.9, < 2.0)
46
46
  signet (~> 0.14)
47
47
  httpclient (2.8.3)
48
- jwt (2.2.1)
48
+ jwt (2.2.2)
49
49
  memoist (0.16.2)
50
50
  mini_mime (1.0.2)
51
51
  mini_portile2 (2.4.0)
52
- multi_json (1.14.1)
52
+ multi_json (1.15.0)
53
53
  multipart-post (2.1.1)
54
- nokogiri (1.10.9)
54
+ nokogiri (1.10.10)
55
55
  mini_portile2 (~> 2.4.0)
56
- os (1.1.0)
57
- public_suffix (4.0.4)
56
+ os (1.1.1)
57
+ public_suffix (4.0.6)
58
58
  rake (12.3.3)
59
59
  representable (3.0.4)
60
60
  declarative (< 0.1.0)
@@ -72,7 +72,7 @@ GEM
72
72
  multi_json (~> 1.10)
73
73
  thor (1.0.1)
74
74
  uber (0.1.0)
75
- yard (0.9.24)
75
+ yard (0.9.25)
76
76
 
77
77
  PLATFORMS
78
78
  ruby
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Eost [![Build Status](https://travis-ci.com/hernanirvaz/esot.svg?branch=master)](https://travis-ci.com/hernanirvaz/esot)
1
+ # Eost [![Build Status](https://travis-ci.com/hernanirvaz/eost.svg?branch=master)](https://travis-ci.com/hernanirvaz/eost)
2
2
 
3
3
  Arquiva eos-transactions.csv no bigquery. Pode apagar movimentos existentes ja no bigquery.
4
4
 
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
32
 
33
33
  ## Contributing
34
34
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eost. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/eost/blob/master/CODE_OF_CONDUCT.md).
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hernanirvaz/eost. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hernanirvaz/eost/blob/master/CODE_OF_CONDUCT.md).
36
36
 
37
37
 
38
38
  ## License
@@ -41,4 +41,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
41
41
 
42
42
  ## Code of Conduct
43
43
 
44
- Everyone interacting in the Eost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/eost/blob/master/CODE_OF_CONDUCT.md).
44
+ Everyone interacting in the Eost project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hernanirvaz/eost/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
- require "bundler/gem_tasks"
2
- task :default => :build
1
+ # frozen_string_literal: true
2
+
3
+ require('bundler/gem_tasks')
4
+ task(default: :build)
@@ -11,8 +11,7 @@ Gem::Specification.new do |spec|
11
11
  spec.license = 'MIT'
12
12
 
13
13
  spec.summary = 'Arquiva eos-transactions.csv no bigquery.'
14
- spec.description = spec.summary +
15
- ' Pode apagar movimentos existentes ja no bigquery.'
14
+ spec.description = spec.summary + ' Pode apagar movimentos existentes ja no bigquery.'
16
15
 
17
16
  spec.metadata['homepage_uri'] = spec.homepage
18
17
  spec.metadata['yard.run'] = 'yard'
@@ -22,8 +21,7 @@ Gem::Specification.new do |spec|
22
21
  # Specify which files should be added to the gem when it is released.
23
22
  # The `git ls-files -z` loads files in RubyGem that have been added into git.
24
23
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
- `git ls-files -z`.split("\x0")
26
- .reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
25
  end
28
26
  spec.bindir = 'exe'
29
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'eost/bigquery'
5
- require 'eost/folhacalculo'
6
- require 'eost/version'
3
+ require('thor')
4
+ require('eost/bigquery')
5
+ require('eost/carteiras')
6
+ require('eost/eosscan')
7
+ require('eost/folhacalculo')
8
+ require('eost/formatar')
9
+ require('eost/version')
7
10
 
8
11
  # @author Hernani Rodrigues Vaz
9
12
  module Eost
@@ -13,34 +16,43 @@ module Eost
13
16
 
14
17
  # CLI para carregar folhas calculo comuns no bigquery
15
18
  class CLI < Thor
16
- desc 'load', 'carrega dados da folha calculo no bigquery'
17
- option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
18
- desc: 'Onde procurar folhas calculo'
19
- option :x, banner: 'EXT', default: '.csv',
20
- desc: 'Extensao das folhas calculo'
21
- option :e, type: :boolean, default: false,
22
- desc: 'apaga linha igual no bigquery'
23
- option :m, type: :boolean, default: false,
24
- desc: 'apaga linhas existencia multipla no bigquery'
25
- # processa csv
26
- def load
19
+ desc 'workfc', 'carrega/apaga dados da folha calculo'
20
+ option :d, banner: 'DIR', default: "/home/#{ID}/Downloads", desc: 'Onde procurar folhas calculo'
21
+ option :x, banner: 'EXT', default: '.csv', desc: 'Extensao das folhas calculo'
22
+ option :e, type: :boolean, default: false, desc: 'apaga linha igual'
23
+ option :m, type: :boolean, default: false, desc: 'apaga linhas existencia multipla'
24
+ # processa folha calculo
25
+ def workfc
27
26
  Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
28
- Bigquery.new(f, { e: options[:e], m: options[:m], i: true }).processa
27
+ Bigquery.new(f, { e: options[:e], m: options[:m], i: true }).processa_csv
29
28
  end
30
29
  end
31
30
 
32
- desc 'mostra', 'mostra dados da folha calculo'
33
- option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
34
- desc: 'Onde procurar folhas calculo'
35
- option :x, banner: 'EXT', default: '.csv',
36
- desc: 'Extensao das folhas calculo'
37
- # mostra csv
38
- def mostra
31
+ desc 'showfc', 'mostra dados da folha calculo'
32
+ option :d, banner: 'DIR', default: "/home/#{ID}/Downloads", desc: 'Onde procurar folhas calculo'
33
+ option :x, banner: 'EXT', default: '.csv', desc: 'Extensao das folhas calculo'
34
+ # show folha calculo
35
+ def showfc
39
36
  Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
40
- Bigquery.new(f).processa
37
+ Bigquery.new(f).processa_csv
41
38
  end
42
39
  end
43
40
 
44
- default_task :mostra
41
+ desc 'work', 'carrega transacoes novas no bigquery'
42
+ option :h, type: :hash, default: {}, desc: 'configuracao ajuste reposicionamento temporal'
43
+ # carrega transacoes novas no bigquery
44
+ def work
45
+ Bigquery.new('', options).processa
46
+ end
47
+
48
+ desc 'show', 'mostra reumo carteiras & transacoes'
49
+ option :v, type: :boolean, default: false, desc: 'mostra transacoes'
50
+ option :t, type: :boolean, default: false, desc: 'mostra transacoes todas ou somente novas'
51
+ # mostra reumo carteiras & transacoes
52
+ def show
53
+ Bigquery.new('', options).carteiras.mostra_resumo
54
+ end
55
+
56
+ default_task :show
45
57
  end
46
58
  end
@@ -1,100 +1,166 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'roo'
4
- require 'google/cloud/bigquery'
3
+ require('roo')
4
+ require('google/cloud/bigquery')
5
5
 
6
6
  module Eost
7
+ BD = 'hernanirvaz.coins'
7
8
  DF = '%Y-%m-%d'
8
9
  DI = '%Y-%m-%d %H:%M:%S'
9
10
 
10
11
  # (see Bigquery)
11
12
  class Bigquery
12
- # @return [Google::Cloud::Bigquery] API bigquery
13
- attr_reader :apibq
14
13
  # @return [Roo::CSV] folha calculo a processar
15
14
  attr_reader :folha
16
15
  # @return [Hash<Symbol, Boolean>] opcoes trabalho com linhas
17
16
  attr_reader :linha
18
17
 
18
+ # @return [Google::Cloud::Bigquery] API bigquery
19
+ attr_reader :api
19
20
  # @return [Array] row folha calculo em processamento
20
21
  attr_reader :row
21
22
  # @return [Google::Cloud::Bigquery::QueryJob] job bigquery
22
23
  attr_reader :job
23
- # @return (see sql_select)
24
- attr_reader :sql
24
+ # @return (see sql)
25
+ attr_reader :sqr
25
26
 
26
27
  # @param [String] csv folha calculo para processar
27
28
  # @param [Hash<Symbol, Boolean>] ops opcoes trabalho com linhas
28
29
  # @option ops [Boolean] :e (false) apaga linha igual?
29
30
  # @option ops [Boolean] :m (false) apaga linhas existencia multipla?
30
31
  # @option ops [Boolean] :i (false) insere linha nova?
31
- # @return [Bigquery] acesso folhas calculo bloks.io
32
- # & correspondente bigquery dataset
32
+ # @return [Bigquery] acesso folhas calculo bloks.io & correspondente bigquery dataset
33
33
  def initialize(csv = '', ops = { e: false, m: false, i: false })
34
- # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
35
- # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
36
- @apibq = Google::Cloud::Bigquery.new
37
34
  @folha = Roo::CSV.new(csv) if csv.size.positive?
38
35
  @linha = ops
36
+
37
+ # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
38
+ # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
39
+ @api = Google::Cloud::Bigquery.new
39
40
  end
40
41
 
41
- # cria job bigquery & verifica execucao
42
- #
43
- # @param [String] sql a executar
44
- # @return [Boolean] job ok?
45
- def job_bigquery?(sql)
46
- @job = apibq.query_job(sql)
47
- @job.wait_until_done!
48
- puts @job.error['message'] if @job.failed?
49
- @job.failed?
42
+ # @return [Carteiras] API eosscan - processar transacoes
43
+ def transacoes
44
+ @transacoes ||= Carteiras.new(
45
+ {
46
+ wb: sql("select * from #{BD}.walletEos order by 1").map { |e| { ax: e[:weos], sl: e[:eos].to_d } },
47
+ nt: sql("select blocknumber,iax from #{BD}.eostx order by 1")
48
+ },
49
+ linha
50
+ )
50
51
  end
51
52
 
52
- # cria Data Manipulation Language (DML) job bigquery
53
- #
54
- # @param (see job_bigquery?)
55
- # @return [Integer] numero linhas afetadas
56
- def dml(sql)
57
- job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
53
+ # @return [Carteiras] API eosscan - processar carteiras & transacoes
54
+ def carteiras
55
+ transacoes
58
56
  end
59
57
 
60
- # pesquisa existencia linha folha calculo no bigquery
61
- #
62
- # @return [Google::Cloud::Bigquery::Data] resultado do sql num array<hash>
63
- def sql_select
64
- # array.count = 0 ==> pode carregar esta linha
65
- # array.count >= 1 ==> nao carregar esta linha
66
- @sql = job_bigquery?('select * ' + sql_where) ? [{}, {}] : job.data
58
+ # insere transacoes novas na tabela eos
59
+ def processa
60
+ puts(format("%<n>2i LINHAS INSERIDAS #{BD}.eos", n: transacoes.novas.count.positive? ? eos_insert_api : 0))
61
+ end
62
+
63
+ # @return [String] campos da tabela eos no bigquery
64
+ def eos_fields
65
+ 'blocknumber,time,contract,action,acfrom,acto,amount,symbol,memo,data,dias'
67
66
  end
68
67
 
69
68
  # @return [String] parte sql para processamento linhas existentes
70
69
  def sql_where
71
- "from hernanirvaz.coins.eos where blocknumber=#{row[0]}"
70
+ "from #{BD}.eos where blocknumber=#{row[0]}"
72
71
  end
73
72
 
74
73
  # @return [Integer] numero linhas inseridas
75
- def sql_insert
74
+ def eos_insert_csv
76
75
  return 1 unless linha[:i]
77
76
 
78
- dml('insert hernanirvaz.coins.eos(blocknumber,time,contract,' \
79
- 'action,acfrom,acto,amount,symbol,memo,data,dias) VALUES(' +
80
- str_insert1)
77
+ dml("INSERT #{BD}.eos(#{eos_fields}) VALUES(#{eos_csv_val1})")
78
+ end
79
+
80
+ # @return [String] valores formatados para insert eos (parte1)
81
+ def eos_csv_val1
82
+ "#{row[0]}," \
83
+ "'#{Time.parse(row[1]).strftime(DI)}'," \
84
+ "'#{row[2]}'," \
85
+ "#{eos_csv_val2}"
86
+ end
87
+
88
+ # @return [String] valores formatados para insert eos (parte2)
89
+ def eos_csv_val2
90
+ "'#{row[3]}'," \
91
+ "'#{row[4]}'," \
92
+ "'#{row[5]}'," \
93
+ "#{Float(row[6])}," \
94
+ "'#{row[7]}'," \
95
+ "'#{row[8]}'," \
96
+ "'#{row[9]}',0"
97
+ end
98
+
99
+ # @return [Integer] numero linhas inseridas
100
+ def eos_insert_api
101
+ dml("INSERT #{BD}.eos(#{eos_fields}) VALUES#{transacoes.novas.map { |e| eos_api_val1(e) }.join(',')}")
102
+ end
103
+
104
+ # @param [Hash] htx transacao ligadas a uma carteira - sem elementos irrelevantes
105
+ # @return [String] valores formatados para insert eos (parte1)
106
+ def eos_api_val1(htx)
107
+ "(#{Integer(htx['block_num'])}," \
108
+ "DATETIME(TIMESTAMP('#{htx['block_time']}'))," \
109
+ "'#{act(htx)['account']}'," \
110
+ "'#{act(htx)['name']}'," \
111
+ "'#{act_data(htx)['from']}'," \
112
+ "'#{act_data(htx)['to']}'," \
113
+ "#{eos_api_val2(htx)}"
81
114
  end
82
115
 
83
- # @return [String] campos insert da linha bigquery
84
- def str_insert1
85
- "#{row[0]},'#{DateTime.parse(row[1]).strftime(DI)}','#{row[2]}'," +
86
- str_insert2
116
+ # @param [Hash] htx transacao ligadas a uma carteira - sem elementos irrelevantes
117
+ # @return [String] valores formatados para insert eos (parte2)
118
+ def eos_api_val2(htx)
119
+ "#{act_data(htx)['quantity'].to_d}," \
120
+ "'#{act_data(htx)['quantity'][/[[:upper:]]+/]}'," \
121
+ "'#{act_data(htx)['memo']}'," \
122
+ "'#{act_data(htx)}'," \
123
+ "#{Integer(linha[:h][String(htx['block_num'])] || 0)})"
87
124
  end
88
125
 
89
- # @return [String] campos insert da linha bigquery
90
- def str_insert2
91
- "'#{row[3]}','#{row[4]}','#{row[5]}',#{row[6].to_f}," \
92
- "'#{row[7]}','#{row[8]}','#{row[9]}',0)"
126
+ # @param [Hash] htx transacao normal
127
+ # @return [Hash] dados da acao
128
+ def act(htx)
129
+ htx['action_trace']['act']
93
130
  end
94
131
 
95
- # @return [Integer] numero linhas apagadas
96
- def sql_delete
97
- dml('delete ' + sql_where)
132
+ # @param [Hash] htx transacao normal
133
+ # @return [Hash] dados da acao
134
+ def act_data(htx)
135
+ act(htx)['data']
136
+ end
137
+
138
+ # cria job bigquery & verifica execucao
139
+ #
140
+ # @param cmd (see sql)
141
+ # @return [Boolean] job ok?
142
+ def job?(cmd)
143
+ @job = api.query_job(cmd)
144
+ @job.wait_until_done!
145
+ puts(@job.error['message']) if @job.failed?
146
+ @job.failed?
147
+ end
148
+
149
+ # cria Structured Query Language (SQL) job bigquery
150
+ #
151
+ # @param [String] cmd comando SQL a executar
152
+ # @param [Array<Hash>] red resultado quando SQL tem erro
153
+ # @return [Google::Cloud::Bigquery::Data] resultado do SQL
154
+ def sql(cmd, red = [])
155
+ @sqr = job?(cmd) ? red : job.data
156
+ end
157
+
158
+ # cria Data Manipulation Language (DML) job bigquery
159
+ #
160
+ # @param cmd (see sql)
161
+ # @return [Integer] numero linhas afetadas
162
+ def dml(cmd)
163
+ job?(cmd) ? 0 : job.num_dml_affected_rows
98
164
  end
99
165
  end
100
166
  end