joycecast commited on
Commit
a7d00db
·
verified ·
1 Parent(s): 2f60b4d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +99 -82
app.py CHANGED
@@ -5,85 +5,102 @@ import altair as alt
5
  st.set_page_config(page_title="Shipment Monitoring Dashboard", layout="wide")
6
  st.title("Shipment Monitoring Dashboard")
7
 
8
- uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"])
9
-
10
- if uploaded_file:
11
- df = pd.read_excel(uploaded_file, sheet_name=0)
12
-
13
- # Rename columns
14
- df.columns = ['MAWB', 'MAWB Serial Number', 'Injection Gateway', 'Clearance Port', 'Latest Status',
15
- 'Cartons', 'Packages', 'Weights', 'Not online packages count', 'ETD', 'ETA', 'ATD', 'ATA',
16
- 'Last Mile Carrier', 'Readynotice has been notified', 'Vehicle has been arranged',
17
- 'Pick-upcompletedfrom', 'WH-IN Scan', 'Cargo Ready', 'Ship Out', 'Note',
18
- 'Exception Note', 'Exception Note Description']
19
-
20
- # Add status column
21
- def determine_status(row):
22
- if pd.isna(row['WH-IN Scan']):
23
- return "Pending"
24
- elif pd.isna(row['Cargo Ready']):
25
- return "WH-IN"
26
- elif pd.isna(row['Ship Out']):
27
- return "Cargo Ready"
28
- else:
29
- return "Ship Out"
30
-
31
- df['Shipment Status'] = df.apply(determine_status, axis=1)
32
- df['ETA'] = pd.to_datetime(df['ETA'])
33
-
34
- # Filter for Injection Gateway
35
- injection_gateways = df['Injection Gateway'].dropna().unique().tolist()
36
- selected_gateway = st.selectbox("Filter by Injection Gateway", options=["All"] + injection_gateways)
37
- if selected_gateway != "All":
38
- df = df[df['Injection Gateway'] == selected_gateway]
39
-
40
- # Filter by ETA date range
41
- st.subheader("Filter by ETA Date Range")
42
- min_date, max_date = df['ETA'].min(), df['ETA'].max()
43
- start_date, end_date = st.date_input("Select ETA date range:", [min_date, max_date], min_value=min_date, max_value=max_date)
44
- df = df[(df['ETA'] >= pd.to_datetime(start_date)) & (df['ETA'] <= pd.to_datetime(end_date))]
45
-
46
- # Shipment status distribution with interactive selection
47
- st.subheader("Shipment Status Distribution")
48
- status_order = ["Pending", "WH-IN", "Cargo Ready", "Ship Out"]
49
- status_counts = df['Shipment Status'].value_counts().reindex(status_order).reset_index()
50
- status_counts.columns = ['Shipment Status', 'Count']
51
- status_counts = status_counts.dropna()
52
-
53
- # Altair selection for interactivity
54
- selection = alt.selection_single(fields=['Shipment Status'], bind='legend', name='Select', init={'Shipment Status': 'Pending'})
55
-
56
- chart = alt.Chart(status_counts).mark_bar().encode(
57
- x=alt.X('Shipment Status', sort=status_order),
58
- y='Count',
59
- color='Shipment Status',
60
- tooltip=['Shipment Status', 'Count'],
61
- opacity=alt.condition(selection, alt.value(1), alt.value(0.4))
62
- ).add_params(selection).properties(height=300)
63
-
64
- st.altair_chart(chart, use_container_width=True)
65
-
66
- selected_status = selection.init['Shipment Status'] if selection else "Pending"
67
-
68
- # Volume by ETA
69
- st.subheader("Shipment Volume by ETA")
70
- volume_by_eta = df.groupby('ETA').agg({
71
- 'MAWB': 'count',
72
- 'Cartons': 'sum',
73
- }).reset_index().rename(columns={'MAWB': 'Shipment Count'})
74
-
75
- st.dataframe(volume_by_eta, use_container_width=True)
76
-
77
- line_chart = alt.Chart(volume_by_eta).mark_line(point=True).encode(
78
- x='ETA:T',
79
- y='Cartons:Q',
80
- tooltip=['ETA:T', 'Shipment Count:Q', 'Cartons:Q']
81
- ).properties(height=400)
82
-
83
- st.altair_chart(line_chart, use_container_width=True)
84
-
85
- # Table view sorted by ETA and filtered by selected status
86
- st.subheader("Shipment Detail View by ETA")
87
- filtered_df = df[df['Shipment Status'] == selected_status]
88
- sorted_df = filtered_df[['MAWB', 'ETA', 'ATA', 'Shipment Status', 'Cartons', 'Last Mile Carrier']].sort_values(by='ETA')
89
- st.dataframe(sorted_df, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  st.set_page_config(page_title="Shipment Monitoring Dashboard", layout="wide")
6
  st.title("Shipment Monitoring Dashboard")
7
 
8
+ tabs = st.tabs(["Main Dashboard", "Last Mile Summary"])
9
+
10
+ with tabs[0]:
11
+ uploaded_file = st.file_uploader("Upload your Excel file", type=["xlsx"], key="main_upload")
12
+
13
+ if uploaded_file:
14
+ df = pd.read_excel(uploaded_file, sheet_name=0)
15
+
16
+ # Rename columns
17
+ df.columns = ['MAWB', 'MAWB Serial Number', 'Injection Gateway', 'Clearance Port', 'Latest Status',
18
+ 'Cartons', 'Packages', 'Weights', 'Not online packages count', 'ETD', 'ETA', 'ATD', 'ATA',
19
+ 'Last Mile Carrier', 'Readynotice has been notified', 'Vehicle has been arranged',
20
+ 'Pick-upcompletedfrom', 'WH-IN Scan', 'Cargo Ready', 'Ship Out', 'Note',
21
+ 'Exception Note', 'Exception Note Description']
22
+
23
+ # Add status column
24
+ def determine_status(row):
25
+ if pd.isna(row['WH-IN Scan']):
26
+ return "Pending"
27
+ elif pd.isna(row['Cargo Ready']):
28
+ return "WH-IN"
29
+ elif pd.isna(row['Ship Out']):
30
+ return "Cargo Ready"
31
+ else:
32
+ return "Ship Out"
33
+
34
+ df['Shipment Status'] = df.apply(determine_status, axis=1)
35
+ df['ETA'] = pd.to_datetime(df['ETA'])
36
+
37
+ # Filter for Injection Gateway
38
+ injection_gateways = df['Injection Gateway'].dropna().unique().tolist()
39
+ selected_gateway = st.selectbox("Filter by Injection Gateway", options=["All"] + injection_gateways)
40
+ if selected_gateway != "All":
41
+ df = df[df['Injection Gateway'] == selected_gateway]
42
+
43
+ # Filter by ETA date range
44
+ st.subheader("Filter by ETA Date Range")
45
+ min_date, max_date = df['ETA'].min(), df['ETA'].max()
46
+ start_date, end_date = st.date_input("Select ETA date range:", [min_date, max_date], min_value=min_date, max_value=max_date)
47
+ df = df[(df['ETA'] >= pd.to_datetime(start_date)) & (df['ETA'] <= pd.to_datetime(end_date))]
48
+
49
+ # Shipment status distribution with interactive selection
50
+ st.subheader("Shipment Status Distribution")
51
+ status_order = ["Pending", "WH-IN", "Cargo Ready", "Ship Out"]
52
+ status_counts = df['Shipment Status'].value_counts().reindex(status_order).reset_index()
53
+ status_counts.columns = ['Shipment Status', 'Count']
54
+ status_counts = status_counts.dropna()
55
+
56
+ # Altair selection for interactivity
57
+ selection = alt.selection_single(fields=['Shipment Status'], bind='legend', name='Select', init={'Shipment Status': 'Pending'})
58
+
59
+ chart = alt.Chart(status_counts).mark_bar().encode(
60
+ x=alt.X('Shipment Status', sort=status_order),
61
+ y='Count',
62
+ color='Shipment Status',
63
+ tooltip=['Shipment Status', 'Count'],
64
+ opacity=alt.condition(selection, alt.value(1), alt.value(0.4))
65
+ ).add_params(selection).properties(height=300)
66
+
67
+ st.altair_chart(chart, use_container_width=True)
68
+
69
+ selected_status = selection.init['Shipment Status'] if selection else "Pending"
70
+
71
+ # Volume by ETA
72
+ st.subheader("Shipment Volume by ETA")
73
+ volume_by_eta = df.groupby('ETA').agg({
74
+ 'MAWB': 'count',
75
+ 'Cartons': 'sum',
76
+ }).reset_index().rename(columns={'MAWB': 'Shipment Count'})
77
+
78
+ st.dataframe(volume_by_eta, use_container_width=True)
79
+
80
+ line_chart = alt.Chart(volume_by_eta).mark_line(point=True).encode(
81
+ x='ETA:T',
82
+ y='Cartons:Q',
83
+ tooltip=['ETA:T', 'Shipment Count:Q', 'Cartons:Q']
84
+ ).properties(height=400)
85
+
86
+ st.altair_chart(line_chart, use_container_width=True)
87
+
88
+ # Table view sorted by ETA and filtered by selected status
89
+ st.subheader("Shipment Detail View by ETA")
90
+ filtered_df = df[df['Shipment Status'] == selected_status]
91
+ sorted_df = filtered_df[['MAWB', 'ETA', 'ATA', 'Shipment Status', 'Cartons', 'Last Mile Carrier']].sort_values(by='ETA')
92
+ st.dataframe(sorted_df, use_container_width=True)
93
+
94
+ with tabs[1]:
95
+ st.header("Upload CTN File for Last Mile Summary")
96
+ ctn_file = st.file_uploader("Upload Excel with Last Mile Service", type=["xlsx"], key="ctn_upload")
97
+
98
+ if ctn_file:
99
+ df_ctn = pd.read_excel(ctn_file, sheet_name=0)
100
+
101
+ # Try to match the correct column
102
+ last_mile_col = [col for col in df_ctn.columns if "last mile" in col.lower()][0]
103
+
104
+ # Group by Last Mile Service and count cartons
105
+ grouped = df_ctn.groupby(last_mile_col).agg({"Cartons": "sum"}).reset_index()
106
+ st.dataframe(grouped, use_container_width=True)