-
Notifications
You must be signed in to change notification settings - Fork 0
/
p2pool_stats
executable file
·124 lines (101 loc) · 5.39 KB
/
p2pool_stats
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
#!/usr/bin/ruby
require 'time'
require 'net/http'
require 'json'
require 'fileutils'
require 'vcr'
require 'webmock'
FileUtils.mkdir_p('/tmp/vcr')
VCR.configure do |c|
c.hook_into :webmock
c.cassette_library_dir = '/tmp/vcr'
end
class Time
def readable
case self.to_i
when 0 then 'just now'
when 1 then '1 second ago'
when 2..59 then self.to_i.to_s + ' seconds ago'
when 60..119 then '1 minute ago'
when 120..3540 then (self.to_i / 60).to_i.to_s + ' minutes ago'
when 3541..7100 then 'an hour ago'
when 7101..82_800 then ((self.to_i + 99) / 3600).to_i.to_s + ' hours ago'
when 82_801..172_000 then '1 day ago'
else ((self.to_i + 800) / 86_400).to_i.to_s + ' days ago'
end
end
end
xmr_addr = ARGV[0]
p2pool_host = case ARGV[1]
when 'main'
'https://p2pool.observer'
when 'mini'
'https://mini.p2pool.observer'
else
'https://mini.p2pool.observer'
end
info_url = "#{p2pool_host}/api/pool_info"
shares_url = "#{p2pool_host}/api/side_blocks_in_window/#{xmr_addr}?window=8640"
payouts_url = "#{p2pool_host}/api/payouts/#{xmr_addr}"
local_info_file = '/tmp/p2pool_data/local/stratum'
raffle_url = 'https://xmrvsbeast.com/p2pool/stats'
info_res = VCR.use_cassette('info', record: :new_episodes, re_record_interval: 300, match_requests_on: [:method, :host, :path]) do
JSON.parse(Net::HTTP.get(URI(info_url)))
end
shares_res = VCR.use_cassette('shares', record: :new_episodes, re_record_interval: 300, match_requests_on: [:method, :host, :path]) do
JSON.parse(Net::HTTP.get(URI(shares_url))).sort { |a,b| a['side_height'] <=> b['side_height'] }
end
raffle_res = VCR.use_cassette('raffle', record: :new_episodes, re_record_interval: 300, match_requests_on: [:method, :host, :path]) do
JSON.parse(Net::HTTP.get(URI(raffle_url)))
end
cur_time = info_res['sidechain']['timestamp']
cur_pool_effort = info_res['sidechain']['effort']['current']
cur_height = info_res['sidechain']['height']
prev_day = cur_height - 8640
pplns_window = cur_height - info_res['sidechain']['window']['blocks'].to_i
payouts_res = VCR.use_cassette('payouts', record: :new_episodes, re_record_interval: 300, match_requests_on: [:method, :host, :path]) do
JSON.parse(Net::HTTP.get(URI(payouts_url))).sort { |a,b| a['side_height'] <=> b['side_height'] }
end
local_info = JSON.parse(File.readlines(local_info_file).join)
current_shares = shares_res.select { |r| !r.has_key?('uncle_of') && r['side_height'] >= pplns_window }.count
current_uncles = shares_res.select { |r| r.has_key?('uncle_of') && r['side_height'] >= pplns_window }.count
ranges = (prev_day..cur_height).each_slice(72).map do |a|
a.first..a.last
end
window_bar_loc = (prev_day..cur_height).each_slice(72).to_a.size - (info_res['sidechain']['window']['blocks'].to_i / 72) - 1
shares = ranges.map do |range|
shares_res.select { |r| !r.has_key?('uncle_of') && range.include?(r['side_height']) }.count.to_s
end.map { |s| s.gsub(/^[1-9][0-9]+$/, '+').gsub('0', '.') }.insert(window_bar_loc, '|').join
uncles = ranges.map do |range|
shares_res.select { |r| r.has_key?('uncle_of') && range.include?(r['side_height']) }.count.to_s
end.map { |s| s.gsub(/^[1-9][0-9]+$/, '+').gsub('0', '.') }.insert(window_bar_loc, '|').join
payouts = ranges.map do |range|
payouts_res.select { |r| range.include?(r['side_height']) }.count.to_s
end.map { |s| s.gsub(/^[1-9][0-9]+$/, '+').gsub('0', '.') }.insert(window_bar_loc, '|').join
last_share_time = "Last share #{shares_res.last ? Time.at(cur_time - shares_res.last['timestamp']).readable : 'more than 1 day ago'}"
current_shares_info = "Current shares: #{current_shares} (+#{current_uncles} uncles)"
current_effort = "Current effort: #{local_info['current_effort']}%"
ls_size = last_share_time.size
cs_size = current_shares_info.size
ce_size = current_effort.size
total_padding_size_top = 135 - (ls_size + cs_size + ce_size)
padding_sizes_top = if total_padding_size_top.even?
[total_padding_size_top / 2, total_padding_size_top / 2]
else
[total_padding_size_top / 2, total_padding_size_top / 2 + 1]
end
last_payout_time = "Last payout #{payouts_res.last ? Time.at(cur_time - payouts_res.last['timestamp']).readable : 'more than 1 day ago'}"
current_pool_effort = "Current pool effort: #{cur_pool_effort}%"
lp_size = last_payout_time.size
cpe_size = current_pool_effort.size
lp_padding = 134 - (lp_size + cpe_size)
payout_vals = payouts_res.map do |pr|
"#{Time.at(pr.dig('timestamp'))}: #{('%d.%012d' % [pr['coinbase_reward'].to_i / 1_000_000_000_000, pr['coinbase_reward'].to_i % 1_000_000_000_000]).rjust(18)}".rjust(45)
end.reverse
puts "#{last_share_time}#{' ' * padding_sizes_top[0]}#{current_shares_info}#{' ' * padding_sizes_top[1]}#{current_effort} | Last 5 Payouts"
puts "SHARES: [<#{shares}<] | #{payout_vals.dig(0).to_s.rjust(45)} |"
puts "UNCLES: [<#{uncles}<] | #{payout_vals.dig(1).to_s.rjust(45)} |"
puts "PAYOUTS: [<#{payouts}<] | #{payout_vals.dig(2).to_s.rjust(45)} |"
puts "#{' ' * 135} | #{payout_vals.dig(3).to_s.rjust(45)} |"
puts "#{last_payout_time}#{' ' * lp_padding} #{current_pool_effort} | #{payout_vals.dig(4).to_s.rjust(45)} |"
puts "Raffle Winner: #{raffle_res['winner']}, Round Type: #{raffle_res['round_type']} (#{raffle_res['players_round']} players), Time Left: #{raffle_res['time_remain']} minutes, HR: #{raffle_res['bonus_hr']}+#{raffle_res['donate_hr']} kH/s"