As we know, Jupyter is an awesome tool for academics, AI, Data scientists, etc.
When I run some nodes for the IPFS filecoin ecosystem, some Data I need to know, data visualization is more clear for us.
So I use jupyter, cause I used it when we do quant-trading. everything is similar.
This time, I used jupyter docker image to host service on my server.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib3
import json
import datetime
from datetime import datetime
from datetime import date
from matplotlib import pyplot as plt
import numpy as np
import math
import pandas as pd
import pytz
%matplotlib inline
def loadFilDataFromFilfox():
http = urllib3.PoolManager()
sectors_data = []
df = pd.DataFrame(columns=['times', 'event'])
for i in range(30):
api_url = 'https://filfox.info/api/v1/address/{YOUR_FIL_ACCOUNT}/messages?pageSize=100&page=' + str(i)
r = http.request('GET', api_url)
if r.status == 200:
block_data = json.loads(r.data)
# print(block_data['messages'])
sectors_data.extend(block_data['messages'])
print('loading {:.0f} %'.format(((i+1)/30)*100))
hour = None
times = 0
index = 0
for blk in sectors_data:
df.loc[index] = [datetime.fromtimestamp(blk['timestamp'],pytz.timezone("Asia/ShangHai")), blk['method']]
index += 1
my_date = datetime.now(pytz.timezone('Asia/Shanghai'))
df = df.loc[df['times'].dt.day == my_date.day]
prove_df = df.loc[df['event'] == 'ProveCommitSector']
pre_df = df.loc[df['event'] == 'PreCommitSector']
plt.figure(figsize=(20, 10))
ax = (pre_df['event'].groupby(pre_df['times'].dt.hour)
.count()).plot(kind="bar", grid=True, color='purple')
ax.set_facecolor('#eeeeee')
ax.set_xlabel("hour of the day")
ax.set_ylabel("PreCommit Sectors")
ax.set_title(str(date.today()) + ' PreCommit Sectors Figure: ' + str(len(pre_df)) + ' Sectors')
ax.bar_label(ax.containers[0], size=18)
plt.show()
plt.figure(figsize=(20, 10))
ax = (prove_df['event'].groupby(prove_df['times'].dt.hour)
.count()).plot(kind="bar", color='orange', grid=True)
ax.set_facecolor('#eeeeee')
ax.set_xlabel("hour of the day")
ax.set_ylabel("Proved Sectors")
ax.set_title(str(date.today()) + ' Proved Sectors Figure: ' + str(len(prove_df)) + ' Sectors')
ax.bar_label(ax.containers[0], size=18, color='blue')
plt.show()
loadFilDataFromFilfox()


Visualize yourself mining process data.