hive_sql 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: be36232746b573c2cc3d705708967c221bad9321c0042ee5cd5d176e14972c1d
4
- data.tar.gz: 442ad33603f8b64559d7ee6f8a884d3c08e762bf9ea6fc7c8892a8b98db48c25
3
+ metadata.gz: 8cc58e527a62f06dd3c1965553ce95b385170373f32f49cfd3d08dab53e9541c
4
+ data.tar.gz: 953234f4a4548da4b3ab4c3d46ef7e3e49c2346fa6c3858e6618d57648a2dadb
5
5
  SHA512:
6
- metadata.gz: a226b60838ad33fa4eb43beb4edd935511b1b1bbbabb084629b729ec4d1f7307a8891e38b7d939bfd141c4be329c5951fcefcbed8a8da002b4d12e4499215cd8
7
- data.tar.gz: 9043c8ff22eebf9f46c42dc1fe446a8c48909dfe3f8b947e3aae8f493f4701b484da8b899f74b914e29686a44b4b3b7b5f23c11d4c2500e1975668f8d3bbf0f2
6
+ metadata.gz: 91e0adc7e812497c1ce7335eac25d8df66c72e4fe1c0c43216397d132971dbb52824c38284f9d89624a63a803c5561aa7379dd9875c365bfe95c71eababf6944
7
+ data.tar.gz: 73f2d1539ffec1fe0fdb1d13dba4445a13d53d273ccbbc7d986daf1ee253f4461d354b8dfb29d1f41903158857a52da81f41c1eaab917568522e07c52a4fe390
@@ -0,0 +1,636 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require 'hive_sql'
4
+ require 'awesome_print'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'test'
8
+ t.libs << 'lib'
9
+ t.test_files = FileList['test/**/*_test.rb']
10
+ t.ruby_opts << if ENV['HELL_ENABLED']
11
+ '-W2'
12
+ else
13
+ '-W1'
14
+ end
15
+ end
16
+
17
+ task :default => :test
18
+
19
+ task :console do
20
+ exec "irb -r hive_sql -I ./lib"
21
+ end
22
+
23
+ namespace :created do
24
+ desc 'Lists accounts created grouped by creator and date.'
25
+ task :accounts, [:creator, :days_ago] do |t, args|
26
+ now = Time.now.utc
27
+ creator = args[:creator]
28
+ after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
29
+
30
+ accounts = HiveSQL::Tx::AccountCreate.all
31
+
32
+ if !!creator || creator == '%'
33
+ unless creator == '%'
34
+ accounts = accounts.where(creator: creator)
35
+ end
36
+ elsif creator =~ /.*%.*/
37
+ accounts = accounts.where('creator LIKE ?', creator)
38
+ end
39
+
40
+ accounts = accounts.where('timestamp > ?', after_timestamp)
41
+ accounts = accounts.group('CAST(timestamp AS DATE)', :creator)
42
+ accounts = accounts.order('cast_timestamp_as_date ASC')
43
+
44
+ accounts = accounts.count
45
+ puts "# Daily creation count by #{creator.nil? ? 'all account creators' : creator} since #{after_timestamp} ..."
46
+ ap accounts
47
+ puts "# Total accounts: #{accounts.values.sum}"
48
+ end
49
+
50
+ desc 'Lists custom_json_operations grouped by id and date.'
51
+ task :custom_json, [:id, :days_ago, :min_count] do |t, args|
52
+ now = Time.now.utc
53
+ tid = args[:id]
54
+ after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
55
+ min_count = (args[:min_count] || 1).to_i
56
+
57
+ customs = HiveSQL::Tx::Custom.all
58
+
59
+ if !!tid && tid != '%' && tid =~ /.*%.*/
60
+ customs = customs.where("tid LIKE ?", tid)
61
+ elsif !!tid && tid != '%'
62
+ customs = customs.where(tid: tid)
63
+ end
64
+
65
+ customs = customs.where('timestamp > ?', after_timestamp)
66
+ customs = customs.group('CAST(timestamp AS DATE)', :tid)
67
+ customs = customs.order('cast_timestamp_as_date ASC')
68
+
69
+ customs = customs.count
70
+
71
+ customs = customs.map do |k, v|
72
+ [k, v] if v >= min_count
73
+ end.compact.to_h
74
+
75
+ puts "# Daily creation count by #{tid.nil? ? 'all custom_json_operation' : tid} since #{after_timestamp} ..."
76
+ ap customs
77
+ puts "# Total custom_json_operation: #{customs.values.sum}"
78
+ end
79
+ end
80
+
81
+ desc 'Lists sum of transfers grouped by date, from, and to.'
82
+ task :transfers, [:minimum_amount, :symbol, :days_ago] do |t, args|
83
+ now = Time.now.utc
84
+ minimum_amount = (args[:minimum_amount] || '1000000').to_f
85
+ symbol = (args[:symbol] || 'HIVE').upcase
86
+ after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
87
+
88
+ # Only type: transfer; ignore savings, vestings
89
+ transfers = HiveSQL::Tx::Transfer.where(type: 'transfer')
90
+ transfers = transfers.where('amount > ?', minimum_amount)
91
+ transfers = transfers.where('amount_symbol = ?', symbol)
92
+ transfers = transfers.where('timestamp > ?', after_timestamp)
93
+ transfers = transfers.group('CAST(timestamp AS DATE)', :from, :to)
94
+ transfers = transfers.order('cast_timestamp_as_date ASC')
95
+
96
+ puts "Daily transfer sum over #{'%.3f' % minimum_amount} #{symbol} since #{after_timestamp} ..."
97
+ ap transfers.sum(:amount)
98
+ end
99
+
100
+ desc 'Lists sum of powered up grouped by date, from, and to.'
101
+ task :powerup, [:minimum_amount, :symbol, :days_ago, :not_to_self] do |t, args|
102
+ now = Time.now.utc
103
+ minimum_amount = (args[:minimum_amount] || '500').to_f
104
+ symbol = (args[:symbol] || 'HIVE').upcase
105
+ after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
106
+ not_to_self = (args[:not_to_self] || 'false') == 'true'
107
+
108
+ minimum_amount = case symbol
109
+ when 'MVESTS' then minimum_amount * 1e6 #TODO
110
+ when 'VESTS' then minimum_amount # TODO
111
+ when 'HIVE' then minimum_amount
112
+ else; raise "Unknown symbol: #{symbol}"
113
+ end
114
+
115
+ # Only type: transfer; ignore savings, vestings
116
+ transfers = HiveSQL::Tx::Transfer.where(type: 'transfer_to_vesting')
117
+ transfers = transfers.where('amount > ?', minimum_amount)
118
+ transfers = transfers.where('amount_symbol = ?', 'HIVE')
119
+ transfers = transfers.where('timestamp > ?', after_timestamp)
120
+ transfers = transfers.group('CAST(timestamp AS DATE)', :from, :to)
121
+ transfers = transfers.order('cast_timestamp_as_date ASC')
122
+
123
+ transfers = transfers.sum(:amount)
124
+
125
+ if not_to_self
126
+ transfers = transfers.map do |k, v|
127
+ [k, v] if k[1] != k[2]
128
+ end.compact.to_h
129
+ end
130
+
131
+ puts "# Daily transfer sum over #{'%.3f' % minimum_amount} #{symbol} #{not_to_self ? '' : 'not to self '}since #{after_timestamp} ..."
132
+ ap transfers
133
+ puts "# Total #{symbol}: #{transfers.values.sum}"
134
+ end
135
+
136
+ desc 'Lists sum of powered down grouped by date, from, and to.'
137
+ task :powerdown, [:minimum_amount, :symbol, :days_ago, :not_to_self] do |t, args|
138
+ now = Time.now.utc
139
+ minimum_amount = (args[:minimum_amount] || '500').to_f
140
+ symbol = (args[:symbol] || 'HIVE').upcase
141
+ after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
142
+ not_to_self = (args[:not_to_self] || 'false') == 'true'
143
+
144
+ minimum_amount = case symbol
145
+ when 'MVESTS' then minimum_amount * 1e6 #TODO
146
+ when 'VESTS' then minimum_amount # TODO
147
+ when 'HIVE' then minimum_amount
148
+ else; raise "Unknown symbol: #{symbol}"
149
+ end
150
+
151
+ # Only type: transfer; ignore savings, vestings
152
+ transfers = HiveSQL::Tx::Transfer.where(type: 'transfer_to_vesting')
153
+ transfers = transfers.where('amount > ?', minimum_amount)
154
+ transfers = transfers.where('amount_symbol = ?', 'HIVE')
155
+ transfers = transfers.where('timestamp > ?', after_timestamp)
156
+ transfers = transfers.group('CAST(timestamp AS DATE)', :from, :to)
157
+ transfers = transfers.order('cast_timestamp_as_date ASC')
158
+
159
+ transfers = transfers.sum(:amount)
160
+
161
+ if not_to_self
162
+ transfers = transfers.map do |k, v|
163
+ [k, v] if k[1] != k[2]
164
+ end.compact.to_h
165
+ end
166
+
167
+ puts "# Daily transfer sum over #{'%.3f' % minimum_amount} #{symbol} #{not_to_self ? '' : 'not to self '}since #{after_timestamp} ..."
168
+ ap transfers
169
+ puts "# Total #{symbol}: #{transfers.values.sum}"
170
+ end
171
+
172
+ desc 'Lists apps grouped by date, app/version.'
173
+ task :apps, [:app, :days_ago] do |t, args|
174
+ now = Time.now.utc
175
+ app = args[:app]
176
+ after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
177
+
178
+ comments = HiveSQL::Comment.normalized_json
179
+ comments = comments.app(app) if !!app
180
+ comments = comments.where('created > ?', after_timestamp)
181
+ comments = comments.group('CAST(created AS DATE)', "JSON_VALUE(json_metadata, '$.app')")
182
+ comments = comments.order('cast_created_as_date ASC')
183
+
184
+ matching = " matching \"#{app}\"" if !!app
185
+ puts "Daily app#{matching} count since #{after_timestamp} ..."
186
+ ap comments.count(:all)
187
+ end
188
+
189
+ desc 'Lists app names grouped by date, app/version.'
190
+ task :app_names, [:app, :days_ago] do |t, args|
191
+ now = Time.now.utc
192
+ app = args[:app]
193
+ after_timestamp = now - ((args[:days_ago] || '7').to_f * 86400)
194
+
195
+ comments = HiveSQL::Comment.normalized_json
196
+ comments = comments.app(app) if !!app
197
+ comments = comments.where('created > ?', after_timestamp)
198
+ comments = comments.group('CAST(created AS DATE)', "JSON_VALUE(json_metadata, '$.app')")
199
+ comments = comments.order('cast_created_as_date ASC')
200
+
201
+ matching = " matching \"#{app}\"" if !!app
202
+ puts "# Daily app#{matching} count since #{after_timestamp} ..."
203
+
204
+ app_names = {}
205
+
206
+ comments.count(:all).each do |k, v|
207
+ date, app = k
208
+ if !!app && app.include?('/')
209
+ name, version = app.split('/')
210
+ app_names[[date, name]] ||= 0.0
211
+ app_names[[date, name]] += v
212
+ end
213
+ end
214
+
215
+ ap app_names
216
+ end
217
+
218
+ desc 'Do all crosschecks of given account.'
219
+ task :crosscheck, [:account] do |t, args|
220
+ account = args[:account]
221
+
222
+ Rake::Task["crosscheck:powerdowns"].invoke(account)
223
+ Rake::Task["crosscheck:powerups"].invoke(account)
224
+ Rake::Task["crosscheck:transfers"].invoke(account)
225
+ Rake::Task["crosscheck:vesting_from"].invoke(account)
226
+ Rake::Task["crosscheck:vesting_to"].invoke(account)
227
+ end
228
+
229
+ namespace :crosscheck do
230
+ desc 'List of accounts grouped by transfer count crosschecked by memo of given account.'
231
+ task :transfers, [:account] do |t, args|
232
+ exchanges = %w(bittrex poloniex openledger blocktrades deepcrypto8 gopax
233
+ binanceexchange teambitwala changelly hitbtc-exchange korbit roomofsatoshi
234
+ shapeshiftio)
235
+ account = args[:account]
236
+
237
+ if account.nil? || account == ''
238
+ puts 'Account name required.'
239
+ exit
240
+ elsif exchanges.include? account
241
+ puts 'That procedure is not recommended.'
242
+ exit
243
+ end
244
+
245
+ all = HiveSQL::Tx::Transfer.where(type: 'transfer')
246
+ transfers = all.where.not(memo: '')
247
+ transfers = transfers.where(to: exchanges)
248
+ transfers = if account =~ /%/
249
+ table = HiveSQL::Tx::Transfer.arel_table
250
+ transfers.where(table[:from].matches(account))
251
+ else
252
+ transfers.where(from: account)
253
+ end
254
+ crosscheck_transfers = all.where(memo: transfers.select(:memo))
255
+
256
+ if transfers.none?
257
+ puts "No match."
258
+ else
259
+ from = transfers.pluck(:from).uniq.join(', ')
260
+ puts "Accounts grouped by transfer count using common memos as #{from} on common exchanges ..."
261
+ ap crosscheck_transfers.group(:from).order('count_all').count(:all)
262
+ end
263
+ end
264
+
265
+ desc 'List of accounts grouped by vesting transfers from a given account'
266
+ task :vesting_from, [:account] do |t, args|
267
+ account = args[:account]
268
+
269
+ if account.nil? || account == ''
270
+ puts 'Account name required.'
271
+ exit
272
+ end
273
+
274
+ table = HiveSQL::Tx::Transfer.arel_table
275
+ all = HiveSQL::Tx::Transfer.where(type: 'transfer_to_vesting')
276
+ transfers = all.where(table[:from].not_eq(:to))
277
+ transfers = transfers.where.not(to: '')
278
+ transfers = if account =~ /%/
279
+ table = HiveSQL::Tx::Transfer.arel_table
280
+ transfers.where(table[:from].matches(account))
281
+ else
282
+ transfers.where(from: account)
283
+ end
284
+
285
+ if transfers.none?
286
+ puts "No match."
287
+ else
288
+ from = transfers.pluck(:from).uniq.join(', ')
289
+ puts "Accounts grouped by vesting transfer count from #{from} ..."
290
+ ap transfers.group(:to).order('count_all').count(:all)
291
+ end
292
+ end
293
+
294
+ desc 'List of accounts grouped by vesting transfers to a given account'
295
+ task :vesting_to, [:account] do |t, args|
296
+ account = args[:account]
297
+
298
+ if account.nil? || account == ''
299
+ puts 'Account name required.'
300
+ exit
301
+ end
302
+
303
+ table = HiveSQL::Tx::Transfer.arel_table
304
+ all = HiveSQL::Tx::Transfer.where(type: 'transfer_to_vesting')
305
+ transfers = all.where(table[:from].not_eq(table[:to]))
306
+ transfers = transfers.where.not(to: '')
307
+ transfers = if account =~ /%/
308
+ table = HiveSQL::Tx::Transfer.arel_table
309
+ transfers.where(table[:to].matches(account))
310
+ else
311
+ transfers.where(to: account)
312
+ end
313
+
314
+ if transfers.none?
315
+ puts "No match."
316
+ else
317
+ from = transfers.pluck(:to).uniq.join(', ')
318
+ puts "Accounts grouped by vesting transfer count to #{from} ..."
319
+ ap transfers.group(:from).order('count_all').count(:all)
320
+ end
321
+ end
322
+
323
+ desc 'List of accounts grouped by powerdown sums crosschecked by given account.'
324
+ task :powerdowns, [:account] do |t, args|
325
+ account = args[:account]
326
+
327
+ if account.nil? || account == ''
328
+ puts 'Account name required.'
329
+ exit
330
+ end
331
+
332
+ table = HiveSQL::Vo::FillVestingWithdraw.arel_table
333
+ all = HiveSQL::Vo::FillVestingWithdraw.where(table[:from_account].not_eq(table[:to_account]))
334
+ powerdowns = if account =~ /%/
335
+ all.where(table[:from_account].matches(account))
336
+ else
337
+ all.where(from_account: account)
338
+ end
339
+
340
+ if powerdowns.none?
341
+ puts "No match."
342
+ else
343
+ from = powerdowns.pluck(:from_account).uniq.join(', ')
344
+ puts "Powerdowns grouped by sum from #{from} ..."
345
+ ap powerdowns.group(:to_account).
346
+ order('sum_try_parse_replace_withdrawn_vests_as_float').
347
+ sum("TRY_PARSE(REPLACE(withdrawn, ' VESTS', '') AS float)")
348
+ end
349
+ end
350
+
351
+ desc 'List of accounts grouped by powerup sums crosschecked by given account.'
352
+ task :powerups, [:account] do |t, args|
353
+ account = args[:account]
354
+
355
+ if account.nil? || account == ''
356
+ puts 'Account name required.'
357
+ exit
358
+ end
359
+
360
+ table = HiveSQL::Vo::FillVestingWithdraw.arel_table
361
+ all = HiveSQL::Vo::FillVestingWithdraw.where(table[:from_account].not_eq(table[:to_account]))
362
+ powerups = if account =~ /%/
363
+ all.where(table[:to_account].matches(account))
364
+ else
365
+ all.where(to_account: account)
366
+ end
367
+
368
+ if powerups.none?
369
+ puts "No match."
370
+ else
371
+ to = powerups.pluck(:to_account).uniq.join(', ')
372
+ puts "Powerups grouped by sum to #{to} ..."
373
+ ap powerups.group(:from_account).
374
+ order('sum_try_parse_replace_withdrawn_vests_as_float').
375
+ sum("TRY_PARSE(REPLACE(withdrawn, ' VESTS', '') AS float)")
376
+ end
377
+ end
378
+ end
379
+
380
+ namespace :rewards do
381
+ desc 'Lists author rewards grouped by date.'
382
+ task :author, [:symbol, :days_ago, :author] do |t, args|
383
+ now = Time.now.utc
384
+ symbol = (args[:symbol] || 'HBD').upcase
385
+ after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
386
+ author = args[:author]
387
+
388
+ rewards = HiveSQL::Vo::AuthorReward
389
+ rewards = rewards.where('timestamp > ?', after_timestamp)
390
+ rewards = rewards.group('CAST(timestamp AS DATE)')
391
+ rewards = rewards.order('cast_timestamp_as_date ASC')
392
+
393
+ if !!author
394
+ if author =~ /%/
395
+ rewards = rewards.where("author LIKE ?", author)
396
+ else
397
+ rewards = rewards.where(author: author)
398
+ end
399
+
400
+ puts "Daily #{author} reward #{symbol} sum grouped by date since #{after_timestamp} ..."
401
+ else
402
+ puts "Daily reward #{symbol} sum grouped by date since #{after_timestamp} ..."
403
+ end
404
+
405
+ rewards = case symbol
406
+ when 'HBD' then rewards.sum(:hbd_payout)
407
+ when 'HIVE' then rewards.sum(:hive_payout)
408
+ when 'VESTS' then rewards.sum(:vesting_payout)
409
+ when 'MVESTS'
410
+ rewards.sum('vesting_payout / 1000000')
411
+ else; puts "Unknown symbol: #{symbol}. Symbols supported: HBD, HIVE, VESTS, MVESTS"
412
+ end
413
+
414
+ ap rewards
415
+ sum = rewards.values.sum
416
+ puts "# Total rewards: %.3f %s (average: %.3f per day)" % [sum, symbol, (sum / rewards.size)]
417
+ end
418
+
419
+ desc 'Lists curation rewards grouped by date.'
420
+ task :curation, [:symbol, :days_ago, :curator] do |t, args|
421
+ now = Time.now.utc
422
+ symbol = (args[:symbol] || 'MVESTS').upcase
423
+ after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
424
+ curator = args[:curator]
425
+
426
+ rewards = HiveSQL::Vo::CurationReward
427
+ rewards = rewards.where('timestamp > ?', after_timestamp)
428
+ rewards = rewards.group('CAST(timestamp AS DATE)')
429
+ rewards = rewards.order('cast_timestamp_as_date ASC')
430
+
431
+ if !!curator
432
+ if curator =~ /%/
433
+ rewards = rewards.where("curator LIKE ?", curator)
434
+ else
435
+ rewards = rewards.where(curator: curator)
436
+ end
437
+
438
+ puts "Daily #{curator} reward #{symbol} sum grouped by date since #{after_timestamp} ..."
439
+ else
440
+ puts "Daily curation reward #{symbol} sum grouped by date since #{after_timestamp} ..."
441
+ end
442
+
443
+ case symbol
444
+ when 'VESTS'
445
+ ap rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float)")
446
+ when 'MVESTS'
447
+ ap rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float) / 1000000")
448
+ else; puts "Unknown symbol: #{symbol}. Symbols supported: VESTS, MVESTS"
449
+ end
450
+ end
451
+ end
452
+
453
+ desc 'Lists proxied grouped by month.'
454
+ task :proxied, [:days_ago] do |t, args|
455
+ now = Time.now.utc
456
+ after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
457
+
458
+ proxied = HiveSQL::Tx::AccountWitnessProxy
459
+ proxied = proxied.where('timestamp > ?', after_timestamp)
460
+ proxied = proxied.group("FORMAT(timestamp, 'yyyy-MM')", :proxy)
461
+ proxied = proxied.order('format_timestamp_yyyy_mm ASC')
462
+
463
+ puts "Daily proxied grouped by month since #{after_timestamp} ..."
464
+
465
+ ap proxied.count(:all)
466
+ end
467
+
468
+ desc <<~EOF
469
+ Claimed Rewards.
470
+ Use the "account_name" of a user or '%' to match on any user.
471
+ EOF
472
+ task :claimed, [:account_name, :days_ago, :symbol] do |t, args|
473
+ now = Time.now.utc
474
+ account_name = args[:account_name] || '%'
475
+ after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
476
+ symbol = (args[:symbol] || 'vests').downcase.to_sym
477
+ claims = HiveSQL::Tx::ClaimRewardBalance.where('timestamp > ?', after_timestamp)
478
+
479
+ claims = if account_name =~ /%/
480
+ claims.where('account LIKE ?', account_name)
481
+ else
482
+ claims.where(account: account_name)
483
+ end
484
+
485
+ claims = case symbol
486
+ when :vests then claims.where("reward_vests > 0")
487
+ when :mvests then claims.where("reward_vests > 0")
488
+ when :hive then claims.where("reward_hive > 0")
489
+ when :hbd then claims.where("reward_hbd > 0")
490
+ else; raise "Unknown symbol: #{symbol.to_s.upcase} (allowed: VESTS, MVESTS, HIVE, HBD)"
491
+ end
492
+
493
+ claims = claims.group("FORMAT(timestamp, 'yyyy-MM')")
494
+ claims = claims.order('format_timestamp_yyyy_mm ASC')
495
+
496
+ claims = case symbol
497
+ when :vests then claims.sum(:reward_vests)
498
+ when :mvests then claims.sum('reward_vests / 1000000')
499
+ when :hive then claims.sum(:reward_hive)
500
+ when :hbd then claims.sum(:reward_hbd)
501
+ end
502
+
503
+ puts "# Claimed rewards in #{symbol.to_s.upcase} sum grouped by month ..."
504
+
505
+ ap claims
506
+ puts "# Total claimed #{symbol}: #{claims.values.sum}"
507
+ end
508
+
509
+ desc <<~EOF
510
+ Balance for given parties.
511
+ Where "party_a" is the first account, "party_b" is the second account and "symbol" is a valid native symbol.
512
+ EOF
513
+ task :balance, [:party_a, :party_b, :symbol] do |t, args|
514
+ party_a = args[:party_a]
515
+ party_b = args[:party_b]
516
+ symbol = args[:symbol].upcase
517
+
518
+ balance_a = HiveSQL::Tx::Transfer.where(to: party_a, from: party_b, amount_symbol: symbol).sum(:amount).to_f
519
+ balance_b = HiveSQL::Tx::Transfer.where(to: party_b, from: party_a, amount_symbol: symbol).sum(:amount).to_f
520
+
521
+ puts "#{party_a}: %.3f #{symbol}, difference: %.3f #{symbol}" % [balance_a, (balance_a - balance_b)]
522
+ puts "#{party_b}: %.3f #{symbol}, difference: %.3f #{symbol}" % [balance_b, (balance_b - balance_a)]
523
+ end
524
+
525
+ desc <<~EOF
526
+ Top comments by what ...
527
+ Allowed \"what\" options: upvoted downvoted
528
+ EOF
529
+ task :top, [:what, :limit] do |t, args|
530
+ what = args[:what].to_s.downcase.to_sym
531
+ limit = (args[:limit] || '10').to_i
532
+ since = 1.week.ago
533
+
534
+ case what
535
+ when :upvoted, :downvoted
536
+ comments = HiveSQL::Comment.after(since)
537
+ comments = if what == :upvoted
538
+ comments.where('net_rshares > 0')
539
+ comments = comments.order('sum_net_rshares DESC')
540
+ elsif what == :downvoted
541
+ comments.where('net_rshares < 0')
542
+ comments = comments.order('sum_net_rshares ASC')
543
+ end
544
+
545
+ comments = comments.group(:author, :permlink, :created)
546
+ comments = comments.limit(limit)
547
+
548
+ comments = comments.sum(:net_rshares)
549
+
550
+ comments.each do |k, v|
551
+ url = "https://hive.blog/@#{k[0]}/#{k[1]}"
552
+ created = (Time.now - k[2]) / 60 / 60 / 24
553
+
554
+ puts "#{v}; #{created.round(2)} days ago: #{url}"
555
+ end
556
+ end
557
+ end
558
+
559
+ desc <<~EOF
560
+ Top tags by pending_payout_value.
561
+ EOF
562
+ task :top_tags, [:limit] do |t, args|
563
+ limit = (args[:limit] || '100').to_i
564
+ since = 1.week.ago
565
+
566
+ comments = HiveSQL::Comment.after(since)
567
+ comments = comments.joins(:tags)
568
+ comments = comments.where('pending_payout_value > 0')
569
+ comments = comments.order('sum_pending_payout_value DESC')
570
+
571
+ comments = comments.group('LOWER(tags.tag)')
572
+ comments = comments.limit(limit)
573
+
574
+ comments = comments.sum(:pending_payout_value)
575
+
576
+ comments.each do |k, v|
577
+ url = "https://hive.blog/#{k}"
578
+
579
+ puts "#{v}; #{url}"
580
+ end
581
+ end
582
+
583
+ desc 'Lists sum of proposal pay grouped by date, from, and to.'
584
+ task :proposal_pay, [:minimum_payment, :days_ago] do |t, args|
585
+ now = Time.now.utc
586
+ minimum_payment = (args[:minimum_payment] || '0.001').to_f
587
+ symbol = (args[:symbol] || 'HBD').upcase
588
+ days_ago = (args[:days_ago] || '30').to_i
589
+ after_timestamp = now - days_ago * 86400
590
+
591
+ payments = HiveSQL::Vo::ProposalPay.where.not(receiver: ['steem.dao', 'hive.fund'])
592
+ payments = payments.where('payment > ?', minimum_payment)
593
+ payments = payments.where('payment_symbol = ?', symbol)
594
+ payments = payments.where('timestamp > ?', after_timestamp)
595
+ payments = payments.group('CAST(timestamp AS DATE)', :receiver)
596
+ payments = payments.order('cast_timestamp_as_date ASC')
597
+
598
+ puts "Daily payment sum over #{'%.3f' % minimum_payment} #{symbol} since #{after_timestamp} ..."
599
+ ap payments.sum(:payment)
600
+
601
+ average_daily_payments = payments.sum(:payment).values.sum / days_ago
602
+ puts "Average daily payments: #{'%.3f' % average_daily_payments} #{symbol}"
603
+ end
604
+
605
+ # Doesn't look like this table exists.
606
+ # desc 'List conversion HBD conversion request sums grouped by day.'
607
+ # task :convert, [:days_ago] do |t, args|
608
+ # now = Time.now.utc
609
+ # after_timestamp = now - ((args[:days_ago] || '3.5').to_f * 86400)
610
+ #
611
+ # converts = HiveSQL::Vo::FillConvertRequest
612
+ # converts = converts.where('timestamp > ?', after_timestamp)
613
+ # converts = converts.group('CAST(timestamp AS DATE)')
614
+ # converts = converts.order('cast_timestamp_as_date ASC')
615
+ #
616
+ # puts "Daily conversion requests failled sum grouped by date since #{after_timestamp} ..."
617
+ # ap converts.sum(:amount)
618
+ # end
619
+
620
+ desc 'Build a new version of the hive_sql gem.'
621
+ task :build do
622
+ exec 'gem build hive_sql.gemspec'
623
+ end
624
+
625
+ desc 'Publish the current version of the hive_sql gem.'
626
+ task :push do
627
+ exec "gem push hive_sql-#{HiveSQL::VERSION}.gem"
628
+ end
629
+
630
+ # We're not going to yank on a regular basis, but this is how it's done if you
631
+ # really want a task for that for some reason.
632
+
633
+ # desc 'Yank the current version of the hive_sql gem.'
634
+ # task :yank do
635
+ # exec "gem yank hive_sql -v #{HiveSQL::VERSION}"
636
+ # end
@@ -11,6 +11,7 @@ require "hive_sql/models/connection"
11
11
  require "hive_sql/models/community"
12
12
  require "hive_sql/models/community_subscriber"
13
13
  require "hive_sql/models/community_role"
14
+ require "hive_sql/models/delegation"
14
15
  require "hive_sql/models/dynamic_global_properties"
15
16
  require "hive_sql/models/follower"
16
17
  require "hive_sql/models/reblog"
@@ -0,0 +1,24 @@
1
+ module HiveSQL
2
+ class Delegation < HiveSQL::SqlBase
3
+
4
+ self.table_name = :Delegations
5
+
6
+ belongs_to :delegator_account, foreign_key: :delegator, primary_key: 'name', class_name: 'HiveSQL::Account'
7
+ belongs_to :delegatee_account, foreign_key: :delegatee, primary_key: 'name', class_name: 'HiveSQL::Account'
8
+
9
+ scope :delegator, lambda {|delegator| where(delegator: delegator)}
10
+ scope :delegatee, lambda {|delegatee| where(delegatee: delegatee)}
11
+
12
+ def mvests
13
+ vests / 1e6
14
+ end
15
+ end
16
+ end
17
+
18
+ # Structure
19
+ #
20
+ # HiveSQL::Delegation(
21
+ # delegator: varchar,
22
+ # delegatee: varchar,
23
+ # vests: money
24
+ # )
@@ -1,3 +1,3 @@
1
1
  module HiveSQL
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hive_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anthony Martin (inertia)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-22 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -225,9 +225,6 @@ dependencies:
225
225
  - - ">="
226
226
  - !ruby/object:Gem::Version
227
227
  version: '4'
228
- - - "<"
229
- - !ruby/object:Gem::Version
230
- version: '6'
231
228
  type: :runtime
232
229
  prerelease: false
233
230
  version_requirements: !ruby/object:Gem::Requirement
@@ -235,9 +232,6 @@ dependencies:
235
232
  - - ">="
236
233
  - !ruby/object:Gem::Version
237
234
  version: '4'
238
- - - "<"
239
- - !ruby/object:Gem::Version
240
- version: '6'
241
235
  - !ruby/object:Gem::Dependency
242
236
  name: tiny_tds
243
237
  requirement: !ruby/object:Gem::Requirement
@@ -259,9 +253,6 @@ dependencies:
259
253
  - - ">="
260
254
  - !ruby/object:Gem::Version
261
255
  version: '4'
262
- - - "<"
263
- - !ruby/object:Gem::Version
264
- version: '6'
265
256
  type: :runtime
266
257
  prerelease: false
267
258
  version_requirements: !ruby/object:Gem::Requirement
@@ -269,9 +260,6 @@ dependencies:
269
260
  - - ">="
270
261
  - !ruby/object:Gem::Version
271
262
  version: '4'
272
- - - "<"
273
- - !ruby/object:Gem::Version
274
- version: '6'
275
263
  - !ruby/object:Gem::Dependency
276
264
  name: activesupport
277
265
  requirement: !ruby/object:Gem::Requirement
@@ -279,9 +267,6 @@ dependencies:
279
267
  - - ">="
280
268
  - !ruby/object:Gem::Version
281
269
  version: '4'
282
- - - "<"
283
- - !ruby/object:Gem::Version
284
- version: '6'
285
270
  type: :runtime
286
271
  prerelease: false
287
272
  version_requirements: !ruby/object:Gem::Requirement
@@ -289,9 +274,6 @@ dependencies:
289
274
  - - ">="
290
275
  - !ruby/object:Gem::Version
291
276
  version: '4'
292
- - - "<"
293
- - !ruby/object:Gem::Version
294
- version: '6'
295
277
  - !ruby/object:Gem::Dependency
296
278
  name: awesome_print
297
279
  requirement: !ruby/object:Gem::Requirement
@@ -322,6 +304,7 @@ extra_rdoc_files: []
322
304
  files:
323
305
  - LICENSE
324
306
  - README.md
307
+ - Rakefile
325
308
  - bin/hive_sql
326
309
  - lib/hive_sql.rb
327
310
  - lib/hive_sql/models/account.rb
@@ -331,6 +314,7 @@ files:
331
314
  - lib/hive_sql/models/community_role.rb
332
315
  - lib/hive_sql/models/community_subscriber.rb
333
316
  - lib/hive_sql/models/connection.rb
317
+ - lib/hive_sql/models/delegation.rb
334
318
  - lib/hive_sql/models/dynamic_global_properties.rb
335
319
  - lib/hive_sql/models/follower.rb
336
320
  - lib/hive_sql/models/reblog.rb