Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,8 +78,34 @@ def create_severity_violation_chart(df, age_group=None):
|
|
| 78 |
barmode='stack'
|
| 79 |
)
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
return fig
|
| 82 |
|
|
|
|
| 83 |
def get_top_violations(df, age_group):
|
| 84 |
if age_group == 'All Ages':
|
| 85 |
violations = pd.concat([
|
|
@@ -322,6 +348,17 @@ def main():
|
|
| 322 |
# Create and display chart
|
| 323 |
fig = create_severity_violation_chart(df, selected_age)
|
| 324 |
st.plotly_chart(fig, use_container_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
# Display statistics
|
| 327 |
if selected_age == 'All Ages':
|
|
|
|
| 78 |
barmode='stack'
|
| 79 |
)
|
| 80 |
|
| 81 |
+
# return fig
|
| 82 |
+
return fig, violations # this return is needed for part3
|
| 83 |
+
|
| 84 |
+
# added interactivity plot for part3
|
| 85 |
+
def create_severity_detail_chart(violations, selected_violation):
|
| 86 |
+
# Filter data based on selected violation
|
| 87 |
+
filtered_data = violations[violations['Violation'] == selected_violation]
|
| 88 |
+
|
| 89 |
+
# Create a detailed plot for the selected violation
|
| 90 |
+
fig = px.bar(
|
| 91 |
+
filtered_data,
|
| 92 |
+
x='Severity',
|
| 93 |
+
y='count',
|
| 94 |
+
color='Severity',
|
| 95 |
+
title=f'Severity Level Distribution for Violation: {selected_violation}',
|
| 96 |
+
labels={'count': 'Number of Incidents', 'Severity': 'Severity Level'},
|
| 97 |
+
height=400
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
fig.update_layout(
|
| 101 |
+
xaxis_tickangle=-45,
|
| 102 |
+
legend_title='Severity Level',
|
| 103 |
+
barmode='stack'
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
return fig
|
| 107 |
|
| 108 |
+
|
| 109 |
def get_top_violations(df, age_group):
|
| 110 |
if age_group == 'All Ages':
|
| 111 |
violations = pd.concat([
|
|
|
|
| 348 |
# Create and display chart
|
| 349 |
fig = create_severity_violation_chart(df, selected_age)
|
| 350 |
st.plotly_chart(fig, use_container_width=True)
|
| 351 |
+
|
| 352 |
+
# Interactive selection for linking with the second chart --> for part3
|
| 353 |
+
selected_violation = st.selectbox(
|
| 354 |
+
"Select a Violation Type to View Detailed Severity Levels:",
|
| 355 |
+
options=sorted(violations['Violation'].unique())
|
| 356 |
+
)
|
| 357 |
+
|
| 358 |
+
# Create and display the second detailed chart for the selected violation type --> for part3
|
| 359 |
+
if selected_violation:
|
| 360 |
+
detailed_fig = create_severity_detail_chart(violations, selected_violation)
|
| 361 |
+
st.plotly_chart(detailed_fig, use_container_width=True)
|
| 362 |
|
| 363 |
# Display statistics
|
| 364 |
if selected_age == 'All Ages':
|