-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathreport.rb
40 lines (33 loc) · 1.32 KB
/
report.rb
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
class Bot
module Report
REPORT_DEFAULT_ORDER = '1m'
def send_report msg, order = nil, keep: nil
suffix = "Scale: #{coin.scale} #{coin.sym} rewarded/#{coin.hr_unit}/24h."
suffix += "\nTW: count of tracked wallets."
ds = DB[:rewards]
.group(:pool)
.select(:pool)
.select_append{ count(distinct wallet).as :TW }
.where(coin: coin.name)
DB[:intervals_defs].map{ |id| SymMash.new id }.each do |id|
cond = Sequel.case [[{period: id.period}, :rew_mh_day]], nil
ds = ds.select_append{ round(Sequel.cast(percentile_cont(0.5).within_group(cond), :numeric), 2).as id.label }
end
data = ds.all.map{ |d| SymMash.new d }
return if data.blank?
oc = order || REPORT_DEFAULT_ORDER
oc = oc.to_sym
oc = REPORT_DEFAULT_ORDER unless oc.in? data.first.keys
data = data.sort{ |a,b| if a[oc] && b[oc] then b[oc] <=> a[oc] elsif a[oc] then -1 else 1 end }
data.each.with_index do |d, i|
d.pool = "#{i+1}. #{d.pool}"
end
if report_group? msg
delete = 3.minutes if !keep
delete = 1.hour if keep and Time.now.hour % 3 > 0
end
aliases = {pool: "#{coin.name} pool", oc => "▼#{oc}"}
send_ds msg, data, suffix: suffix, delete_both: delete, aliases: aliases
end
end
end