forked from netuoso/steem_api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRakefile
More file actions
288 lines (244 loc) · 9.65 KB
/
Rakefile
File metadata and controls
288 lines (244 loc) · 9.65 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
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']
end
task :default => :test
task :console do
exec "irb -r steem_api -I ./lib"
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 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 '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)
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(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] do |t, args|
now = Time.now.utc
symbol = (args[:symbol] || 'SBD').upcase
after_timestamp = now - ((args[:days_ago] || '7').to_i * 86400)
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')
puts "Daily author reward #{symbol} sum grouped by date since #{after_timestamp} ..."
case symbol
when 'SBD' then ap rewards.sum(:sdb_payout)
when 'STEEM' then ap rewards.sum(:steem_payout)
when 'VESTS' then ap rewards.sum(:vesting_payout)
when 'MVESTS'
ap rewards.sum('vesting_payout / 1000000')
else; puts "Unknown symbol: #{symbol}. Symbols supported: SBD, STEEM, VESTS, MVESTS"
end
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
# 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