-
Notifications
You must be signed in to change notification settings - Fork 5
/
label_blocks.py
46 lines (39 loc) · 1.46 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
37
38
39
40
41
42
43
44
45
46
import datetime
from dateutil import tz
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
using_metadata_snapshot = True
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):
dt = block.get_datetime()
if using_metadata_snapshot:
# metadata snapshot is in los angeles timezone
dt.replace(tzinfo=tz.gettz('America/Los_Angeles'))
else:
# any data from a local copy will be in the local timezone
dt.replace(tzinfo=tz.tzlocal())
dt = dt.astimezone(tz.tzutc()) # convert from database time to UTC time
date = dt.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')