import pandas as pd
import plotly.graph_objects as go
from dash import Dash, dcc, html, Input, Output
# Read the CSV data
df = pd.read_csv('gpslpr_v1.csv')
# Convert 'Date' column to datetime
df['Date'] = pd.to_datetime(df['Date'], format='%d/%m/%Y')
# Create the Dash app
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
# Define the layout
app.layout = html.Div([
html.H1("השוואת זמני נסיעה LPR ו GPS", style={'textAlign': 'center', 'marginTop': '20px', 'marginBottom': '20px'}),
html.Div([
html.Div([
dcc.DatePickerSingle(
id='date-picker',
min_date_allowed=df['Date'].min(),
max_date_allowed=df['Date'].max(),
initial_visible_month=df['Date'].min(),
date=df['Date'].min()
)
], style={'width': '48%', 'display': 'inline-block'}),
html.Div([
dcc.Dropdown(
id='segment-dropdown',
options=[{'label': i, 'value': i} for i in df['sub_segment_name'].unique()],
value=df['sub_segment_name'].unique()[0]
)
], style={'width': '48%', 'float': 'right', 'display': 'inline-block'})
]),
html.Div([
dcc.Graph(id='travel-time-plot')
])
], style={'padding': '0 20px'})
@app.callback(
Output('travel-time-plot', 'figure'),
[Input('date-picker', 'date'),
Input('segment-dropdown', 'value')]
)
def update_graph(date, segment):
filtered_df = df[(df['Date'] == date) & (df['sub_segment_name'] == segment)]
fig = go.Figure()
fig.add_trace(go.Scatter(x=filtered_df['Hour'], y=filtered_df['LMS_TimeL_Mean'], mode='lines+markers', name='LPR(LMS) זמן נסיעה', line=dict(color='#ff7f0e')))
fig.add_trace(go.Scatter(x=filtered_df['Hour'], y=filtered_df['AH_GPSAvgTravelTimeSec'], mode='lines+markers', name='GPS שיטה 2 זמן נסיעה +', line=dict(color='#1f77b4')))
fig.add_trace(go.Scatter(x=filtered_df['Hour'], y=filtered_df['LMS_TimeG_Mean'], mode='lines+markers', name='(LMS) GPS שיטה 1 זמן נסיעה', line=dict(color='#e377c2')))
fig.add_trace(go.Scatter(x=filtered_df['Hour'], y=filtered_df['LMS_TimeG_StdDev'], mode='lines+markers', name='(LMS) GPS 1 סטיית תקן שיטה', line=dict(color='#2ca02c')))
fig.add_trace(go.Scatter(x=filtered_df['Hour'], y=filtered_df['LMS_TimeL_StdDev'], mode='lines+markers', name='LPR(LMS) סטיית תקן -', line=dict(color='#ff7f0e', dash='dash')))
fig.add_trace(go.Scatter(x=filtered_df['Hour'], y=filtered_df['AH_GPSStdDevTravelTimeSec'], mode='lines+markers', name='GPS שיטה 2 סטיית תקן -', line=dict(color='#1f77b4', dash='dash')))
fig.update_layout(
xaxis_title='שעה ביום',
yaxis_title='זמן נסיעה (שניות)',
legend_title='מקרא',
font=dict(size=12),
height=600
)
return fig
if __name__ == '__main__':
app.run_server(debug=True)