Skip to content

Commit

Permalink
shitty bugfixes, will clean up later
Browse files Browse the repository at this point in the history
  • Loading branch information
jvivian committed May 27, 2024
1 parent 78c4b1d commit b08fb3d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion covid19_drdfm/streamlit/Dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def get_data():
filt_df = pd.concat([x for x in dfs if ~x.empty]).set_index("Time")
filt_df.to_csv(outdir / "factors.csv")
st.dataframe(filt_df)
model.ad.write(outdir / "data.h5ad")
# model.ad.write(outdir / "data.h5ad")
st.balloons()
except ValueError:
st.error(f"No runs succeeded!! Check failures.txt in {outdir}")
Expand Down
24 changes: 16 additions & 8 deletions covid19_drdfm/streamlit/pages/1_Factor_Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ def normalize(df):
path_to_results = Path(
st.text_input("Path to results", value="./covid19_drdfm/data/example-data/test-all-global-1_2019")
)
factor_path = path_to_results / "filtered-factors.csv"
factor_path = path_to_results / "factors.csv"
df = pd.read_csv(factor_path, index_col=0)
df["Time"] = df.index
df.index.name = "Time"
cols_to_drop = [x for x in df.columns if "Time." in x]
df = df.drop(columns=cols_to_drop)

filter_list = ["Unnamed", "Time", "State"]
factor = st.sidebar.selectbox("Factor", [x for x in df.columns if x not in filter_list and "Global" not in x])
Expand All @@ -55,22 +57,28 @@ def normalize(df):
valid_cols = pd.read_csv(state_subdir / "df.csv").columns
# valid_cols = [x for x in valid_cols i]
break
factor_vars = [x for x in FACTORS_GROUPED[factor] if x in valid_cols]

# Get factors and columns
factor_vars = [x for x in FACTORS_GROUPED[factor.split("_")[1]] if x in valid_cols]
columns = [*factor_vars, "State", "Time"]

# Normalize original data for state / valid variables
raw = raw.set_index("Time", drop=False)
new = normalize(raw[raw.State == state][columns]).set_index("Time", drop=False)
new = normalize(raw[raw.State == state][columns])

# Normalize factors and add to new dataframe
if st.sidebar.checkbox("Invert Factor"):
df[factor] = df[factor] * -1
df = normalize(df[df.State == state]).set_index("Time", drop=False) # .reset_index(drop=True)
new = new.loc[df.index, :]
new[factor] = list(df[factor])
df = normalize(df[df.State == state]).reset_index(drop=True)

# Coerce time bullshit to get dates standardized
df["Time"] = pd.to_datetime(df["Time"]).dt.date
new["Time"] = pd.to_datetime(new["Time"]).dt.date
df = df[[factor, "Time"]].merge(new, on="Time")
with st.expander("Graph Data"):
st.dataframe(df)

# Melt into format for plotting
melted_df = new.drop(columns="State").melt(id_vars=["Time"], value_name="value")
melted_df = df.drop(columns="State").melt(id_vars=["Time"], value_name="value")
melted_df["Label"] = [5 if x == factor else 1 for x in melted_df.variable]

# Plot
Expand Down

0 comments on commit b08fb3d

Please sign in to comment.