Use Jupyter to Visualize your FileCoin Mining.

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.

Enable Proxy in WSL2 on windows 11

I have used windows 11 several weeks ago for work.

There have some reasons for me why from Mac to windows:

1, WSL 2 provide full Linux support

2, Windows Laptop has Nvidia Geforce 3070 GPU and 64GB memory

I was working for blockchain development, such as Filecoin Lotus, Cosmos, Polkadot, BSC, etc.

Though I am going to develop a new chain for our new business.

Cause Windows every reboot, the wsl2 network IP address will be changed. so I need to update the proxy setting, so I can normally work, I am living in China.

#!/bin/bash

host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
echo $host_ip

export ALL_PROXY="socks5://$host_ip:51837"
export HTTP_PROXY="http://$host_ip:1087"
export HTTPS_PROXY="http://$host_ip:1087"
                          

put the above lines in the bash script file, and source it.

If you want to add it into bashrc,

. "$HOME/enable_proxy.sh"

use env command to ensure the proxy settings successfully.