-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddresses.rb
executable file
·154 lines (111 loc) · 3.22 KB
/
addresses.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
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
#!/usr/bin/env ruby
require 'bigdecimal'
private
def page addresses, segment_size
length = addresses.length
segment = 0
while length >= segment * segment_size
first = segment * segment_size
last = ( ( segment + 1 ) * segment_size ) - 1
yield addresses[ first..last ]
segment += 1
end
end
def read_addresses
@all_addresses = [ ]
@more_than_single_satoshi_addresses = [ ]
ARGF.each_line do |line|
entry = line.chomp
address, text_amount = entry.split /\s+/
amount = BigDecimal text_amount
address = { :address => address,
:amount => amount }
@all_addresses << address
print '.'
end
puts
puts 'Reversing...'
puts
@all_addresses.reverse!
end
def all_addresses
@all_addresses
end
SATOSHI = BigDecimal '0.00000001'
def more_than_single_satoshi_addresses
all_addresses.reject { |a| a[:amount] == SATOSHI }
end
def sum_amounts addresses
addresses.collect { |a| a[:amount] }.reduce :+
end
def format amount, precision=8
total = 9 + precision
"%#{total}.#{precision}f" % amount
end
def segment_size addresses
addresses.length / 10 + 1
end
def segmentize addresses
page_size = segment_size addresses
page( addresses, page_size ) do |page_of_addresses|
sum = sum_amounts page_of_addresses
min = page_of_addresses.first[:amount]
max = page_of_addresses.last[:amount]
yield sum, min, max
end
end
def render addresses, divided_addresses
overall_sum = sum_amounts addresses
puts ' ---------------------------------------------------------------------------------------------------'
puts '| Total | Percentage | Average | Min | Max |'
puts ' ---------------------------------------------------------------------------------------------------'
segmentize( divided_addresses ) do | sum, min, max |
amount = format sum
percentage = format ( sum / overall_sum ) * 100
average = format sum / segment_size( divided_addresses )
minimum = format min
maximum = format max
puts "| #{amount} | #{percentage} | #{average} | #{minimum} | #{maximum} |"
end
puts ' ---------------------------------------------------------------------------------------------------'
puts
end
def render_top addresses, percentage
top_index = addresses.length * percentage
render addresses, addresses[ -top_index..-1 ]
end
def run_top_hundred addresses
puts 'Top 100%'
render_top addresses, 1
end
def run_top_ten addresses
puts 'Top 10%'
render_top addresses, 0.1
end
def run_top_one addresses
puts 'Top 1%'
render_top addresses, 0.01
end
def run_with_single_satoshi
puts 'With single satoshi addresses'
puts '-----------------------------'
puts
run_top_hundred all_addresses
run_top_ten all_addresses
run_top_one all_addresses
end
def run_without_single_satoshi
puts 'Without single satoshi addresses'
puts '--------------------------------'
puts
run_top_hundred more_than_single_satoshi_addresses
run_top_ten more_than_single_satoshi_addresses
run_top_one more_than_single_satoshi_addresses
end
def run_reports
run_with_single_satoshi
run_without_single_satoshi
end
public
read_addresses
run_reports