joycecast commited on
Commit
1ecc1c6
·
verified ·
1 Parent(s): 6c74bda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import altair as alt
4
- import io
5
 
6
  st.set_page_config(page_title="Shipment Monitoring Dashboard", layout="wide")
7
  st.title("Shipment Monitoring Dashboard")
@@ -97,10 +96,12 @@ with tabs[0]:
97
  else:
98
  filtered_df = df[df['Shipment Status'] == selected_status]
99
 
100
- sorted_df = filtered_df[['MAWB', 'ETA', 'ATA', 'Shipment Status', 'Cartons', 'Last Mile Carrier', 'Exception Note Description']].sort_values(by='ETA')
101
  st.dataframe(sorted_df, use_container_width=True)
102
 
103
- # Export to Excel
 
 
104
  excel_buffer = io.BytesIO()
105
  with pd.ExcelWriter(excel_buffer, engine='xlsxwriter') as writer:
106
  sorted_df.to_excel(writer, index=False, sheet_name='Shipment Details')
@@ -112,17 +113,33 @@ with tabs[0]:
112
  file_name="shipment_details.xlsx",
113
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
114
  )
115
-
116
  with tabs[1]:
117
  st.header("Upload CTN File for Last Mile Summary")
118
- ctn_file = st.file_uploader("Upload Excel with Last Mile Service", type=["xlsx"], key="ctn_upload")
119
 
120
- if ctn_file:
121
- df_ctn = pd.read_excel(ctn_file, sheet_name=0)
 
 
 
 
 
122
 
123
  # Try to match the correct column
124
  last_mile_col = [col for col in df_ctn.columns if "last mile" in col.lower()][0]
125
 
126
- # Group by Last Mile Service and aggregate by row count
127
- grouped = df_ctn.groupby(last_mile_col).size().reset_index(name='CTN Count')
128
- st.dataframe(grouped, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  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("Shipment Monitoring Dashboard")
 
96
  else:
97
  filtered_df = df[df['Shipment Status'] == selected_status]
98
 
99
+ sorted_df = filtered_df[['MAWB', 'ETA', 'ATA', 'Shipment Status', 'Cartons', 'Last Mile Carrier']].sort_values(by='ETA')
100
  st.dataframe(sorted_df, use_container_width=True)
101
 
102
+ # Add download as Excel button
103
+ import io
104
+
105
  excel_buffer = io.BytesIO()
106
  with pd.ExcelWriter(excel_buffer, engine='xlsxwriter') as writer:
107
  sorted_df.to_excel(writer, index=False, sheet_name='Shipment Details')
 
113
  file_name="shipment_details.xlsx",
114
  mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
115
  )
116
+
117
  with tabs[1]:
118
  st.header("Upload CTN File for Last Mile Summary")
119
+ ctn_files = st.file_uploader("Upload one or more Excel files with Last Mile Service", type=["xlsx"], key="ctn_upload", accept_multiple_files=True)
120
 
121
+ if ctn_files:
122
+ df_list = []
123
+ for file in ctn_files:
124
+ df_part = pd.read_excel(file, sheet_name=0)
125
+ df_list.append(df_part)
126
+
127
+ df_ctn = pd.concat(df_list, ignore_index=True)
128
 
129
  # Try to match the correct column
130
  last_mile_col = [col for col in df_ctn.columns if "last mile" in col.lower()][0]
131
 
132
+ # Uploaded Preview: group by MAWB + Last Mile Service
133
+ st.subheader("MAWB Last Mile Cartons Count")
134
+ if 'MAWB' in df_ctn.columns:
135
+ preview_grouped = df_ctn.groupby(['MAWB', last_mile_col]).size().reset_index(name='CTN Count')
136
+ st.dataframe(preview_grouped, use_container_width=True)
137
+
138
+ # Grouped Summary: only for Last Mile Service == GOFO, grouped by MAWB + Channal_name
139
+ st.subheader("GOFO Each Channel Cartons Summary")
140
+ if 'Channal_name' in df_ctn.columns:
141
+ df_gofo = df_ctn[df_ctn[last_mile_col].str.upper() == 'GOFO']
142
+ grouped = df_gofo.groupby(['MAWB', 'Channal_name']).size().reset_index(name='CTN Count')
143
+ st.dataframe(grouped, use_container_width=True)
144
+ else:
145
+ st.warning("Column 'Channal_name' not found in the uploaded file(s). Please ensure this column exists.")