Created
July 17, 2022 16:58
-
-
Save timbeiko/c46ff87b5007352800ad048e2a868d43 to your computer and use it in GitHub Desktop.
Goerli TTD Estimations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
with open('goerli_td_1m.csv') as csv_file: | |
csv_reader = csv.reader(csv_file, delimiter=',') | |
line_count = 0 | |
avg = 0.0 # Average difficulty added per block | |
deltas = [] # List of added difficulty per block | |
# Calculate average over the entire set, and convert deltas column to a list | |
for row in csv_reader: | |
if line_count == 0: | |
print(f'Column names are {", ".join(row)}') | |
line_count += 1 | |
else: | |
deltas.append(float(row[2])) | |
prev_avg = avg | |
avg += (float(row[2]) - prev_avg) / line_count | |
line_count +=1 | |
# Calculate rolling averages over 50k block windows | |
win_size = 50000 | |
i = 0 | |
avgs = [] | |
while i < len(deltas) - win_size +1: | |
win = deltas[i : i + win_size] | |
win_avg = round(sum(win) / win_size, 2) | |
avgs.append(win_avg) | |
i += 1 | |
if i % 10000 == 0: | |
print(i) | |
# Print data | |
print(avgs) | |
print(avg) # Average difficulty added per block | |
print(max(avgs)) # Maximum average difficulty added over a 50k window | |
print(min(avgs)) # Minimum average difficulty added over a 50k window | |
print(f'Processed {line_count} lines.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output from lines 34-37 using these blocks: