Files
  • main.py
main.py
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
import requests


def getstat():
    r = requests.get('https://stats.masternode.me/network-report/latest/json')
    return r.json()

def selection_probability(mns, blocks):
    p_pool = mns / 10
    p_prob = 1.0 - ((float(p_pool-1)/float(p_pool)) ** float(blocks))
    return "{:0.4f}%".format(p_prob * 100)

    
    
if __name__ == '__main__':
    print
    print 'getting current masternode count...'
    try:
        api = getstat()
        r = api['raw']
        masternode_count = r['mn_count_enabled']
        block_year = r['block_date'][:4]
        blocks_per_hour = r['avg_blocktimes'][block_year]['per_hr']
    except (requests.ConnectionError, KeyError):
        print 'stats api down.'
        print 'using made up masternode count of 5000'
        masternode_count = 5000
    print
    print 'using %d current active masternodes' % masternode_count
    print 'estimated proababilities of selection are'
    print
    print '{0:>2} {1:>2} {2:>8} {3:>8}'.format("days","hours","blocks","prob")
    for hour in [ 1, 2, 3, 4, 6, 8, 10, 12, 18, 24, 30, 36, 42, 48, 72, 96, 120, 144, 168, 192, 216 ]:
        blocks = int(blocks_per_hour * hour)
        day = float(hour) / 24.0
        print '{0:>.2f} {1:>5} {2:>8} {3:>8}'.format(day, hour, blocks, selection_probability(masternode_count, blocks))
Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.8.2] on linux