File size: 1,928 Bytes
d7a62b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import streamlit as st
import pandas as pd
from datetime import datetime

# Initialize the state for the excel file name
if 'excel_file_name' not in st.session_state:
    st.session_state.excel_file_name = 'combined_duplicates_removed.csv'

# Streamlit title
st.title("Automated Road Accident Monitoring System")

# Button to update the dataset
if st.button("Update Dataset"):
    st.session_state.excel_file_name = 'updated.csv'

# Get the current excel file name from session state
excel_file_name = st.session_state.excel_file_name

# Display a note to the user
st.write("Please Note, First Date must be smaller than Last date. Example: First Date = 25-08-2024 and Last Date = 28-08-2024")

# Get today's date
today = datetime.strptime(datetime.today().strftime('%d-%m-%Y'), '%d-%m-%Y')

# Input fields for date range
start = st.date_input("Enter first date", max_value=today, format="DD-MM-YYYY")
start_string = start.strftime('%d-%m-%Y')
end = st.date_input("Enter last date", max_value=today, format="DD-MM-YYYY")
end_string = end.strftime('%d-%m-%Y')

# Button to generate dataset based on date range
if st.button("Generate Dataset"):
    # Read the selected excel file
    df3 = pd.read_csv(excel_file_name)

    # Convert 'Publish Date' column to datetime with 'day-month-year' format
    df3['Publish Date'] = pd.to_datetime(df3['Publish Date'], format='%d-%m-%Y')

    # Convert user input dates to datetime
    start_date = pd.to_datetime(start_string, format='%d-%m-%Y')
    end_date = pd.to_datetime(end_string, format='%d-%m-%Y')

    # Filter rows based on the specified date range
    filtered_entries = df3[(df3['Publish Date'] >= start_date) & (df3['Publish Date'] <= end_date)]
    filtered_entries.reset_index(inplace=True, drop=True)

    # Display the filtered data
    st.dataframe(filtered_entries)

# Display selected start and end dates
st.write("Start date is:", start)
st.write("End date is:", end)