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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/eost.rb +3 -6
- data/lib/eost/bigquery.rb +18 -27
- data/lib/eost/folhacalculo.rb +22 -34
- data/lib/eost/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 835ae5c9c6dea5232face3c0299d55d457de19e7582c9e6df8b4d2b2069b4471
|
4
|
+
data.tar.gz: 03bf840348e46d196154e37a7511bd259628e5f1ca0cbad9911a0bfcd71247af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4070be5ed57ac7f0f55481788cf7d36c3e808af2e5d6e095855f8e2f0c6dbc0dce801f2924d82c06b1148e96073267a5f70f614e0de395511e4ba5ac731fdf94
|
7
|
+
data.tar.gz: 644b2d88915363242d30ada517347fe4c9b05bc1504c560c4c4128154c996ffbbd5eacf6eecaea53de1e1e09ab26cc695a7322b669b8bb0274dbbd9f1e55dec6
|
data/Gemfile.lock
CHANGED
data/lib/eost.rb
CHANGED
@@ -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
|
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,
|
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
|
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
|
data/lib/eost/bigquery.rb
CHANGED
@@ -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 [
|
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 [
|
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
|
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
|
88
|
-
|
89
|
-
|
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
|
93
|
-
def
|
94
|
-
"
|
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
|
90
|
+
dml('delete ' + sql_where)
|
100
91
|
end
|
101
92
|
end
|
102
93
|
end
|
data/lib/eost/folhacalculo.rb
CHANGED
@@ -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
|
-
|
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
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
48
|
+
# @param (see show_row)
|
43
49
|
# @return [String] linha folha calculo processada
|
44
50
|
def processa_row(has)
|
45
|
-
|
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
|
60
|
+
# @param [Hash] has da linha em processamento
|
56
61
|
# @return (see row_str)
|
57
62
|
def show_row(has)
|
58
|
-
|
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
|
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
|
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
|
data/lib/eost/version.rb
CHANGED