This repository was archived by the owner on Jun 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathRakefile
More file actions
538 lines (448 loc) · 18.2 KB
/
Rakefile
File metadata and controls
538 lines (448 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
require "bundler/gem_tasks"
require "rake/testtask"
require 'steem_api'
require 'awesome_print'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
t.ruby_opts << if ENV['HELL_ENABLED']
'-W2'
else
'-W1'
end
end
task :default => :test
task :console do
exec "irb -r steem_api -I ./lib"
end
namespace :created do
desc 'Lists accounts created grouped by creator and date.'
task :accounts, [:creator, :days_ago] do |t, args|
now = Time.now.utc
creator = args[:creator]
after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
accounts = SteemApi::Tx::AccountCreate.all
if !!creator || creator == '%'
unless creator == '%'
accounts = accounts.where(creator: creator)
end
elsif creator =~ /.*%.*/
accounts = accounts.where('creator LIKE ?', creator)
end
accounts = accounts.where('timestamp > ?', after_timestamp)
accounts = accounts.group('CAST(timestamp AS DATE)', :creator)
accounts = accounts.order('cast_timestamp_as_date ASC')
accounts = accounts.count
puts "# Daily creation count by #{creator.nil? ? 'all account creators' : creator} since #{after_timestamp} ..."
ap accounts
puts "# Total accounts: #{accounts.values.sum}"
end
desc 'Lists custom_json_operations grouped by id and date.'
task :custom_json, [:id, :days_ago, :min_count] do |t, args|
now = Time.now.utc
tid = args[:id]
after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
min_count = (args[:min_count] || 1).to_i
customs = SteemApi::Tx::Custom.all
if !!tid && tid != '%' && tid =~ /.*%.*/
customs = customs.where("tid LIKE ?", tid)
elsif !!tid && tid != '%'
customs = customs.where(tid: tid)
end
customs = customs.where('timestamp > ?', after_timestamp)
customs = customs.group('CAST(timestamp AS DATE)', :tid)
customs = customs.order('cast_timestamp_as_date ASC')
customs = customs.count
customs = customs.map do |k, v|
[k, v] if v >= min_count
end.compact.to_h
puts "# Daily creation count by #{tid.nil? ? 'all custom_json_operation' : tid} since #{after_timestamp} ..."
ap customs
puts "# Total custom_json_operation: #{customs.values.sum}"
end
end
desc 'Lists sum of transfers grouped by date, from, and to.'
task :transfers, [:minimum_amount, :symbol, :days_ago] do |t, args|
now = Time.now.utc
minimum_amount = (args[:minimum_amount] || '1000000').to_f
symbol = (args[:symbol] || 'STEEM').upcase
after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
# Only type: transfer; ignore savings, vestings
transfers = SteemApi::Tx::Transfer.where(type: 'transfer')
transfers = transfers.where('amount > ?', minimum_amount)
transfers = transfers.where('amount_symbol = ?', symbol)
transfers = transfers.where('timestamp > ?', after_timestamp)
transfers = transfers.group('CAST(timestamp AS DATE)', :from, :to)
transfers = transfers.order('cast_timestamp_as_date ASC')
puts "Daily transfer sum over #{'%.3f' % minimum_amount} #{symbol} since #{after_timestamp} ..."
ap transfers.sum(:amount)
end
desc 'Lists sum of powered up grouped by date, from, and to.'
task :powerup, [:minimum_amount, :symbol, :days_ago, :not_to_self] do |t, args|
now = Time.now.utc
minimum_amount = (args[:minimum_amount] || '500').to_f
symbol = (args[:symbol] || 'STEEM').upcase
after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
not_to_self = (args[:not_to_self] || 'false') == 'true'
minimum_amount = case symbol
when 'MVESTS' then minimum_amount * 1e6 #TODO
when 'VESTS' then minimum_amount # TODO
when 'STEEM' then minimum_amount
else; raise "Unknown symbol: #{symbol}"
end
# Only type: transfer; ignore savings, vestings
transfers = SteemApi::Tx::Transfer.where(type: 'transfer_to_vesting')
transfers = transfers.where('amount > ?', minimum_amount)
transfers = transfers.where('amount_symbol = ?', 'STEEM')
transfers = transfers.where('timestamp > ?', after_timestamp)
transfers = transfers.group('CAST(timestamp AS DATE)', :from, :to)
transfers = transfers.order('cast_timestamp_as_date ASC')
transfers = transfers.sum(:amount)
if not_to_self
transfers = transfers.map do |k, v|
[k, v] if k[1] != k[2]
end.compact.to_h
end
puts "# Daily transfer sum over #{'%.3f' % minimum_amount} #{symbol} #{not_to_self ? '' : 'not to self '}since #{after_timestamp} ..."
ap transfers
puts "# Total #{symbol}: #{transfers.values.sum}"
end
desc 'Lists sum of powered down grouped by date, from, and to.'
task :powerdown, [:minimum_amount, :symbol, :days_ago, :not_to_self] do |t, args|
now = Time.now.utc
minimum_amount = (args[:minimum_amount] || '500').to_f
symbol = (args[:symbol] || 'STEEM').upcase
after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
not_to_self = (args[:not_to_self] || 'false') == 'true'
minimum_amount = case symbol
when 'MVESTS' then minimum_amount * 1e6 #TODO
when 'VESTS' then minimum_amount # TODO
when 'STEEM' then minimum_amount
else; raise "Unknown symbol: #{symbol}"
end
# Only type: transfer; ignore savings, vestings
transfers = SteemApi::Tx::Transfer.where(type: 'transfer_to_vesting')
transfers = transfers.where('amount > ?', minimum_amount)
transfers = transfers.where('amount_symbol = ?', 'STEEM')
transfers = transfers.where('timestamp > ?', after_timestamp)
transfers = transfers.group('CAST(timestamp AS DATE)', :from, :to)
transfers = transfers.order('cast_timestamp_as_date ASC')
transfers = transfers.sum(:amount)
if not_to_self
transfers = transfers.map do |k, v|
[k, v] if k[1] != k[2]
end.compact.to_h
end
puts "# Daily transfer sum over #{'%.3f' % minimum_amount} #{symbol} #{not_to_self ? '' : 'not to self '}since #{after_timestamp} ..."
ap transfers
puts "# Total #{symbol}: #{transfers.values.sum}"
end
desc 'Lists apps grouped by date, app/version.'
task :apps, [:app, :days_ago] do |t, args|
now = Time.now.utc
app = args[:app]
after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
comments = SteemApi::Comment.normalized_json
comments = comments.app(app) if !!app
comments = comments.where('created > ?', after_timestamp)
comments = comments.group('CAST(created AS DATE)', "JSON_VALUE(json_metadata, '$.app')")
comments = comments.order('cast_created_as_date ASC')
matching = " matching \"#{app}\"" if !!app
puts "Daily app#{matching} count since #{after_timestamp} ..."
ap comments.count(:all)
end
desc 'Lists app names grouped by date, app/version.'
task :app_names, [:app, :days_ago] do |t, args|
now = Time.now.utc
app = args[:app]
after_timestamp = now - ((args[:days_ago] || '7').to_f * 86400)
comments = SteemApi::Comment.normalized_json
comments = comments.app(app) if !!app
comments = comments.where('created > ?', after_timestamp)
comments = comments.group('CAST(created AS DATE)', "JSON_VALUE(json_metadata, '$.app')")
comments = comments.order('cast_created_as_date ASC')
matching = " matching \"#{app}\"" if !!app
puts "# Daily app#{matching} count since #{after_timestamp} ..."
app_names = {}
comments.count(:all).each do |k, v|
date, app = k
if !!app && app.include?('/')
name, version = app.split('/')
app_names[[date, name]] ||= 0.0
app_names[[date, name]] += v
end
end
ap app_names
end
desc 'Do all crosschecks of given account.'
task :crosscheck, [:account] do |t, args|
account = args[:account]
Rake::Task["crosscheck:powerdowns"].invoke(account)
Rake::Task["crosscheck:powerups"].invoke(account)
Rake::Task["crosscheck:transfers"].invoke(account)
Rake::Task["crosscheck:vesting_from"].invoke(account)
Rake::Task["crosscheck:vesting_to"].invoke(account)
end
namespace :crosscheck do
desc 'List of accounts grouped by transfer count crosschecked by memo of given account.'
task :transfers, [:account] do |t, args|
exchanges = %w(bittrex poloniex openledger blocktrades deepcrypto8 gopax
binanceexchange teambitwala changelly hitbtc-exchange korbit roomofsatoshi
shapeshiftio)
account = args[:account]
if account.nil? || account == ''
puts 'Account name required.'
exit
elsif exchanges.include? account
puts 'That procedure is not recommended.'
exit
end
all = SteemApi::Tx::Transfer.where(type: 'transfer')
transfers = all.where.not(memo: '')
transfers = transfers.where(to: exchanges)
transfers = if account =~ /%/
table = SteemApi::Tx::Transfer.arel_table
transfers.where(table[:from].matches(account))
else
transfers.where(from: account)
end
crosscheck_transfers = all.where(memo: transfers.select(:memo))
if transfers.none?
puts "No match."
else
from = transfers.pluck(:from).uniq.join(', ')
puts "Accounts grouped by transfer count using common memos as #{from} on common exchanges ..."
ap crosscheck_transfers.group(:from).order('count_all').count(:all)
end
end
desc 'List of accounts grouped by vesting transfers from a given account'
task :vesting_from, [:account] do |t, args|
account = args[:account]
if account.nil? || account == ''
puts 'Account name required.'
exit
end
table = SteemApi::Tx::Transfer.arel_table
all = SteemApi::Tx::Transfer.where(type: 'transfer_to_vesting')
transfers = all.where(table[:from].not_eq(:to))
transfers = transfers.where.not(to: '')
transfers = if account =~ /%/
table = SteemApi::Tx::Transfer.arel_table
transfers.where(table[:from].matches(account))
else
transfers.where(from: account)
end
if transfers.none?
puts "No match."
else
from = transfers.pluck(:from).uniq.join(', ')
puts "Accounts grouped by vesting transfer count from #{from} ..."
ap transfers.group(:to).order('count_all').count(:all)
end
end
desc 'List of accounts grouped by vesting transfers to a given account'
task :vesting_to, [:account] do |t, args|
account = args[:account]
if account.nil? || account == ''
puts 'Account name required.'
exit
end
table = SteemApi::Tx::Transfer.arel_table
all = SteemApi::Tx::Transfer.where(type: 'transfer_to_vesting')
transfers = all.where(table[:from].not_eq(table[:to]))
transfers = transfers.where.not(to: '')
transfers = if account =~ /%/
table = SteemApi::Tx::Transfer.arel_table
transfers.where(table[:to].matches(account))
else
transfers.where(to: account)
end
if transfers.none?
puts "No match."
else
from = transfers.pluck(:to).uniq.join(', ')
puts "Accounts grouped by vesting transfer count to #{from} ..."
ap transfers.group(:from).order('count_all').count(:all)
end
end
desc 'List of accounts grouped by powerdown sums crosschecked by given account.'
task :powerdowns, [:account] do |t, args|
account = args[:account]
if account.nil? || account == ''
puts 'Account name required.'
exit
end
table = SteemApi::Vo::FillVestingWithdraw.arel_table
all = SteemApi::Vo::FillVestingWithdraw.where(table[:from_account].not_eq(table[:to_account]))
powerdowns = if account =~ /%/
all.where(table[:from_account].matches(account))
else
all.where(from_account: account)
end
if powerdowns.none?
puts "No match."
else
from = powerdowns.pluck(:from_account).uniq.join(', ')
puts "Powerdowns grouped by sum from #{from} ..."
ap powerdowns.group(:to_account).
order('sum_try_parse_replace_withdrawn_vests_as_float').
sum("TRY_PARSE(REPLACE(withdrawn, ' VESTS', '') AS float)")
end
end
desc 'List of accounts grouped by powerup sums crosschecked by given account.'
task :powerups, [:account] do |t, args|
account = args[:account]
if account.nil? || account == ''
puts 'Account name required.'
exit
end
table = SteemApi::Vo::FillVestingWithdraw.arel_table
all = SteemApi::Vo::FillVestingWithdraw.where(table[:from_account].not_eq(table[:to_account]))
powerups = if account =~ /%/
all.where(table[:to_account].matches(account))
else
all.where(to_account: account)
end
if powerups.none?
puts "No match."
else
to = powerups.pluck(:to_account).uniq.join(', ')
puts "Powerups grouped by sum to #{to} ..."
ap powerups.group(:from_account).
order('sum_try_parse_replace_withdrawn_vests_as_float').
sum("TRY_PARSE(REPLACE(withdrawn, ' VESTS', '') AS float)")
end
end
end
namespace :rewards do
desc 'Lists author rewards grouped by date.'
task :author, [:symbol, :days_ago, :author] do |t, args|
now = Time.now.utc
symbol = (args[:symbol] || 'SBD').upcase
after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
author = args[:author]
rewards = SteemApi::Vo::AuthorReward
rewards = rewards.where('timestamp > ?', after_timestamp)
rewards = rewards.group('CAST(timestamp AS DATE)')
rewards = rewards.order('cast_timestamp_as_date ASC')
if !!author
if author =~ /%/
rewards = rewards.where("author LIKE ?", author)
else
rewards = rewards.where(author: author)
end
puts "Daily #{author} reward #{symbol} sum grouped by date since #{after_timestamp} ..."
else
puts "Daily reward #{symbol} sum grouped by date since #{after_timestamp} ..."
end
rewards = case symbol
when 'SBD' then rewards.sum(:sbd_payout)
when 'STEEM' then rewards.sum(:steem_payout)
when 'VESTS' then rewards.sum(:vesting_payout)
when 'MVESTS'
rewards.sum('vesting_payout / 1000000')
else; puts "Unknown symbol: #{symbol}. Symbols supported: SBD, STEEM, VESTS, MVESTS"
end
ap rewards
sum = rewards.values.sum
puts "# Total rewards: %.3f %s (average: %.3f per day)" % [sum, symbol, (sum / rewards.size)]
end
desc 'Lists curation rewards grouped by date.'
task :curation, [:symbol, :days_ago] do |t, args|
now = Time.now.utc
symbol = (args[:symbol] || 'MVESTS').upcase
after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
rewards = SteemApi::Vo::CurationReward
rewards = rewards.where('timestamp > ?', after_timestamp)
rewards = rewards.group('CAST(timestamp AS DATE)')
rewards = rewards.order('cast_timestamp_as_date ASC')
puts "Daily curation reward #{symbol} sum grouped by date since #{after_timestamp} ..."
case symbol
when 'VESTS'
ap rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float)")
when 'MVESTS'
ap rewards.sum("TRY_PARSE(REPLACE(reward, ' VESTS', '') AS float) / 1000000")
else; puts "Unknown symbol: #{symbol}. Symbols supported: VESTS, MVESTS"
end
end
end
desc 'Lists proxied grouped by month.'
task :proxied, [:days_ago] do |t, args|
now = Time.now.utc
after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
proxied = SteemApi::Tx::AccountWitnessProxy
proxied = proxied.where('timestamp > ?', after_timestamp)
proxied = proxied.group("FORMAT(timestamp, 'yyyy-MM')", :proxy)
proxied = proxied.order('format_timestamp_yyyy_mm ASC')
puts "Daily proxied grouped by month since #{after_timestamp} ..."
ap proxied.count(:all)
end
desc 'Claimed Rewards'
task :claimed, [:account_name, :days_ago, :symbol] do |t, args|
now = Time.now.utc
account_name = args[:account_name] || '%'
after_timestamp = now - ((args[:days_ago] || '30').to_i * 86400)
symbol = (args[:symbol] || 'vests').downcase.to_sym
claims = SteemApi::Tx::ClaimRewardBalance.where('timestamp > ?', after_timestamp)
claims = if account_name =~ /%/
claims.where('account LIKE ?', account_name)
else
claims.where(account: account_name)
end
claims = case symbol
when :vests then claims.where("reward_vests > 0")
when :mvests then claims.where("reward_vests > 0")
when :steem then claims.where("reward_steem > 0")
when :sbd then claims.where("reward_sbd > 0")
else; raise "Unknown symbol: #{symbol}"
end
claims = claims.group("FORMAT(timestamp, 'yyyy-MM')")
claims = claims.order('format_timestamp_yyyy_mm ASC')
claims = case symbol
when :vests then claims.sum(:reward_vests)
when :mvests then claims.sum('reward_vests / 1000000')
when :steem then claims.sum(:reward_steem)
when :sbd then claims.sum(:reward_sbd)
end
puts "# Claimed rewards in #{symbol.to_s.upcase} sum grouped by month ..."
ap claims
puts "# Total claimed #{symbol}: #{claims.values.sum}"
end
task :balance, [:party_a, :party_b, :symbol] do |t, args|
party_a = args[:party_a]
party_b = args[:party_b]
symbol = args[:symbol].upcase
balance_a = SteemApi::Tx::Transfer.where(to: party_a, from: party_b, amount_symbol: symbol).sum(:amount).to_f
balance_b = SteemApi::Tx::Transfer.where(to: party_b, from: party_a, amount_symbol: symbol).sum(:amount).to_f
puts "#{party_a}: %.3f #{symbol}, difference: %.3f #{symbol}" % [balance_a, (balance_a - balance_b)]
puts "#{party_b}: %.3f #{symbol}, difference: %.3f #{symbol}" % [balance_b, (balance_b - balance_a)]
end
# Doesn't look like this table exists.
# desc 'List conversion SBD conversion request sums grouped by day.'
# task :convert, [:days_ago] do |t, args|
# now = Time.now.utc
# after_timestamp = now - ((args[:days_ago] || '3.5').to_f * 86400)
#
# converts = SteemApi::Vo::FillConvertRequest
# converts = converts.where('timestamp > ?', after_timestamp)
# converts = converts.group('CAST(timestamp AS DATE)')
# converts = converts.order('cast_timestamp_as_date ASC')
#
# puts "Daily conversion requests failled sum grouped by date since #{after_timestamp} ..."
# ap converts.sum(:amount)
# end
desc 'Build a new version of the steem_api gem.'
task :build do
exec 'gem build steem_api.gemspec'
end
desc 'Publish the current version of the steem_api gem.'
task :push do
exec "gem push steem_api-#{SteemApi::VERSION}.gem"
end
# We're not going to yank on a regular basis, but this is how it's done if you
# really want a task for that for some reason.
# desc 'Yank the current version of the steem_api gem.'
# task :yank do
# exec "gem yank steem_api -v #{SteemApi::VERSION}"
# end