Skip to content

Instantly share code, notes, and snippets.

@timbeiko
Created July 17, 2022 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timbeiko/c46ff87b5007352800ad048e2a868d43 to your computer and use it in GitHub Desktop.
Save timbeiko/c46ff87b5007352800ad048e2a868d43 to your computer and use it in GitHub Desktop.
Goerli TTD Estimations
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.')
@timbeiko
Copy link
Author

Output from lines 34-37 using these blocks:

1.4346965929656057
1.71
1.28
Processed 1001840 lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment