eost 0.1.3 → 0.1.4

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: 835ae5c9c6dea5232face3c0299d55d457de19e7582c9e6df8b4d2b2069b4471
4
+ data.tar.gz: 03bf840348e46d196154e37a7511bd259628e5f1ca0cbad9911a0bfcd71247af
5
5
  SHA512:
6
- metadata.gz: 4a84238e1a425df8e86c651dd3bec214cb7c522b22efb1d7cae236ad44d684e8b68c5c06b21b6ae7103a3406c1acf475b60a3612ef2b08056ab831b289f1c906
7
- data.tar.gz: c4752ba045f65fee93b6af7ae268ab6c06f20f0b41efcb65b05e110f31f79f3f6ef602cc18d7c0aa6eddc3320435737178c76325eb50d23815cfd3e7d679217d
6
+ metadata.gz: 4070be5ed57ac7f0f55481788cf7d36c3e808af2e5d6e095855f8e2f0c6dbc0dce801f2924d82c06b1148e96073267a5f70f614e0de395511e4ba5ac731fdf94
7
+ data.tar.gz: 644b2d88915363242d30ada517347fe4c9b05bc1504c560c4c4128154c996ffbbd5eacf6eecaea53de1e1e09ab26cc695a7322b669b8bb0274dbbd9f1e55dec6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eost (0.1.3)
4
+ eost (0.1.4)
5
5
  google-cloud-bigquery
6
6
  roo
7
7
  thor
@@ -17,16 +17,13 @@ module Eost
17
17
  desc: 'Onde procurar folhas calculo'
18
18
  option :x, banner: 'EXT', default: '.csv',
19
19
  desc: 'Extensao das folhas calculo'
20
- option :s, type: :boolean, default: false,
21
- desc: 'apaga linhas similares no bigquery'
22
20
  option :e, type: :boolean, default: false,
23
21
  desc: 'apaga linhas existentes no bigquery'
24
- # processa xlsx
22
+ # processa csv
25
23
  def load
26
24
  # opcoes apagar linhas
27
- d = options.select { |_, v| [true, false].include?(v) }
28
25
  Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
29
- Bigquery.new(f, d).processa
26
+ Bigquery.new(f, options[:e]).processa
30
27
  end
31
28
  end
32
29
 
@@ -35,7 +32,7 @@ module Eost
35
32
  desc: 'Onde procurar folhas calculo'
36
33
  option :x, banner: 'EXT', default: '.csv',
37
34
  desc: 'Extensao das folhas calculo'
38
- # mostra xlsx
35
+ # mostra csv
39
36
  def mostra
40
37
  Dir.glob("#{options[:d]}/*#{options[:x]}").sort.each do |f|
41
38
  Bigquery.new(f).show
@@ -5,6 +5,7 @@ require 'google/cloud/bigquery'
5
5
 
6
6
  module Eost
7
7
  DF = '%Y-%m-%d'
8
+ DI = '%Y-%m-%d %H:%M:%S'
8
9
 
9
10
  # folhas calculo comuns no bigquery
10
11
  class Bigquery
@@ -18,21 +19,16 @@ module Eost
18
19
  attr_reader :job
19
20
  # @return (see sql_select)
20
21
  attr_reader :sql
21
- # @return [Integer] numero conta
22
- attr_reader :num
23
- # @return [Hash<String, Boolean>] opcoes apagar linhas
22
+ # @return [Boolean] apaga linhas existentes sim/nao?
24
23
  attr_reader :apaga
25
24
 
26
25
  # permite processa folhas calculo comuns no bigquery
27
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?
28
+ # @param [Boolean] apaga linhas existentes sim/nao?
32
29
  # @return [Bigquery] acesso folha calculo & bigquery
33
- def initialize(csv = '', apaga = {})
30
+ def initialize(csv = '', apaga = false)
34
31
  @book = Roo::CSV.new(csv) if csv.size.positive?
35
- @num = csv.match?(/card/i) ? 2 : 1
36
32
  @apaga = apaga
37
33
  # usa env GOOGLE_APPLICATION_CREDENTIALS para obter credentials
38
34
  # @see https://cloud.google.com/bigquery/docs/authentication/getting-started
@@ -68,35 +64,30 @@ module Eost
68
64
 
69
65
  # @return [String] parte sql para processamento linhas similares
70
66
  def sql_where
71
- "from ab.mv where nc=#{num}" \
72
- " and dl='#{row[0].strftime(DF)}'" \
73
- " and vl=#{row[3]}"
74
- end
75
-
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
67
+ "from coins.eos where blocknumber=#{row[0]}"
83
68
  end
84
69
 
85
70
  # @return [Integer] numero linhas inseridas
86
71
  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)
72
+ dml('insert coins.eos(blocknumber,time,contract,' \
73
+ 'action,acfrom,acto,amount,symbol,memo,data,dias) VALUES(' +
74
+ sql_insert1 + sql_insert2)
75
+ end
76
+
77
+ # @return [String] campos insert da linha bigquery
78
+ def sql_insert1
79
+ "#{row[0]},'#{DateTime.parse(row[1]).strftime(DI)}','#{row[2]}',"
90
80
  end
91
81
 
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'}')"
82
+ # @return [String] campos insert da linha bigquery
83
+ def sql_insert2
84
+ "'#{row[3]}','#{row[4]}','#{row[5]}',#{row[6]}," \
85
+ "'#{row[7]}','#{row[8]}','#{row[9]}',0)"
95
86
  end
96
87
 
97
88
  # @return [Integer] numero linhas apagadas
98
89
  def sql_delete
99
- dml('delete ' + sql_where + " and ds='#{sql.first[:ds].strip}'")
90
+ dml('delete ' + sql_where)
100
91
  end
101
92
  end
102
93
  end
@@ -1,19 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eost
4
- HT = %w[block_num block_time contract action \
4
+ HT = %w[block_num block_time contract action
5
5
  from to amount symbol memo data].freeze
6
- RF = '%<v3>-50.50s %<v4>8.2f'
6
+ R1 = '%<v3>-12.12s %<v4>s %<v5>-12.12s %<v6>-12.12s'
7
+ R2 = '%<v7>10.5f %<v8>-10.10s'
7
8
 
8
9
  # folhas calculo comuns no bigquery
9
10
  class Bigquery
10
- # prepara linha folha calculo para processamento
11
- #
12
- # @param [Hash] has da linha em processamento
13
- def corrige_hash(has)
14
- @row = has.values
15
- @row[2] = row[2].strip
16
- @row[3] = -1 * row[3] if num > 1
11
+ # @return [String] linha folha calculo formatada
12
+ def row_str
13
+ "#{row[0]} #{DateTime.parse(row[1]).strftime(DF)} " + row_r1 + row_r2
14
+ end
15
+
16
+ # @return [String] linha folha calculo formatada
17
+ def row_r1
18
+ format(R1, v3: row[2], v4: row[3], v5: row[4], v6: row[5])
19
+ end
20
+
21
+ # @return [String] linha folha calculo formatada
22
+ def row_r2
23
+ format(R2, v7: row[6], v8: row[7])
17
24
  end
18
25
 
19
26
  # processa linhas folha calculo
@@ -24,7 +31,6 @@ module Eost
24
31
  n += 1
25
32
  puts n == 1 ? "\n" + book.info : processa_row(r)
26
33
  end
27
- sql_update
28
34
  end
29
35
 
30
36
  # mostra linhas folha calculo
@@ -39,41 +45,28 @@ module Eost
39
45
 
40
46
  # processa linha folha calculo para arquivo
41
47
  #
42
- # @param (see corrige_hash)
48
+ # @param (see show_row)
43
49
  # @return [String] linha folha calculo processada
44
50
  def processa_row(has)
45
- corrige_hash(has)
51
+ @row = has.values
46
52
  sql_select
47
53
  if rnaoexiste? then row_str + (sql_insert == 1 ? ' NOVA' : ' ERRO')
48
- elsif rsimila? then row_similar
49
54
  elsif rexiste? then row_existente
50
55
  end
51
56
  end
52
57
 
53
58
  # obtem linha folha calculo para apresentacao
54
59
  #
55
- # @param (see corrige_hash)
60
+ # @param [Hash] has da linha em processamento
56
61
  # @return (see row_str)
57
62
  def show_row(has)
58
- corrige_hash(has)
63
+ @row = has.values
59
64
  row_str
60
65
  end
61
66
 
62
- # @return [String] linha folha calculo formatada
63
- def row_str
64
- "#{row[0].strftime(DF)} #{row[1].strftime(DF)} " \
65
- "#{format(RF, v3: row[2], v4: row[3])}"
66
- end
67
-
68
- # @return [String] linha folha calculo similar
69
- def row_similar
70
- d = apaga['s'] ? sql_delete : 0
71
- row_str + " SIMILAR#{d.zero? ? ' ' : ' APAGADA '}#{sql.first[:ds].strip}"
72
- end
73
-
74
67
  # @return [String] linha folha calculo existente
75
68
  def row_existente
76
- d = apaga['e'] ? sql_delete : 0
69
+ d = apaga ? sql_delete : 0
77
70
  row_str + " EXISTENTE#{d.zero? ? '' : ' APAGADA'}"
78
71
  end
79
72
 
@@ -84,12 +77,7 @@ module Eost
84
77
 
85
78
  # @return [Boolean] linha folha calculo existe no bigquery?
86
79
  def rexiste?
87
- sql.count == 1 && sql.first[:ds].strip == row[2]
88
- end
89
-
90
- # @return [Boolean] linha folha calculo parecida no bigquery?
91
- def rsimila?
92
- sql.count == 1 && sql.first[:ds].strip != row[2]
80
+ sql.count == 1
93
81
  end
94
82
  end
95
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eost
4
- VERSION = '0.1.3'
4
+ VERSION = '0.1.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hernâni Rodrigues Vaz