forked from kylemcdonald/ethereum-emissions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlabel_blocks.py
36 lines (29 loc) · 1.06 KB
/
label_blocks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import datetime
from collections import defaultdict
from block_index import BlockIndex
from block_classifier import BlockClassifier
from tqdm import tqdm
import pandas as pd
import numpy as np
index = BlockIndex(read_only=True)
classifier = BlockClassifier()
block_labels = defaultdict(lambda: defaultdict(int))
total = index.latest_block() - 1
for block in tqdm(index.list_blocks(skip_genesis=True), total=total):
date = block.get_datetime().date()
# first, try to label the block based on the extra data
label = classifier.classify_extra_data(block.extra_data)
if label is not None:
label = 'extraData:' + label
else:
# if that doesn't work, label it based on the pool
label = classifier.classify_miner(block.miner)
if label is not None:
label = 'pool:' + label
# if neither work, call it 'unknown'
if label is None:
label = 'unknown'
block_labels[date][label] += 1
df = pd.DataFrame(block_labels).T.sort_index()
df.index.name = 'Date'
df.to_csv('output/block-labels.csv', float_format='%.0f')