import json from collections import deque from statistics import mean import matplotlib.pyplot as plt from aucoin import config timestamps = [] data = [] with open(config.data_dir.joinpath("statistics/stats.json")) as file: for line in file.readlines(): stat = json.loads(line) d = stat["data"] timestamp = d["blockchain"]["header"]["timestamp"] timestamps.append(timestamp) data.append(d) # remove first 10 data points because the timestamp of the genesis block may cause inaccuracies timestamps = timestamps[10:] data = data[10:] # plot fig, ax1 = plt.subplots() ax1.set_xlabel('timestamp (UTC)') ax1.plot(timestamps, [d["blockchain"]["average_block_timespan"]["since_genesis"] for d in data], 'c--') ax1.set_ylabel('average block timespan since genesis', color='c') ax1.tick_params('y', colors='c') ax2 = ax1.twinx() ax2.plot(timestamps, [d["blockchain"]["header"]["difficulty"] for d in data], 'r-') ax2.set_ylabel('difficulty', color='r') ax2.tick_params('y', colors='r') ax3 = ax1.twinx() ax3.plot(timestamps, [d["blockchain"]["header"]["timespan"] for d in data], 'g.') ax3.set_ylabel('timespan last block', color='g') ax3.tick_params('y', colors='g') # ax4 = ax2.twinx() # ax4.plot(timestamps, [d.hashrate for d in data], 'y-') # ax4.set_ylabel('hashrate', color='y') # ax4.tick_params('y', colors='y') ax5 = ax2.twinx() ax5.plot(timestamps, [d["blockchain"]["average_block_timespan"]["last_100"] for d in data], 'b-') ax5.set_ylabel('average block timespan last 100', color='b') ax5.tick_params('y', colors='b') fig.tight_layout() plt.show()