Last active
May 25, 2020 20:53
-
-
Save Alrighttt/039a190895f8353b00251f7e7465ba31 to your computer and use it in GitHub Desktop.
needs def_credentials from https://github.com/KMDLabs/pos64staker/blob/master/stakerlib.py
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
#!/usr/bin/env python3 | |
import stakerlib | |
import pdb | |
import time | |
import json | |
import plotly.graph_objects as go | |
from datetime import datetime | |
chain = 'DEX' | |
rpc = stakerlib.def_credentials(chain) | |
all_ntz = {} | |
count_ntz = [] | |
start_hours = int(input('Amount of prev hours:')) | |
now = time.time() | |
top_of_hour = now-(now%3600) | |
start_time = int(top_of_hour - start_hours*3600) | |
blocks = rpc.getblockcount() | |
addresses = [] | |
# might be more efficient to scrap RXL... txids depending on chain | |
while start_time < now: | |
ntz = rpc.scanNotarisationsDB(str(blocks), chain) | |
if ntz and ntz not in count_ntz: | |
count_ntz.append(ntz) | |
tx = rpc.getrawtransaction(ntz['hash'], 2) | |
signers = {} | |
for vin in tx['vin']: | |
signers[vin['address']] = 1 | |
if vin['address'] not in addresses: | |
addresses.append(vin['address']) | |
hour = datetime.utcfromtimestamp(tx['time'] - (tx['time']%3600)).strftime('%Y-%m-%d %H:%M:%S') | |
now = tx['time'] | |
if hour in all_ntz: | |
for i in signers: | |
if i in all_ntz[hour]: | |
all_ntz[hour][i] += 1 | |
else: | |
all_ntz[hour][i] = 1 | |
else: | |
all_ntz[hour] = signers | |
blocks -= 1 | |
x_hours = [] | |
for i in all_ntz: | |
x_hours.append(i) | |
hours = {} | |
for addr in addresses: | |
hours[addr] = [0]*len(x_hours) | |
count = 0 | |
for i in all_ntz: | |
if addr in all_ntz[i]: | |
hours[addr][count] = all_ntz[i][addr] | |
count += 1 | |
bars = [] | |
for addr in addresses: | |
bars.append(go.Bar(name=addr, x=x_hours, y=hours[addr])) | |
fig = go.Figure(data=bars) | |
fig.update_layout(barmode='stack') | |
fig.write_html("/path/to/output.html") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment