Skip to content

Instantly share code, notes, and snippets.

"""
This script converts a properly formatted CSV file to a JSON list.
The CSV must have the `Project ID` in the first column and `OP Amount` in the second column.
The `Project ID` can be found at the end of the voting URL, eg:
https://vote.optimism.io/retropgf/3/application/0xd730a803f5714c7f1b5e518edd57121d1b64c8c91cf611ae5f226cf9bb4b963f
https://round3.optimism.io/projects/0xd730a803f5714c7f1b5e518edd57121d1b64c8c91cf611ae5f226cf9bb4b963f
`Project ID` = 0xd730a803f5714c7f1b5e518edd57121d1b64c8c91cf611ae5f226cf9bb4b963f
@ccerv1
ccerv1 / RPGF3_projects_on_EAS.py
Created November 4, 2023 09:06
Approved RPGF3 projects on EAS
import json
import os
import requests
PROJECT_APP_SCHEMA = "0x76e98cce95f3ba992c2ee25cef25f756495147608a3da3aa2e5ca43109fe77cc"
PROJECT_REVIEW_SCHEMA = "0xebbf697d5d3ca4b53579917ffc3597fb8d1a85b8c6ca10ec10039709903b9277"
REVIEWER_ADDRESS = "0x621477dBA416E12df7FF0d48E14c4D20DC85D7D9"
DATA_EXPORT_JSON = "rpgf3_applicant_data.json"
@ccerv1
ccerv1 / RPGF3_attestation_fetcher.py
Last active October 23, 2023 17:26
RPGF3 Attestations
import json
import os
import requests
EAS_SCHEMA = "0x76e98cce95f3ba992c2ee25cef25f756495147608a3da3aa2e5ca43109fe77cc"
START_TIME = 0
RAW_APPLICANT_JSON = "raw_applicant_data.json"
CLEANED_APPLICANT_JSON = "cleaned_applicant_data.json"
@ccerv1
ccerv1 / plot_real_nominal_prices.py
Created August 15, 2019 13:48
Plot real and nominal prices in the same graph
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(20,8))
df.plot(kind='line', y=['C Market (Real)', 'C Market (Nominal)'], ax=ax)
current_price = df.iloc[-1]['C Market (Nominal)']
ax.axhline(current_price, color='black')
@ccerv1
ccerv1 / real_c_prices.py
Created August 15, 2019 13:46
Convert nominal to real coffee prices
df['C Market (Real)'] = df['C Market'] * df['FX Index'] * df['Inflation Index']
df.rename(columns={'C Market': 'C Market (Nominal)'}, inplace=True)
@ccerv1
ccerv1 / index_annual_rate_to_date.py
Created August 15, 2019 13:43
Converts annualized rates to daily rates, and indexes them to a given date
def index_annual_rate_to_date(date, series):
daily_rate = (1 + series/100) ** (1/365)
cumulative_rate = daily_rate.sort_index(ascending=False).cumprod()
return index_to_date(date, cumulative_rate)
df['Inflation Index'] = index_annual_rate_to_date(index_date, df['Inflation'])
df.plot(kind='line', y=['Inflation', 'Inflation Index'], secondary_y='Inflation')
@ccerv1
ccerv1 / index_to_date.py
Created August 15, 2019 13:38
Takes a date we want to index to and a series of values, and returns a new series that shows the ratio of historical values to the current (or indexed) value
index_date = datetime(2019,3,31)
def index_to_date(date, series):
index_val = series.loc[date]
indexed_series = series / index_val
return indexed_series
df['FX Index'] = index_to_date(index_date, df['FX'])
df.plot(kind='line', y=['FX', 'FX Index'], secondary_y='FX', alpha=.5)
@ccerv1
ccerv1 / format_real_price_df.py
Created April 26, 2019 05:34
Apply some formatting so our table looks nice
df.set_index('Date', inplace=True)
df.rename(columns={
'Value_x': 'FX',
'Value_y': 'Inflation',
'CLOSE': 'C Market'
}, inplace=True)
@ccerv1
ccerv1 / merge_asof_real_prices.py
Created April 26, 2019 05:32
Merges are three datasets onto a continuous date series
df = pd.merge_asof(continuous_dates, currency[['Date', 'Value']], on='Date', direction='nearest')
df = pd.merge_asof(df, inflation[['Date', 'Value']], on='Date', direction='forward')
df = pd.merge_asof(df, prices[['Date', 'CLOSE']], on='Date', direction='backward')
@ccerv1
ccerv1 / continuous_date_series.py
Created April 26, 2019 05:27
Create a DataFrame with a continuous series of dates
from datetime import timedelta
start_date = datetime(1999, 4, 1)
end_date = datetime(2019, 3, 31)
this_date = start_date
date_range = []
while this_date <= end_date:
date_range.append(this_date)
this_date += timedelta(1)