Skip to content

Commit

Permalink
ux cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
daviidarr committed Apr 3, 2024
1 parent dc712ef commit 136723b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
33 changes: 8 additions & 25 deletions pnl_explain.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,12 @@
pd.options.mode.chained_assignment = None
st.session_state.parameters = load_parameters()

st.session_state.debank_key = st.sidebar.text_input("debank key",
value=st.session_state.parameters['profile'][
'debank_key'] if 'debank_key' in st.session_state.parameters[
'profile'] else '',
help="you think i am going to pay for you?")
addresses = st.sidebar.text_area("addresses",
value=st.session_state.parameters['profile']['addresses'] if 'addresses' in
st.session_state.parameters[
'profile'] else '',
help='Enter multiple strings, like a list')
addresses = [address for address in eval(addresses) if address[:2] == "0x"]

if (st.session_state['debank_key'] == '') or (not addresses):
st.warning("Please enter your debank key and addresses")
st.stop()

# tamper with the db file name to add hash of debank key
hashed_debank_key = st.session_state.debank_key
plex_db_params = copy.deepcopy(st.session_state.parameters['input_data']['plex_db'])
plex_db_params['remote_file'] = plex_db_params['remote_file'].replace('.db', f'_{hashed_debank_key}.db')

# TODO: no pb reloading each time ? bc of sql
if 'plex_db' not in st.session_state:
# tamper with the db file name to add debank key
plex_db_params = copy.deepcopy(st.session_state.parameters['input_data']['plex_db'])
plex_db_params['remote_file'] = plex_db_params['remote_file'].replace('.db',
f"_{st.session_state.parameters['profile']['debank_key']}.db")
st.session_state.plex_db: PlexDB = SQLiteDB(plex_db_params, st.secrets)
raw_data_db: RawDataDB = RawDataDB.build_RawDataDB(st.session_state.parameters['input_data']['raw_data_db'], st.secrets)
st.session_state.api = DebankAPI(raw_data_db, st.session_state.plex_db)
Expand All @@ -59,8 +42,8 @@
with st.sidebar.form("snapshot_form"):
refresh = st.form_submit_button("fetch from debank", help="fetch from debank costs credits !")

snapshots = asyncio.run(safe_gather([st.session_state.api.position_snapshot(address, debank_key=st.session_state.debank_key, refresh=refresh)
for address in addresses],
snapshots = asyncio.run(safe_gather([st.session_state.api.position_snapshot(address, debank_key=st.session_state.parameters['profile']['debank_key'], refresh=refresh)
for address in st.session_state.parameters['profile']['addresses']],
n=st.session_state.parameters['run_parameters']['async']['gather_limit']))
if refresh:
st.session_state.plex_db.upload_to_s3()
Expand Down Expand Up @@ -116,7 +99,7 @@
# fetch data from db
start_list = {}
end_list = {}
for address in addresses:
for address in st.session_state.parameters['profile']['addresses']:
data = st.session_state.plex_db.query_start_end_snapshots(address, start_datetime, end_datetime)
start_list[address] = data['start_snapshot']
end_list[address] = data['end_snapshot']
Expand Down Expand Up @@ -150,7 +133,7 @@
with history_tab:
# snapshots
snapshots_within = pd.concat([st.session_state.plex_db.query_snapshots_within(address, start_datetime, end_datetime)
for address in addresses], axis=0, ignore_index=True)
for address in st.session_state.parameters['profile']['addresses']], axis=0, ignore_index=True)
# explains btw snapshots
explains = []
for start, end in zip(
Expand Down
32 changes: 26 additions & 6 deletions utils/streamlit_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,35 @@


def load_parameters() -> dict:
with open(os.path.join(os.sep, os.getcwd(), "config", 'params.yaml'), 'r') as fp:
defaults = yaml.safe_load(fp)

with open('temp.yaml', 'w') as file:
yaml.dump(defaults, file)
with open('temp.yaml', "rb") as file:
st.sidebar.download_button(
label="Download parameters template",
data=file,
file_name='temp.yaml',
mime='yaml',
)

if parameter_file := st.sidebar.file_uploader("upload parameters", type=['yaml']):
result = yaml.safe_load(parameter_file)
return yaml.safe_load(parameter_file)
elif 'parameters' not in st.session_state:
with open(os.path.join(os.sep, os.getcwd(), "config", 'params.yaml'), 'r') as fp:
result = yaml.safe_load(fp)
else:
result = st.session_state.parameters
defaults['profile'] = {'debank_key': st.sidebar.text_input("debank key",
help="you think i am going to pay for you?")}
addresses = st.sidebar.text_area("addresses",
help='Enter multiple strings, like a list')

return result
if (defaults['profile']['debank_key'] == '') or (not addresses):
st.warning("Please enter your debank key and addresses")
st.stop()

defaults['profile']['addresses'] = [address for address in eval(addresses) if address[:2] == "0x"]
return defaults
else:
return st.session_state.parameters


def prompt_plex_interval():
Expand Down

0 comments on commit 136723b

Please sign in to comment.