Skip to content

Commit

Permalink
Merge pull request #36 from jvivian:jvivian/issue27
Browse files Browse the repository at this point in the history
Choose the start date on the Dashboard for running the model
  • Loading branch information
jvivian authored Feb 21, 2024
2 parents 677c987 + 6f19075 commit 3d8d372
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion coverage.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" ?>
<coverage version="7.3.1" timestamp="1708496031059" lines-valid="147" lines-covered="145" line-rate="0.9864" branches-valid="54" branches-covered="51" branch-rate="0.9444" complexity="0">
<coverage version="7.3.1" timestamp="1708500367269" lines-valid="147" lines-covered="145" line-rate="0.9864" branches-valid="54" branches-covered="51" branch-rate="0.9444" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.3.1 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
Expand Down
23 changes: 7 additions & 16 deletions covid19_drdfm/streamlit/Dashboard.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
import json
import time
from pathlib import Path
Expand Down Expand Up @@ -63,10 +64,12 @@ def get_data():

# State selections
state_sel = st.multiselect("States", df.State.unique(), default=df.State.unique())
c1, c2, c3 = st.columns([0.5, 0.25, 0.25])
c1, c2, c3, c4 = st.columns([0.35, 0.25, 0.20, 0.20])
outdir = c1.text_input("Output Directory", value="./")
mult_sel = c2.slider("Global Multiplier", 0, 4, 2)
maxiter = c3.slider("Max EM Iterations", 1000, 20_000, 10_000, 100)
date_start = c2.date_input("Start Date", value=df.Time.min(), min_value=df.Time.min(), max_value=df.Time.max())
mult_sel = c3.slider("Global Multiplier", 0, 4, 2)
maxiter = c4.slider("Max EM Iterations", 1000, 20_000, 10_000, 100)
df = df[df.Time > date_start.isoformat()]

# Metrics
lengths = [len(selectors[x]) for x in selectors]
Expand Down Expand Up @@ -110,10 +113,7 @@ def get_data():
subdir / "filtered-factors.csv" for subdir in outdir.iterdir() if (subdir / "filtered-factors.csv").exists()
]
dfs = [pd.read_csv(x) for x in filt_paths]
try:
filt_df = pd.concat([x for x in dfs if ~x.empty]).set_index("Time")
except ValueError:
filt_df = pd.DataFrame()
filt_df = pd.concat([x for x in dfs if ~x.empty]).set_index("Time")
filt_df.to_csv(outdir / "filtered-factors.csv")
st.dataframe(filt_df)

Expand All @@ -122,13 +122,4 @@ def get_data():
minutes, seconds = divmod(rem, 60)
st.write(f"Runtime: {int(hours):0>2}H:{int(minutes):0>2}M:{seconds:05.2f}S")

fail_path = outdir / "failed.txt"
if fail_path.exists():
with open(fail_path) as f:
lines = f.readlines()
_, c1, c2, _ = st.columns([0.1, 0.2, 0.6, 0.1])
c1.metric("Failures", value=len(lines))
lines = "\n".join(lines)
c2.warning(f"\t\tFailures Detected\n\n{lines}")

st.balloons()
5 changes: 4 additions & 1 deletion covid19_drdfm/streamlit/pages/1_Factor_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
factor_path = path_to_results / "filtered-factors.csv"
df = pd.read_csv(factor_path, index_col=0)
df["Time"] = df.index
df.index.name = "Time"

filter_list = ["Global", "Unnamed", "Time", "State"]
factor = st.sidebar.selectbox("Factor", [x for x in df.columns if x not in filter_list])
Expand All @@ -40,7 +41,9 @@
columns = [*factor_vars, "State", "Time"]

# Normalize original data for state / valid variables
new = normalize(raw.query("State == @state")[columns].iloc[1:]) # .reset_index(drop=True)
raw = raw.set_index("Time", drop=False)
raw = raw.loc[df.index, :]
new = normalize(raw.query("State == @state")[columns]) # .iloc[1:]) # .reset_index(drop=True)

# Normalize factors and add to new dataframe
if st.sidebar.checkbox("Invert Factor"):
Expand Down

0 comments on commit 3d8d372

Please sign in to comment.