Created
December 31, 2018 01:32
-
-
Save macterra/dae15a529b58e17cab83a00dd664c39e to your computer and use it in GitHub Desktop.
Calculate mean and stdev for most recent 1000 block times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException | |
from datetime import datetime | |
from dateutil import tz | |
import numpy | |
N = 1000 | |
rpc_connection = AuthServiceProxy("http://[name]:[pass]@127.0.0.1:8332") | |
best_block_hash = rpc_connection.getbestblockhash() | |
tip = rpc_connection.getblock(best_block_hash) | |
max = tip["height"] | |
commands = [ [ "getblockhash", height] for height in range(max-N, max) ] | |
block_hashes = rpc_connection.batch_(commands) | |
blocks = rpc_connection.batch_([ [ "getblock", h ] for h in block_hashes ]) | |
block_times = [ block["time"] for block in blocks ] | |
times = numpy.diff(block_times) | |
print("block times avg={:.2f} std={:.2f}".format(numpy.mean(times), numpy.std(times))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment