Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,22 +22,33 @@ def process_file(file, truck_type, auto_suggest):
|
|
| 22 |
|
| 23 |
print(f"File processed successfully, data:\n{df.head()}") # Print first few rows of the data
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Prepare consignments data from the DataFrame
|
| 26 |
consignments_data = []
|
| 27 |
grouped = df.groupby('ConsignmentNo')
|
| 28 |
for consignment_no, group in grouped:
|
| 29 |
consignment_boxes = [
|
| 30 |
{
|
| 31 |
-
'PieceLength': row['PieceLength'],
|
| 32 |
-
'PieceBreadth': row['PieceBreadth'],
|
| 33 |
-
'PieceHeight': row['PieceHeight'],
|
| 34 |
-
'Priority': row.get('Priority', 0)
|
|
|
|
| 35 |
}
|
| 36 |
for _, row in group.iterrows()
|
| 37 |
]
|
| 38 |
consignments_data.append({
|
| 39 |
'ConsignmentNo': str(consignment_no), # Convert ConsignmentNo to string
|
| 40 |
-
'Priority': group['Priority'].max(),
|
|
|
|
| 41 |
'boxes': consignment_boxes
|
| 42 |
})
|
| 43 |
|
|
@@ -47,7 +58,8 @@ def process_file(file, truck_type, auto_suggest):
|
|
| 47 |
json_data = {
|
| 48 |
'truck_name': truck_type,
|
| 49 |
'autoSuggest': auto_suggest,
|
| 50 |
-
'consignments_data': consignments_data
|
|
|
|
| 51 |
}
|
| 52 |
|
| 53 |
print(f"Sending the following data to backend:\n{json_data}")
|
|
|
|
| 22 |
|
| 23 |
print(f"File processed successfully, data:\n{df.head()}") # Print first few rows of the data
|
| 24 |
|
| 25 |
+
# Define a destination mapping
|
| 26 |
+
destination_mapping = {
|
| 27 |
+
"Destination A": 1,
|
| 28 |
+
"Destination B": 2,
|
| 29 |
+
"Destination C": 3,
|
| 30 |
+
"Destination D": 4,
|
| 31 |
+
"Destination E": 5
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
# Prepare consignments data from the DataFrame
|
| 35 |
consignments_data = []
|
| 36 |
grouped = df.groupby('ConsignmentNo')
|
| 37 |
for consignment_no, group in grouped:
|
| 38 |
consignment_boxes = [
|
| 39 |
{
|
| 40 |
+
'PieceLength': float(row['PieceLength']),
|
| 41 |
+
'PieceBreadth': float(row['PieceBreadth']),
|
| 42 |
+
'PieceHeight': float(row['PieceHeight']),
|
| 43 |
+
'Priority': int(row.get('Priority', 0)),
|
| 44 |
+
'Destination': row.get('Destination', "Unknown")
|
| 45 |
}
|
| 46 |
for _, row in group.iterrows()
|
| 47 |
]
|
| 48 |
consignments_data.append({
|
| 49 |
'ConsignmentNo': str(consignment_no), # Convert ConsignmentNo to string
|
| 50 |
+
'Priority': int(group['Priority'].max()), # Ensure Priority is int
|
| 51 |
+
'Destination': group['Destination'].iloc[0], # Taking the destination of the first box
|
| 52 |
'boxes': consignment_boxes
|
| 53 |
})
|
| 54 |
|
|
|
|
| 58 |
json_data = {
|
| 59 |
'truck_name': truck_type,
|
| 60 |
'autoSuggest': auto_suggest,
|
| 61 |
+
'consignments_data': consignments_data,
|
| 62 |
+
'destination_mapping': destination_mapping # Include destination mapping in payload
|
| 63 |
}
|
| 64 |
|
| 65 |
print(f"Sending the following data to backend:\n{json_data}")
|