Spaces:
Sleeping
Sleeping
add write up
Browse files
app.py
CHANGED
@@ -303,7 +303,26 @@ def create_category_distribution_chart(df, selected_category, selected_year):
|
|
303 |
return fig
|
304 |
|
305 |
def main():
|
306 |
-
st.title('Traffic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
# Load data
|
309 |
df = load_and_preprocess_data('1.08_Crash_Data_Report_(detail).csv')
|
@@ -361,6 +380,25 @@ def main():
|
|
361 |
key=f"map_{selected_year}",
|
362 |
returned_objects=["null_drawing"]
|
363 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
|
365 |
with tab3:
|
366 |
# Weather condition filter
|
@@ -372,6 +410,27 @@ def main():
|
|
372 |
trend_fig = create_crash_trend_chart(df, selected_weather)
|
373 |
st.plotly_chart(trend_fig, use_container_width=True)
|
374 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
with tab4:
|
376 |
# Dropdown for Unit Type selection
|
377 |
unit_type_pairs = set()
|
@@ -408,6 +467,18 @@ def main():
|
|
408 |
distribution_chart = create_category_distribution_chart(df, selected_category, selected_year)
|
409 |
st.plotly_chart(distribution_chart, use_container_width=True)
|
410 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
411 |
|
412 |
if __name__ == "__main__":
|
413 |
main()
|
|
|
303 |
return fig
|
304 |
|
305 |
def main():
|
306 |
+
st.title('Traffic Accident Dataset')
|
307 |
+
|
308 |
+
st.markdown("""
|
309 |
+
**Team Members:**
|
310 |
+
- Janhavi Tushar Zarapkar ([email protected])
|
311 |
+
- Hangyue Zhang ([email protected])
|
312 |
+
- Andrew Nam ([email protected])
|
313 |
+
- Nirmal Attarde
|
314 |
+
- Maanas Sandeep Agrawa
|
315 |
+
""")
|
316 |
+
|
317 |
+
|
318 |
+
st.markdown("""
|
319 |
+
### Introduction to the Traffic Accident Dataset
|
320 |
+
This dataset contains detailed information about traffic accidents in the city of **Tempe**. It includes various attributes of the accidents, such as the severity of injuries, the demographics of the drivers involved, the locations of the incidents, and the conditions at the time of the accidents. The dataset covers accidents that occurred over several years, with data on factors like **weather conditions**, **road surface conditions**, the **time of day**, and the type of **violations** (e.g., alcohol or drug use) that may have contributed to the accident.
|
321 |
+
|
322 |
+
The data was sourced from **Tempe City's traffic incident reports** and provides a comprehensive view of the factors influencing road safety and accident severity in the city. By analyzing this dataset, we can gain insights into the key contributors to traffic incidents and uncover trends that could help improve traffic safety measures, urban planning, and law enforcement policies in the city.
|
323 |
+
""")
|
324 |
+
|
325 |
+
|
326 |
|
327 |
# Load data
|
328 |
df = load_and_preprocess_data('1.08_Crash_Data_Report_(detail).csv')
|
|
|
380 |
key=f"map_{selected_year}",
|
381 |
returned_objects=["null_drawing"]
|
382 |
)
|
383 |
+
|
384 |
+
st.markdown("""
|
385 |
+
### Traffic Crash Location Map
|
386 |
+
This interactive map visualizes traffic accidents in Tempe for the selected year. It combines **marker clustering** and a **heatmap** to show:
|
387 |
+
1. **Accident Markers**: Red markers indicate individual accidents, with popups displaying the coordinates, date/time, and severity of each incident.
|
388 |
+
2. **Heatmap**: The heatmap highlights accident hotspots with colors ranging from blue (low frequency) to yellow (moderate) and red (high frequency), showing areas with more frequent accidents.
|
389 |
+
|
390 |
+
**Key Features:**
|
391 |
+
* **Interactive Year Selection**: Users can select a year to view accidents for that specific time.
|
392 |
+
* **Accident Patterns**: The map reveals accident-prone areas and severity patterns, helping identify dangerous locations.
|
393 |
+
|
394 |
+
**Color Scheme:**
|
395 |
+
* **Red**: Individual accident markers.
|
396 |
+
* **Blue to Red**: Heatmap colors indicate accident frequency, from low (blue) to high (red).
|
397 |
+
|
398 |
+
This map provides insights into accident trends and can help guide safety improvements in the city.
|
399 |
+
""")
|
400 |
+
|
401 |
+
|
402 |
|
403 |
with tab3:
|
404 |
# Weather condition filter
|
|
|
410 |
trend_fig = create_crash_trend_chart(df, selected_weather)
|
411 |
st.plotly_chart(trend_fig, use_container_width=True)
|
412 |
|
413 |
+
st.markdown("""
|
414 |
+
## **Crash Trend Over Time**
|
415 |
+
This interactive line chart visualizes the trend of unique traffic crashes over the years, optionally filtered by weather conditions. It highlights how crash frequency changes over time, helping identify trends and potential contributing factors.
|
416 |
+
|
417 |
+
**Key Features:**
|
418 |
+
* **Time Trend Analysis**: Displays the total number of unique crashes for each year, showing long-term patterns.
|
419 |
+
* **Weather Filter**: Users can filter the data by weather conditions (e.g., "Rainy", "Sunny") to analyze how weather impacts crash trends.
|
420 |
+
* **Interactive Tooltips**: Hovering over data points reveals the exact crash count for each year, providing detailed insights.
|
421 |
+
|
422 |
+
**Color Scheme and Design:**
|
423 |
+
* **Line and Markers**: A smooth line connects data points, with prominent markers for each year to highlight trends clearly.
|
424 |
+
* **Dynamic Title**: The chart updates its title to reflect the selected weather condition or "All Conditions" for the overall trend.
|
425 |
+
|
426 |
+
**Insights:**
|
427 |
+
This chart helps uncover:
|
428 |
+
* Annual fluctuations in crash incidents.
|
429 |
+
* Correlations between weather conditions and crash frequencies.
|
430 |
+
* Historical patterns that can guide future safety measures and urban planning decisions
|
431 |
+
""")
|
432 |
+
|
433 |
+
|
434 |
with tab4:
|
435 |
# Dropdown for Unit Type selection
|
436 |
unit_type_pairs = set()
|
|
|
467 |
distribution_chart = create_category_distribution_chart(df, selected_category, selected_year)
|
468 |
st.plotly_chart(distribution_chart, use_container_width=True)
|
469 |
|
470 |
+
st.markdown("""
|
471 |
+
## Distribution by Category
|
472 |
+
This visualization explores the distribution of traffic incidents across various categories, such as Collision Manner, Weather, Surface Condition, Alcohol Use, and Driver Gender. Each bar represents a specific category value (e.g., "Male" or "Female" for Gender), and the bars are divided into segments based on Injury Severity (e.g., Minor, Moderate, Serious, Fatal).
|
473 |
+
|
474 |
+
**Key features include:**
|
475 |
+
* Interactive Filters: Select a category and filter by year to analyze trends over time.
|
476 |
+
* Insightful Tooltips: Hover over each segment to view the exact count and percentage of incidents for a given severity level.
|
477 |
+
* Comparative Analysis: Quickly identify how different conditions or behaviors correlate with injury severity.
|
478 |
+
|
479 |
+
This chart provides actionable insights into factors contributing to traffic incidents and their outcomes, helping stakeholders target interventions and improve road safety.
|
480 |
+
""")
|
481 |
+
|
482 |
|
483 |
if __name__ == "__main__":
|
484 |
main()
|