eost 0.1.3 → 0.1.8

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: 26150cc1f7bb4bab759957e79dd517d22c4fa78b970bf1644e9ab2640d68b049
4
- data.tar.gz: 87c983e443cc415679b3ecbce48f1f4df7f2fbe2a0b32293e9090942c7f24fcb
3
+ metadata.gz: 687e12616155b4451efb922e845a2453e7faf4c40d9256b4276aa694af26caf8
4
+ data.tar.gz: 6351df02bb6e4b34aec4fb644b53ddd7613b2541c2a4ba41134e00ba66572f0b
5
5
  SHA512:
6
- metadata.gz: 4a84238e1a425df8e86c651dd3bec214cb7c522b22efb1d7cae236ad44d684e8b68c5c06b21b6ae7103a3406c1acf475b60a3612ef2b08056ab831b289f1c906
7
- data.tar.gz: c4752ba045f65fee93b6af7ae268ab6c06f20f0b41efcb65b05e110f31f79f3f6ef602cc18d7c0aa6eddc3320435737178c76325eb50d23815cfd3e7d679217d
6
+ metadata.gz: ae002efa0379cf084560a1a6e835d9777291bb35c499748bdb1506fea26b2cb36524179d1919b068bfdc9534c79830072b3de1fa371b8a58098f94ccfd242223
7
+ data.tar.gz: 276a420aefee6ac02c4b6a624757a19971d14ef759f2b4887b608f787d0aa7c3d337ad6ec91bc8166696e888456bb03e5725d0b9c45e904a17066d0e54ba91b9
@@ -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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eost (0.1.3)
4
+ eost (0.1.8)
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.43.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.5)
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/eost.svg?branch=master)](https://travis-ci.com/hernanirvaz/eost)
1
+ # Eost [![Build Status](https://travis-ci.com/hernanirvaz/esot.svg?branch=master)](https://travis-ci.com/hernanirvaz/esot)
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).
@@ -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,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thor'
4
- require 'eost/version'
5
- require 'eost/bigquery'
6
- require 'eost/folhacalculo'
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
 
11
+ # @author Hernani Rodrigues Vaz
8
12
  module Eost
9
13
  ID = `whoami`.chomp
10
14
 
@@ -12,36 +16,43 @@ module Eost
12
16
 
13
17
  # CLI para carregar folhas calculo comuns no bigquery
14
18
  class CLI < Thor
15
- desc 'load', 'carrega dados da folha calculo no bigquery'
16
- option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
17
- desc: 'Onde procurar folhas calculo'
18
- option :x, banner: 'EXT', default: '.csv',
19
- desc: 'Extensao das folhas calculo'
20
- option :s, type: :boolean, default: false,
21
- desc: 'apaga linhas similares no bigquery'
22
- option :e, type: :boolean, default: false,
23
- desc: 'apaga linhas existentes no bigquery'
24
- # processa xlsx
25
- def load
26
- # opcoes apagar linhas
27
- d = options.select { |_, v| [true, false].include?(v) }
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
28
26
  Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
29
- Bigquery.new(f, d).processa
27
+ Bigquery.new(f, { e: options[:e], m: options[:m], i: true }).processa_csv
30
28
  end
31
29
  end
32
30
 
33
- desc 'mostra', 'mostra dados da folha calculo'
34
- option :d, banner: 'DIR', default: "/home/#{ID}/Downloads",
35
- desc: 'Onde procurar folhas calculo'
36
- option :x, banner: 'EXT', default: '.csv',
37
- desc: 'Extensao das folhas calculo'
38
- # mostra xlsx
39
- 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
40
36
  Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
41
- Bigquery.new(f).show
37
+ Bigquery.new(f).processa_csv
42
38
  end
43
39
  end
44
40
 
45
- 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
46
57
  end
47
58
  end
@@ -1,102 +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'
9
+ DI = '%Y-%m-%d %H:%M:%S'
8
10
 
9
- # folhas calculo comuns no bigquery
11
+ # (see Bigquery)
10
12
  class Bigquery
11
- # @return [Roo::Excelx] folha calculo a processar
12
- attr_reader :book
13
- # @return [Array] row folha calculo em processamento
14
- attr_reader :row
13
+ # @return [Roo::CSV] folha calculo a processar
14
+ attr_reader :folha
15
+ # @return [Hash<Symbol, Boolean>] opcoes trabalho com linhas
16
+ attr_reader :linha
17
+
15
18
  # @return [Google::Cloud::Bigquery] API bigquery
16
19
  attr_reader :api
20
+ # @return [Array] row folha calculo em processamento
21
+ attr_reader :row
17
22
  # @return [Google::Cloud::Bigquery::QueryJob] job bigquery
18
23
  attr_reader :job
19
- # @return (see sql_select)
20
- attr_reader :sql
21
- # @return [Integer] numero conta
22
- attr_reader :num
23
- # @return [Hash<String, Boolean>] opcoes apagar linhas
24
- attr_reader :apaga
25
-
26
- # permite processa folhas calculo comuns no bigquery
27
- #
24
+ # @return (see sql)
25
+ attr_reader :sqr
26
+
28
27
  # @param [String] csv folha calculo para processar
29
- # @param [Hash<String, Boolean>] apaga opcoes apagar linhas
30
- # @option apaga [Boolean] s apaga linhas similares sim/nao?
31
- # @option apaga [Boolean] e apaga linhas existentes sim/nao?
32
- # @return [Bigquery] acesso folha calculo & bigquery
33
- def initialize(csv = '', apaga = {})
34
- @book = Roo::CSV.new(csv) if csv.size.positive?
35
- @num = csv.match?(/card/i) ? 2 : 1
36
- @apaga = apaga
28
+ # @param [Hash<Symbol, Boolean>] ops opcoes trabalho com linhas
29
+ # @option ops [Boolean] :e (false) apaga linha igual?
30
+ # @option ops [Boolean] :m (false) apaga linhas existencia multipla?
31
+ # @option ops [Boolean] :i (false) insere linha nova?
32
+ # @return [Bigquery] acesso folhas calculo bloks.io & correspondente bigquery dataset
33
+ def initialize(csv = '', ops = { e: false, m: false, i: false })
34
+ @folha = Roo::CSV.new(csv) if csv.size.positive?
35
+ @linha = ops
36
+
37
37
  # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
38
38
  # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
39
39
  @api = Google::Cloud::Bigquery.new
40
40
  end
41
41
 
42
- # cria job bigquery & verifica execucao
43
- #
44
- # @param [String] sql para executar
45
- # @return [Boolean] job ok?
46
- def job_bigquery?(sql)
47
- @job = api.query_job(sql)
48
- @job.wait_until_done!
49
- puts @job.error['message'] if @job.failed?
50
- @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
+ )
51
51
  end
52
52
 
53
- # cria Data Manipulation Language (DML) job bigquery
54
- #
55
- # @param (see job_bigquery?)
56
- # @return [Integer] numero linhas afetadas
57
- def dml(sql)
58
- job_bigquery?(sql) ? 0 : job.num_dml_affected_rows
53
+ # @return [Carteiras] API eosscan - processar carteiras & transacoes
54
+ def carteiras
55
+ transacoes
59
56
  end
60
57
 
61
- # cria sql job bigquery com resultados
62
- #
63
- # @return [Array<Hash>] resultado sql
64
- def sql_select
65
- # se array.count > 1 => nao fazer nada
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))
67
61
  end
68
62
 
69
- # @return [String] parte sql para processamento linhas similares
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'
66
+ end
67
+
68
+ # @return [String] parte sql para processamento linhas existentes
70
69
  def sql_where
71
- "from ab.mv where nc=#{num}" \
72
- " and dl='#{row[0].strftime(DF)}'" \
73
- " and vl=#{row[3]}"
70
+ "from #{BD}.eos where blocknumber=#{row[0]}"
71
+ end
72
+
73
+ # @return [Integer] numero linhas inseridas
74
+ def eos_insert_csv
75
+ return 1 unless linha[:i]
76
+
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}"
74
86
  end
75
87
 
76
- # classifica linhas
77
- def sql_update
78
- puts 'LINHAS CLASSIFICADAS ' +
79
- dml('update ab.mv set mv.ct=tt.nct' \
80
- ' from (select * from ab.cl) as tt ' \
81
- 'where mv.dl=tt.dl and mv.dv=tt.dv' \
82
- ' and mv.ds=tt.ds and mv.vl=tt.vl').to_s
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"
83
97
  end
84
98
 
85
99
  # @return [Integer] numero linhas inseridas
86
- def sql_insert
87
- dml('insert ab.mv(dl,dv,ds,vl,nc,ano,mes,ct,tp) VALUES(' \
88
- "'#{row[0].strftime(DF)}','#{row[1].strftime(DF)}','#{row[2]}'," \
89
- "#{row[3]},#{num}" + sql_insert_calculado)
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)}"
114
+ end
115
+
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)})"
124
+ end
125
+
126
+ # @param [Hash] htx transacao normal
127
+ # @return [Hash] dados da acao
128
+ def act(htx)
129
+ htx['action_trace']['act']
130
+ end
131
+
132
+ # @param [Hash] htx transacao normal
133
+ # @return [Hash] dados da acao
134
+ def act_data(htx)
135
+ act(htx)['data']
90
136
  end
91
137
 
92
- # @return [String] campos calculados da linha bigquery
93
- def sql_insert_calculado
94
- ",#{row[1].year},#{row[1].month},null,'#{row[3].positive? ? 'c' : 'd'}')"
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?
95
147
  end
96
148
 
97
- # @return [Integer] numero linhas apagadas
98
- def sql_delete
99
- dml('delete ' + sql_where + " and ds='#{sql.first[:ds].strip}'")
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
100
164
  end
101
165
  end
102
166
  end