abank 0.7.2 → 0.7.3
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 +3 -3
- data/lib/abank/big.rb +122 -0
- data/lib/abank/version.rb +1 -1
- data/lib/abank.rb +61 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e73d10cac74d20be439fdf8439853e31cfe952a9bdc8af90c9c2466c990b0b58
|
4
|
+
data.tar.gz: f7ba43125296cd98b4ef0d1c91ac9c292d5967fb2c022ad515e479a5cd495af4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23c72b6f7df54b2b6e1226ae2598d69e8302f55a6b6f874bb4d3815a97412a8023d933b2c67506224ee4a36f05e4521e926c1bb43a90fd8c80682f2ca97fd5d0
|
7
|
+
data.tar.gz: f71a7f5a3e0ff2f407d30cceca0816704591e5000828657617d0584eee54fcb435732e1cce5ce645c6a1e90586e5fb411e59f0531d406956a561667907827bae
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
abank (0.7.
|
4
|
+
abank (0.7.3)
|
5
5
|
google-cloud-bigquery
|
6
6
|
roo
|
7
7
|
thor
|
@@ -54,7 +54,7 @@ GEM
|
|
54
54
|
logger
|
55
55
|
faraday-net_http (3.4.0)
|
56
56
|
net-http (>= 0.5.0)
|
57
|
-
google-apis-bigquery_v2 (0.
|
57
|
+
google-apis-bigquery_v2 (0.85.0)
|
58
58
|
google-apis-core (>= 0.15.0, < 2.a)
|
59
59
|
google-apis-core (0.16.0)
|
60
60
|
addressable (~> 2.5, >= 2.5.1)
|
@@ -154,7 +154,7 @@ GEM
|
|
154
154
|
rubocop-ast (>= 1.38.0, < 2.0)
|
155
155
|
ruby-progressbar (~> 1.7)
|
156
156
|
unicode-display_width (>= 2.4.0, < 4.0)
|
157
|
-
rubocop-ast (1.
|
157
|
+
rubocop-ast (1.39.0)
|
158
158
|
parser (>= 3.3.1.0)
|
159
159
|
rubocop-rake (0.7.1)
|
160
160
|
lint_roller (~> 1.1)
|
data/lib/abank/big.rb
CHANGED
@@ -55,6 +55,89 @@ module Abank
|
|
55
55
|
self
|
56
56
|
end
|
57
57
|
|
58
|
+
# mostra dados movimentos classificacao
|
59
|
+
def mc_show
|
60
|
+
if opcao[:c].to_s.empty?
|
61
|
+
puts("\ndados movimentos NAO classificados")
|
62
|
+
cp1 = sql("select distinct p1 from #{BD}.cc where p1 is not null").map { |p| p[:p1] }
|
63
|
+
cp2 = sql("select distinct p2 from #{BD}.cc where p2 is not null").map { |p| p[:p2] }
|
64
|
+
sql("select * from #{BD}.gpl where ct is null order by 1 desc limit @lm", lm: opcao[:n])
|
65
|
+
else
|
66
|
+
puts("\ndados movimentos JA classificados por:")
|
67
|
+
cc_show
|
68
|
+
cp1 = []
|
69
|
+
cp2 = []
|
70
|
+
sql("select * from #{BD}.gpl where ct=@ct order by 1 desc limit @lm", lm: opcao[:n], ct: opcao[:c])
|
71
|
+
end
|
72
|
+
bqres.reject! do |h|
|
73
|
+
h[:p1s] = h[:p1s] - cp1
|
74
|
+
h[:p2s] = h[:p2s] - cp2 - h[:p1s] - cp1
|
75
|
+
h[:p1s].empty? && h[:p2s].empty?
|
76
|
+
end
|
77
|
+
return if bqres.empty?
|
78
|
+
|
79
|
+
puts(' data t1 valor palavras p1s/p2s')
|
80
|
+
bqres.each { |l| puts(format('%<dl>10s %<t1>10s %<vl>8.2f %<p1>s%<p2>s', dl: l[:dl].strftime(DF), t1: l[:p1], vl: l[:vl], p1: fpls(l[:p1s], 'p1 '), p2: fpls(l[:p2s], '; p2 '))) }
|
81
|
+
end
|
82
|
+
|
83
|
+
# mostra classificador
|
84
|
+
def cc_show
|
85
|
+
if opcao[:c].to_s.empty? && opcao[:p1].empty? && opcao[:p2].empty?
|
86
|
+
sql("SELECT * FROM #{BD}.cc")
|
87
|
+
elsif opcao[:c].to_s.empty? && opcao[:p1].empty?
|
88
|
+
sql("select * from #{BD}.cc WHERE p2 in unnest(@p2s)", p2s: opcao[:p2])
|
89
|
+
elsif opcao[:c].to_s.empty? && opcao[:p2].empty?
|
90
|
+
sql("select * from #{BD}.cc WHERE p1 in unnest(@p1s)", p1s: opcao[:p1])
|
91
|
+
elsif opcao[:p1].empty? && opcao[:p2].empty?
|
92
|
+
sql("select * from #{BD}.cc WHERE ct=@ct", ct: opcao[:c])
|
93
|
+
elsif opcao[:p1].empty?
|
94
|
+
sql("select * from #{BD}.cc WHERE ct=@ct and p2 in unnest(@p2s)", ct: opcao[:c], p2s: opcao[:p2])
|
95
|
+
elsif opcao[:p2].empty?
|
96
|
+
sql("select * from #{BD}.cc WHERE ct=@ct and p1 in unnest(@p1s)", ct: opcao[:c], p1s: opcao[:p1])
|
97
|
+
else
|
98
|
+
sql("select * from #{BD}.cc WHERE ct=@ct and p1 in unnest(@p1s) and p2 in unnest(@p2s)", ct: opcao[:c], p1s: opcao[:p1], p2s: opcao[:p2])
|
99
|
+
end
|
100
|
+
if bqres.empty?
|
101
|
+
puts('CLASSIFICADOR NAO EXISTE')
|
102
|
+
else
|
103
|
+
@bqres = bqres.group_by { |c| c[:ct] }.map { |k, v| {ct: k, p1s: fplo(v)} }
|
104
|
+
puts(' id palavras p1s/t1s/p2s ')
|
105
|
+
bqres.sort_by { |i| i[:ct] }.each do |l|
|
106
|
+
puts(format('%<ct>8s p %<p1>s', ct: l[:ct], p1: fpls(l[:p1s])))
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# apaga classificador
|
112
|
+
# @return [Big] acesso a base dados abank no bigquery
|
113
|
+
def cc_apaga
|
114
|
+
cc_show
|
115
|
+
return self if bqres.empty?
|
116
|
+
|
117
|
+
if opcao[:p1].empty? && opcao[:p2].empty?
|
118
|
+
dml("delete from #{BD}.cc WHERE ct=@ct", ct: opcao[:c])
|
119
|
+
elsif opcao[:p1].empty?
|
120
|
+
dml("delete from #{BD}.cc WHERE ct=@ct and p2 IN UNNEST(@p2s)", ct: opcao[:c], p2s: opcao[:p2])
|
121
|
+
else
|
122
|
+
dml("delete from #{BD}.cc WHERE ct=@ct and p1 IN UNNEST(@p1s)", ct: opcao[:c], p1s: opcao[:p1])
|
123
|
+
end
|
124
|
+
puts("CLASSIFICADORES APAGADOS #{bqnrs}")
|
125
|
+
return self unless opcao[:t]
|
126
|
+
|
127
|
+
dml("update #{BD}.mv set ct=null,p1=null WHERE ct=@ct", ct: opcao[:c])
|
128
|
+
puts("MOVIMENTOS DES-CLASSIFICADOS #{bqnrs}")
|
129
|
+
self
|
130
|
+
end
|
131
|
+
|
132
|
+
# cria classificador
|
133
|
+
# @return [Big] acesso a base dados abank no bigquery
|
134
|
+
def cc_cria
|
135
|
+
vls = opcao[:p1].map.with_index { |p1, i| "('#{opcao[:c]}',#{fpli(p1)},#{fpli(opcao[:p2][i])},#{fpli(opcao[:t1][i])})" }
|
136
|
+
dml("insert #{BD}.cc values#{vls.join(',')}")
|
137
|
+
puts("CLASSIFICADORES CRIADOS #{bqnrs}")
|
138
|
+
self
|
139
|
+
end
|
140
|
+
|
58
141
|
# classifica movimentos no bigquery
|
59
142
|
# @return [Big] acesso a base dados abank no bigquery
|
60
143
|
def mv_classifica
|
@@ -64,6 +147,24 @@ module Abank
|
|
64
147
|
self
|
65
148
|
end
|
66
149
|
|
150
|
+
# mostra contrato arrendamento
|
151
|
+
def ct_mostra
|
152
|
+
sql("SELECT * FROM #{BD}.ca WHERE ct=@ct", ct: opcao[:c])
|
153
|
+
if bqres.empty?
|
154
|
+
puts('CONTRATO NAO EXISTE')
|
155
|
+
return
|
156
|
+
end
|
157
|
+
|
158
|
+
@bqres = bqres.first
|
159
|
+
puts(' crontrato data renda')
|
160
|
+
puts(format('%<ct>10s %<dc>10s %<vr>8.2f', ct: bqres[:ct], dc: bqres[:dc].strftime(DF), vr: bqres[:vr]))
|
161
|
+
return unless opcao[:t]
|
162
|
+
|
163
|
+
sql("SELECT * FROM #{BD}.gca WHERE ct=@ct order by ano desc,cnt desc", ct: opcao[:c])
|
164
|
+
puts("\n data ano cnt dias")
|
165
|
+
bqres.each { |l| puts(format('%<dl>10s %<a>4d %<c>3d %<d>4d', dl: l[:dl].strftime(DF), a: l[:ano], c: l[:cnt], d: l[:dias])) }
|
166
|
+
end
|
167
|
+
|
67
168
|
# cria contrato arrendamento no bigquery
|
68
169
|
# @return [Big] acesso a base dados abank no bigquery
|
69
170
|
def ct_cria
|
@@ -125,6 +226,27 @@ module Abank
|
|
125
226
|
|
126
227
|
private
|
127
228
|
|
229
|
+
# @param [Array<Hash>] acc classificadores (cc)
|
230
|
+
# @return [Array<String]> array palavras formatadas
|
231
|
+
def fplo(acc)
|
232
|
+
acc.map { |p| "#{p[:p1]}#{'[' + p[:t1] + ']' unless p[:t1].to_s.empty?}#{'[2:' + p[:p2] + ']' unless p[:p2].to_s.empty?}" }
|
233
|
+
end
|
234
|
+
|
235
|
+
# @param [Array<String>] apl palavras
|
236
|
+
# @param [String] ini pre-texto final
|
237
|
+
# @return [String] palavras juntas filtradas para mostrar
|
238
|
+
def fpls(apl, ini = '')
|
239
|
+
return '' if apl.empty?
|
240
|
+
|
241
|
+
"#{ini}#{apl.join(' ')}"
|
242
|
+
end
|
243
|
+
|
244
|
+
# @param [String] pla palavra
|
245
|
+
# @return [String] palavra formatada para insert
|
246
|
+
def fpli(pla)
|
247
|
+
pla.to_s.empty? ? 'null' : "'#{pla}'"
|
248
|
+
end
|
249
|
+
|
128
250
|
# @return [Google::Cloud::Bigquery] API bigquery
|
129
251
|
def bqapi
|
130
252
|
@bqapi ||= Google::Cloud::Bigquery.new
|
data/lib/abank/version.rb
CHANGED
data/lib/abank.rb
CHANGED
@@ -18,60 +18,105 @@ module Abank
|
|
18
18
|
Big.new(options.to_h).mv_classifica.ct_dados.re_insert
|
19
19
|
end
|
20
20
|
|
21
|
-
desc '
|
21
|
+
desc 'amv', 'apaga movimentos keys|conta'
|
22
22
|
option :k, banner: 'KEY[,KEY...]', default: '', desc: 'keys movimentos apagar'
|
23
23
|
option :n, banner: 'CONTA', type: :numeric, default: 0, desc: 'conta movimentos apagar (>3 outras)'
|
24
24
|
# apaga movimentos
|
25
|
-
def
|
25
|
+
def amv
|
26
26
|
Big.new(options.transform_keys(&:to_sym)).mv_delete.ct_dados.re_insert
|
27
27
|
end
|
28
28
|
|
29
|
-
desc '
|
30
|
-
option :c, banner: 'CONTRATO', required: true, desc: '
|
29
|
+
desc 'sct', 'mostra contrato arrendamento'
|
30
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'identificador contrato arrendamento'
|
31
|
+
option :t, type: :boolean, default: true, desc: 'mostra todas as rendas?'
|
32
|
+
# mostra contrato arrendamento
|
33
|
+
def sct
|
34
|
+
Big.new(options.transform_keys(&:to_sym)).ct_mostra
|
35
|
+
end
|
36
|
+
|
37
|
+
desc 'act', 'apaga contrato arrendamento'
|
38
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'identificador contrato arrendamento'
|
31
39
|
option :t, type: :boolean, default: false, desc: 'apaga todas as rendas?'
|
32
40
|
# apaga contrato arrendamento
|
33
|
-
def
|
41
|
+
def act
|
34
42
|
Big.new(options.transform_keys(&:to_sym)).ct_apaga
|
35
43
|
end
|
36
44
|
|
37
|
-
desc '
|
38
|
-
option :c, banner: 'CONTRATO', required: true, desc: '
|
45
|
+
desc 'cct', 'cria contrato arrendamento'
|
46
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'identificador contrato arrendamento'
|
39
47
|
option :d, banner: 'DATA', default: '', desc: 'data contrato arrendamento'
|
40
48
|
option :t, type: :boolean, default: true, desc: 'cria todas as rendas?'
|
41
49
|
# cria contrato arrendamento
|
42
|
-
def
|
50
|
+
def cct
|
43
51
|
Big.new(options.transform_keys(&:to_sym)).ct_cria
|
44
52
|
end
|
45
53
|
|
46
|
-
desc '
|
47
|
-
option :c, banner: 'CONTRATO', required: true, desc: '
|
54
|
+
desc 'rct', 'atualiza rendas de contrato arrendamento'
|
55
|
+
option :c, banner: 'CONTRATO', required: true, desc: 'identificador contrato arrendamento'
|
48
56
|
# atualiza rendas de contrato arrendamento
|
49
|
-
def
|
57
|
+
def rct
|
50
58
|
opc = options[:c]
|
51
59
|
Big.new(c: opc, t: false).ct_apaga
|
52
60
|
Big.new(c: opc, t: true).ct_cria
|
53
61
|
end
|
54
62
|
|
55
|
-
desc '
|
63
|
+
desc 'rre', 'atualiza rendas dos contratos ativos'
|
56
64
|
# atualiza rendas dos contratos ativos
|
57
|
-
def
|
65
|
+
def rre
|
58
66
|
Big.new.re_atualiza
|
59
67
|
end
|
60
68
|
|
61
|
-
desc '
|
69
|
+
desc 'ccc', 'cria classificador'
|
70
|
+
option :c, banner: 'TAG', required: true, desc: 'identificador classificacao'
|
71
|
+
option :p1, banner: 'P1s', required: true, type: :array, desc: 'array palavras p1'
|
72
|
+
option :p2, banner: 'P2s', default: [], type: :array, desc: 'array palavras p2'
|
73
|
+
option :t1, banner: 'T1s', default: [], type: :array, desc: 'array traducoes t1'
|
74
|
+
# cria classificador
|
75
|
+
def ccc
|
76
|
+
Big.new(options.transform_keys(&:to_sym)).cc_cria.mv_classifica.ct_dados.re_insert
|
77
|
+
end
|
78
|
+
|
79
|
+
desc 'acc', 'apaga classificador'
|
80
|
+
option :c, banner: 'TAG', required: true, desc: 'identificador classificacao'
|
81
|
+
option :t, type: :boolean, default: false, desc: 're-classifica movimentos?'
|
82
|
+
option :p1, banner: 'P1s', default: [], type: :array, desc: 'array palavras p1'
|
83
|
+
option :p2, banner: 'P2s', default: [], type: :array, desc: 'array palavras p2'
|
84
|
+
# apaga classificador
|
85
|
+
def acc
|
86
|
+
Big.new(options.transform_keys(&:to_sym)).cc_apaga.mv_classifica.ct_dados.re_insert
|
87
|
+
end
|
88
|
+
|
89
|
+
desc 'scc', 'mostra classificador'
|
90
|
+
option :c, banner: 'TAG', default: '', desc: 'identificador classificacao'
|
91
|
+
option :p1, banner: 'P1s', default: [], type: :array, desc: 'array palavras p1'
|
92
|
+
option :p2, banner: 'P2s', default: [], type: :array, desc: 'array palavras p2'
|
93
|
+
# mostra classificador
|
94
|
+
def scc
|
95
|
+
Big.new(options.transform_keys(&:to_sym)).cc_show
|
96
|
+
end
|
97
|
+
|
98
|
+
desc 'smc', 'mostra dados movimentos classificacao'
|
99
|
+
option :c, banner: 'TAG', default: '', desc: 'identificador classificacao'
|
100
|
+
option :n, banner: 'LIMIT', type: :numeric, default: 20, desc: 'numero movimentos a mostrar'
|
101
|
+
# mostra dados classificacao
|
102
|
+
def smc
|
103
|
+
Big.new(options.transform_keys(&:to_sym).merge(p1: [], p2: [])).mc_show
|
104
|
+
end
|
105
|
+
|
106
|
+
desc 'work', 'carrega/apaga dados folha calculo'
|
62
107
|
option :s, type: :boolean, default: false, desc: 'apaga movimento similar (=data,=valor,<>descricao)'
|
63
108
|
option :e, type: :boolean, default: false, desc: 'apaga movimento igual'
|
64
109
|
option :n, banner: 'CONTA', type: :numeric, default: 0, desc: 'conta destino (0 auto,1 corrente,2 cartao,3 chash,> outras)'
|
65
110
|
option :v, banner: 'DATA', default: '', desc: 'data lancamento para movimentos a carregar'
|
66
111
|
option :g, banner: 'TAG', default: '', desc: 'classificacao para movimentos a carregar'
|
67
|
-
# carrega/apaga dados
|
112
|
+
# carrega/apaga dados folha calculo
|
68
113
|
def work
|
69
114
|
Dir.glob("#{DR}/*.xlsx").each do |file|
|
70
115
|
Folha.new(options.transform_keys(&:to_sym).merge(f: file, i: true)).processa_xls
|
71
116
|
end
|
72
117
|
end
|
73
118
|
|
74
|
-
desc 'show', 'mostra dados
|
119
|
+
desc 'show', 'mostra dados folha calculo'
|
75
120
|
option :n, banner: 'CONTA', type: :numeric, default: 0, desc: 'conta destino (0 auto,1 corrente,2 cartao,3 chash,> outras)'
|
76
121
|
# mostra folha calculo
|
77
122
|
def show
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hernâni Rodrigues Vaz
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-18 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: bundler
|