Spaces:
Runtime error
Runtime error
feat: add calculated field
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ with st.sidebar:
|
|
| 17 |
st.text("\n".join(file_names))
|
| 18 |
|
| 19 |
data_dict = dict({'trial_id':[], 'pupil_dilation':[], 'baseline':[], 'rating':[]})
|
| 20 |
-
with st.spinner("
|
| 21 |
for file_data in file_bytes:
|
| 22 |
data = json.loads(file_data)
|
| 23 |
for k in data:
|
|
@@ -28,7 +28,7 @@ with st.spinner("building base dictionary..."):
|
|
| 28 |
df_base = pd.DataFrame() # {'<fields>' : []})
|
| 29 |
with col1:
|
| 30 |
if file_bytes:
|
| 31 |
-
with st.spinner("
|
| 32 |
df_base = pd.DataFrame.from_dict(data_dict)
|
| 33 |
df_base["trial_id"] = df_base.trial_id.map(lambda s: "".join([c for c in s if c.isdigit()]))
|
| 34 |
df_base["len_pupil_dilation"] = df_base.pupil_dilation.map(lambda l: len(l))
|
|
@@ -69,14 +69,26 @@ with col2:
|
|
| 69 |
df_right = st.session_state.df.copy(deep=True)
|
| 70 |
df_right.pupil_dilation = df_right.pupil_dilation.map(lambda ser: [f for f in ser if f != 0.0])
|
| 71 |
df_right.baseline = df_right.baseline.map(lambda ser: [f for f in ser if f != 0.0])
|
| 72 |
-
st.success("
|
| 73 |
st.markdown("After transformation")
|
| 74 |
-
st.dataframe(df_right)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
elif detect_blinking and not number_of_blinks:
|
| 76 |
-
st.caption("
|
| 77 |
|
| 78 |
if not df_base.empty:
|
| 79 |
-
st.warning("
|
| 80 |
|
| 81 |
# for key, value in st.session_state.items():
|
| 82 |
# st.success(f"{key}: {value}")
|
|
|
|
| 17 |
st.text("\n".join(file_names))
|
| 18 |
|
| 19 |
data_dict = dict({'trial_id':[], 'pupil_dilation':[], 'baseline':[], 'rating':[]})
|
| 20 |
+
with st.spinner("Building base dictionary..."):
|
| 21 |
for file_data in file_bytes:
|
| 22 |
data = json.loads(file_data)
|
| 23 |
for k in data:
|
|
|
|
| 28 |
df_base = pd.DataFrame() # {'<fields>' : []})
|
| 29 |
with col1:
|
| 30 |
if file_bytes:
|
| 31 |
+
with st.spinner("Building base dataframe..."):
|
| 32 |
df_base = pd.DataFrame.from_dict(data_dict)
|
| 33 |
df_base["trial_id"] = df_base.trial_id.map(lambda s: "".join([c for c in s if c.isdigit()]))
|
| 34 |
df_base["len_pupil_dilation"] = df_base.pupil_dilation.map(lambda l: len(l))
|
|
|
|
| 69 |
df_right = st.session_state.df.copy(deep=True)
|
| 70 |
df_right.pupil_dilation = df_right.pupil_dilation.map(lambda ser: [f for f in ser if f != 0.0])
|
| 71 |
df_right.baseline = df_right.baseline.map(lambda ser: [f for f in ser if f != 0.0])
|
| 72 |
+
st.success("Blinking values have been removed!")
|
| 73 |
st.markdown("After transformation")
|
| 74 |
+
# st.dataframe(df_right)
|
| 75 |
+
if "baseline" in list(df_right.keys()):
|
| 76 |
+
st.markdown(f"A **baseline** feature has been found on your data, do you want to merge it with **{[k for k in list(df_right.keys()) if k != "baseline"]}** with in a new calculated field?")
|
| 77 |
+
relative_key = f"relative_{[k for k in list(df_right.keys()) if k != "baseline"][0]}"
|
| 78 |
+
add_relative = st.button(f"Add {relative_key}")
|
| 79 |
+
if add_relative:
|
| 80 |
+
baseline_mean = [sum(s)/len(s) for s in df['baseline']]
|
| 81 |
+
df_right['relative_pupil_dilation'] = [df['pupil_dilation'][i] - baseline_mean[i] for i in range(len(df))]
|
| 82 |
+
st.markdown("After adding calculated fields")
|
| 83 |
+
st.dataframe(df_right)
|
| 84 |
+
with open('myfile.csv') as f:
|
| 85 |
+
st.download_button('Download CSV', f)
|
| 86 |
+
st.info("Your data has been downloaded, you can visualize and detect outliers in the 'Plotting' and 'Detect Outliers' pages on the sidebar.")
|
| 87 |
elif detect_blinking and not number_of_blinks:
|
| 88 |
+
st.caption("No blinking values were found in your data!")
|
| 89 |
|
| 90 |
if not df_base.empty:
|
| 91 |
+
st.warning("Consider running outlier detection to clean your data!", icon="⚠️")
|
| 92 |
|
| 93 |
# for key, value in st.session_state.items():
|
| 94 |
# st.success(f"{key}: {value}")
|