Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
- import time
- from decimal import *
- import json
- import pprint
- import plotly.plotly as py
- from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
- from plotly.graph_objs import *
- pp = pprint.PrettyPrinter(indent=2)
- class Node:
- def __init__(self, uri):
- self.conn = AuthServiceProxy(uri);
- class Chain:
- def __init__(self, short, name, node):
- self.short = short
- self.name = name
- self.node = node
- self.best_block_hash = self.node.conn.getbestblockhash()
- self.best_block = self.node.conn.getblockheader(self.best_block_hash)
- self.height = self.best_block['height']
- def __str__(self):
- return "Chain %s (%s): @%i" % (self.short, self.name, self.height)
- def getblockheader(self, h):
- block_hash = self.node.conn.getblockhash(h)
- block_header = self.node.conn.getblockheader(block_hash)
- return block_header
- def blocktime_histogram(self, delta_h, hist_size=60, hist_seconds_per_bin=60, height=-1):
- if height < 0:
- height = self.height
- hist = [0 for i in range(hist_size)]
- block = self.getblockheader(self.height - delta_h )
- for h in range( height - delta_h + 1, height ):
- old_block = block
- block = self.getblockheader( h )
- block_time = block['time'] - old_block['time']
- hist_index = block_time // hist_seconds_per_bin;
- hist_index = max(min(hist_size-1, hist_index), 0)
- #print ("h=%u #%u: block_time: %u hist_index: %i" % ( h, block['height'], block_time, hist_index ))
- hist[hist_index] += 1
- fig = Figure(
- data = [
- Bar(
- x = [(i*hist_seconds_per_bin/60) for i in range(hist_size)],#.append("%i+" % (hist_size*hist_seconds_per_bin/60),
- y = hist
- )
- ],
- layout = Layout(
- title = "%s block time histogram (blocks #%i - #%i, %i blocks)" % ( self.name, height - delta_h, height, delta_h ),
- xaxis = dict(title='block time (in minutes, based on block header times)'),
- yaxis = dict(title='number of blocks')
- )
- )
- return fig
- xbc = Chain( 'BCC', 'BitcoinCash', Node('http://joebitcoin:<password>@localhost:8332'))
- xbt = Chain( 'BSW', 'BitcoinSegWit', Node('http://joebitcoin:<password>@localhost:8342'))
- delta_h = 2016
- hist_size = 60
- hist_seconds_per_bin = 60
- init_notebook_mode(connected=True)
- iplot(xbc.blocktime_histogram( delta_h, hist_size, hist_seconds_per_bin ))
- iplot(xbt.blocktime_histogram( delta_h, hist_size, hist_seconds_per_bin ))
Advertisement
Add Comment
Please, Sign In to add comment