Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,9 +3,9 @@ import pandas as pd
|
|
| 3 |
import altair as alt
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Shipment Monitoring Dashboard", layout="wide")
|
| 6 |
-
st.title("
|
| 7 |
|
| 8 |
-
uploaded_file = st.file_uploader("Upload
|
| 9 |
|
| 10 |
if uploaded_file:
|
| 11 |
df = pd.read_excel(uploaded_file, sheet_name=0)
|
|
@@ -29,6 +29,7 @@ if uploaded_file:
|
|
| 29 |
return "Ship Out"
|
| 30 |
|
| 31 |
df['Shipment Status'] = df.apply(determine_status, axis=1)
|
|
|
|
| 32 |
|
| 33 |
# Filter for Injection Gateway
|
| 34 |
injection_gateways = df['Injection Gateway'].dropna().unique().tolist()
|
|
@@ -36,43 +37,53 @@ if uploaded_file:
|
|
| 36 |
if selected_gateway != "All":
|
| 37 |
df = df[df['Injection Gateway'] == selected_gateway]
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
st.subheader("
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
status_counts.columns = ['Shipment Status', 'Count']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
chart = alt.Chart(status_counts).mark_bar().encode(
|
| 44 |
-
x='Shipment Status',
|
| 45 |
y='Count',
|
| 46 |
color='Shipment Status',
|
| 47 |
-
tooltip=['Shipment Status', 'Count']
|
| 48 |
-
|
|
|
|
|
|
|
| 49 |
st.altair_chart(chart, use_container_width=True)
|
| 50 |
|
|
|
|
|
|
|
| 51 |
# Volume by ETA
|
| 52 |
-
st.subheader("
|
| 53 |
-
df['ETA'] = pd.to_datetime(df['ETA'])
|
| 54 |
volume_by_eta = df.groupby('ETA').agg({
|
| 55 |
'MAWB': 'count',
|
| 56 |
'Cartons': 'sum',
|
| 57 |
-
'Packages': 'sum',
|
| 58 |
-
'Weights': 'sum'
|
| 59 |
}).reset_index().rename(columns={'MAWB': 'Shipment Count'})
|
| 60 |
|
| 61 |
st.dataframe(volume_by_eta, use_container_width=True)
|
| 62 |
|
| 63 |
-
line_chart = alt.Chart(volume_by_eta).
|
| 64 |
-
['Shipment Count', 'Cartons', 'Packages', 'Weights'],
|
| 65 |
-
as_=['Metric', 'Value']
|
| 66 |
-
).mark_line(point=True).encode(
|
| 67 |
x='ETA:T',
|
| 68 |
-
y='
|
| 69 |
-
|
| 70 |
-
tooltip=['ETA:T', 'Metric:N', 'Value:Q']
|
| 71 |
).properties(height=400)
|
| 72 |
|
| 73 |
st.altair_chart(line_chart, use_container_width=True)
|
| 74 |
|
| 75 |
-
# Table view sorted by ETA
|
| 76 |
-
st.subheader("
|
| 77 |
-
|
|
|
|
| 78 |
st.dataframe(sorted_df, use_container_width=True)
|
|
|
|
| 3 |
import altair as alt
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Shipment Monitoring Dashboard", layout="wide")
|
| 6 |
+
st.title("\ud83d\ude9a 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)
|
|
|
|
| 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()
|
|
|
|
| 37 |
if selected_gateway != "All":
|
| 38 |
df = df[df['Injection Gateway'] == selected_gateway]
|
| 39 |
|
| 40 |
+
# Filter by ETA date range
|
| 41 |
+
st.subheader("\ud83d\udd0e 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("\ud83d\udcca 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("\ud83d\udcc5 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("\ud83d\udd0d 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)
|