namdini commited on
Commit
a89028e
·
verified ·
1 Parent(s): 75ac53f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -243,6 +243,30 @@ def create_injuries_fatalities_chart(crash_data, unit_type):
243
 
244
  return line_chart
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  def main():
247
  st.title('Traffic Crash Analysis')
248
 
 
243
 
244
  return line_chart
245
 
246
+ def create_crash_trend_chart(df, weather=None):
247
+ if weather and weather != 'All Conditions':
248
+ df = df[df['Weather'] == weather]
249
+
250
+ # Group data by year and count unique Incident IDs
251
+ trend_data = df.groupby('Year')['Incidentid'].nunique().reset_index()
252
+ trend_data.columns = ['Year', 'Crash Count']
253
+
254
+ # Create line graph
255
+ fig = px.line(
256
+ trend_data,
257
+ x='Year',
258
+ y='Crash Count',
259
+ title=f'Crash Trend Over Time ({weather})',
260
+ labels={'Year': 'Year', 'Crash Count': 'Number of Unique Crashes'},
261
+ markers=True,
262
+ height=600
263
+ )
264
+
265
+ fig.update_traces(line=dict(width=2), marker=dict(size=8))
266
+ fig.update_layout(legend_title_text='Trend')
267
+
268
+ return fig
269
+
270
  def main():
271
  st.title('Traffic Crash Analysis')
272