Update app.py
Browse files
app.py
CHANGED
|
@@ -141,11 +141,16 @@ def main():
|
|
| 141 |
# Read the Excel file into a DataFrame
|
| 142 |
df = pd.read_excel(uploaded_file)
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
# Replace student names with initials
|
| 145 |
df = replace_student_names_with_initials(df)
|
| 146 |
|
| 147 |
st.subheader("Uploaded Data")
|
| 148 |
-
st.write(df)
|
| 149 |
|
| 150 |
# Ensure expected column is available
|
| 151 |
if INTERVENTION_COLUMN not in df.columns:
|
|
@@ -158,10 +163,14 @@ def main():
|
|
| 158 |
# Compute Intervention Session Statistics
|
| 159 |
intervention_stats = compute_intervention_statistics(df)
|
| 160 |
st.subheader("Intervention Session Statistics")
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
# Add download button for Intervention Session Statistics chart
|
| 167 |
download_chart(intervention_fig, "intervention_statistics_chart.png")
|
|
@@ -232,12 +241,12 @@ def compute_intervention_statistics(df):
|
|
| 232 |
intervention_frequency = (sessions_held / total_days) * 100 if total_days > 0 else 0
|
| 233 |
intervention_frequency = round(intervention_frequency, 2)
|
| 234 |
|
| 235 |
-
#
|
| 236 |
stats = {
|
| 237 |
-
'
|
| 238 |
'Intervention Sessions Held': [sessions_held],
|
| 239 |
'Intervention Sessions Not Held': [sessions_not_held],
|
| 240 |
-
'
|
| 241 |
}
|
| 242 |
stats_df = pd.DataFrame(stats)
|
| 243 |
return stats_df
|
|
@@ -248,17 +257,16 @@ def plot_intervention_statistics(intervention_stats):
|
|
| 248 |
sessions_not_held = intervention_stats['Intervention Sessions Not Held'].values[0]
|
| 249 |
|
| 250 |
fig, ax = plt.subplots()
|
| 251 |
-
ax.bar(['Intervention Sessions'], [sessions_not_held], label='Not Held', color='#
|
| 252 |
-
ax.bar(['Intervention Sessions'], [sessions_held], bottom=[sessions_not_held], label='Held', color='#
|
| 253 |
|
| 254 |
-
# Display
|
| 255 |
ax.text(0, sessions_not_held / 2, str(sessions_not_held), ha='center', va='center', color='white')
|
| 256 |
ax.text(0, sessions_not_held + sessions_held / 2, str(sessions_held), ha='center', va='center', color='black')
|
| 257 |
|
| 258 |
-
|
| 259 |
-
ax.
|
| 260 |
ax.legend()
|
| 261 |
-
|
| 262 |
st.pyplot(fig)
|
| 263 |
|
| 264 |
return fig
|
|
|
|
| 141 |
# Read the Excel file into a DataFrame
|
| 142 |
df = pd.read_excel(uploaded_file)
|
| 143 |
|
| 144 |
+
# Format "Date of Session" and "Timestamp"
|
| 145 |
+
df['Date of Session'] = pd.to_datetime(df['Date of Session']).dt.strftime('%m/%d/%Y')
|
| 146 |
+
df['Timestamp'] = pd.to_datetime(df['Timestamp']).dt.strftime('%I:%M %p')
|
| 147 |
+
df = df[['Date of Session', 'Timestamp'] + [col for col in df.columns if col not in ['Date of Session', 'Timestamp']]]
|
| 148 |
+
|
| 149 |
# Replace student names with initials
|
| 150 |
df = replace_student_names_with_initials(df)
|
| 151 |
|
| 152 |
st.subheader("Uploaded Data")
|
| 153 |
+
st.write(df)
|
| 154 |
|
| 155 |
# Ensure expected column is available
|
| 156 |
if INTERVENTION_COLUMN not in df.columns:
|
|
|
|
| 163 |
# Compute Intervention Session Statistics
|
| 164 |
intervention_stats = compute_intervention_statistics(df)
|
| 165 |
st.subheader("Intervention Session Statistics")
|
| 166 |
+
|
| 167 |
+
# Two-column layout for the visualization and intervention frequency
|
| 168 |
+
col1, col2 = st.columns(2)
|
| 169 |
+
with col1:
|
| 170 |
+
intervention_fig = plot_intervention_statistics(intervention_stats)
|
| 171 |
+
with col2:
|
| 172 |
+
intervention_frequency = intervention_stats['Intervention Frequency (%)'].values[0]
|
| 173 |
+
st.markdown(f"<h1 style='color: #358E66;'>{intervention_frequency}%</h1>", unsafe_allow_html=True)
|
| 174 |
|
| 175 |
# Add download button for Intervention Session Statistics chart
|
| 176 |
download_chart(intervention_fig, "intervention_statistics_chart.png")
|
|
|
|
| 241 |
intervention_frequency = (sessions_held / total_days) * 100 if total_days > 0 else 0
|
| 242 |
intervention_frequency = round(intervention_frequency, 2)
|
| 243 |
|
| 244 |
+
# Reorder columns as specified
|
| 245 |
stats = {
|
| 246 |
+
'Intervention Frequency (%)': [intervention_frequency],
|
| 247 |
'Intervention Sessions Held': [sessions_held],
|
| 248 |
'Intervention Sessions Not Held': [sessions_not_held],
|
| 249 |
+
'Total Number of Days Available': [total_days]
|
| 250 |
}
|
| 251 |
stats_df = pd.DataFrame(stats)
|
| 252 |
return stats_df
|
|
|
|
| 257 |
sessions_not_held = intervention_stats['Intervention Sessions Not Held'].values[0]
|
| 258 |
|
| 259 |
fig, ax = plt.subplots()
|
| 260 |
+
ax.bar(['Intervention Sessions'], [sessions_not_held], label='Not Held', color='#91D6B8')
|
| 261 |
+
ax.bar(['Intervention Sessions'], [sessions_held], bottom=[sessions_not_held], label='Held', color='#358E66')
|
| 262 |
|
| 263 |
+
# Display values on the bars
|
| 264 |
ax.text(0, sessions_not_held / 2, str(sessions_not_held), ha='center', va='center', color='white')
|
| 265 |
ax.text(0, sessions_not_held + sessions_held / 2, str(sessions_held), ha='center', va='center', color='black')
|
| 266 |
|
| 267 |
+
# Update chart settings
|
| 268 |
+
ax.set_ylabel('Frequency')
|
| 269 |
ax.legend()
|
|
|
|
| 270 |
st.pyplot(fig)
|
| 271 |
|
| 272 |
return fig
|