Do0rMaMu commited on
Commit
463d47b
1 Parent(s): af7571d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -7
app.py CHANGED
@@ -121,16 +121,62 @@ def pack_boxes(truck, boxes):
121
 
122
  return packed_positions
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  @app.post("/upload/")
125
  async def upload_file(
126
  file: UploadFile = File(...),
127
- length: float = Form(...),
128
- width: float = Form(...),
129
- height: float = Form(...),
 
 
130
  ):
131
  if not file:
132
  raise HTTPException(status_code=400, detail="No file uploaded")
133
 
 
134
  ext = file.filename.split('.')[-1].lower()
135
  if ext == 'csv':
136
  data = pd.read_csv(file.file)
@@ -149,7 +195,17 @@ async def upload_file(
149
  Box(row['PieceLength'], row['PieceBreadth'], row['PieceHeight'], row.get('Quantity', 1), f"{row['PieceNo']}-{row['Priority']}")
150
  for _, row in data.iterrows()
151
  ]
152
-
 
 
 
 
 
 
 
 
 
 
153
  # Convert truck dimensions from feet to inches
154
  truck_length = length * 12 # Convert to inches
155
  truck_width = width * 12 # Convert to inches
@@ -171,7 +227,15 @@ async def upload_file(
171
  }
172
  for box, pos in packed_positions
173
  ]
174
- print(f"quantity {[box_data[i]['quantity'] for i in range(len(box_data))]}")
175
-
176
- return {"boxes": box_data}
177
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  return packed_positions
123
 
124
+ def suggest_truck(boxes):
125
+ trucks = {
126
+ "TATA ACE": {"length": 7, "width": 4.8, "height": 4.8},
127
+ "ASHOK LEYLAND DOST": {"length": 7, "width": 4.8, "height": 4.8},
128
+ "MAHINDRA BOLERO PICK UP": {"length": 8, "width": 5, "height": 4.8},
129
+ "ASHOK LEYLAND BADA DOST": {"length": 9.5, "width": 5.5, "height": 5},
130
+ "TATA 407": {"length": 9, "width": 5.5, "height": 5},
131
+ "EICHER 14 FEET": {"length": 14, "width": 6, "height": 6.5},
132
+ "EICHER 17 FEET": {"length": 17, "width": 6, "height": 7},
133
+ "EICHER 19 FEET": {"length": 19, "width": 7, "height": 7},
134
+ "TATA 22 FEET": {"length": 22, "width": 7.5, "height": 7},
135
+ "TATA TRUCK (6 TYRE)": {"length": 17.5, "width": 7, "height": 7},
136
+ "TAURUS 16 T (10 TYRE)": {"length": 21, "width": 7.2, "height": 7},
137
+ "TAURUS 21 T (12 TYRE)": {"length": 24, "width": 7.3, "height": 7},
138
+ "TAURUS 25 T (14 TYRE)": {"length": 28, "width": 7.8, "height": 7},
139
+ "CONTAINER 20 FT": {"length": 20, "width": 8, "height": 8},
140
+ "CONTAINER 32 FT SXL": {"length": 32, "width": 8, "height": 8},
141
+ "CONTAINER 32 FT MXL": {"length": 32, "width": 8, "height": 8},
142
+ "CONTAINER 32 FT SXL / MXL HQ": {"length": 32, "width": 8, "height": 10},
143
+ "20 FEET OPEN ALL SIDE (ODC)": {"length": 20, "width": 8, "height": 8},
144
+ "28-32 FEET OPEN-TRAILOR JCB ODC": {"length": 28, "width": 8, "height": 8},
145
+ "32 FEET OPEN-TRAILOR ODC": {"length": 32, "width": 8, "height": 8},
146
+ "40 FEET OPEN-TRAILOR ODC": {"length": 40, "width": 8, "height": 8},
147
+ "SCV": {"length": 5, "width": 12, "height": 6},
148
+ "LCV": {"length": 11, "width": 5, "height": 5},
149
+ "ICV": {"length": 16, "width": 6.5, "height": 6.5},
150
+ "MCV": {"length": 19, "width": 7, "height": 7}
151
+ }
152
+
153
+ # Sort trucks by volume (smallest first)
154
+ sorted_trucks = sorted(trucks.items(), key=lambda t: t[1]['length'] * t[1]['width'] * t[1]['height'])
155
+
156
+ # Try packing the boxes in each truck, return the first one that fits all boxes
157
+ for truck_name, dimensions in sorted_trucks:
158
+ truck = Truck(dimensions['length'] * 12, dimensions['width'] * 12, dimensions['height'] * 12) # Convert to inches
159
+ packed_positions = pack_boxes(truck, boxes)
160
+
161
+ # Check if all boxes were successfully packed
162
+ if len(packed_positions) == sum(box.quantity for box in boxes):
163
+ return {"name": truck_name, "dimensions": dimensions}
164
+
165
+ return None
166
+
167
  @app.post("/upload/")
168
  async def upload_file(
169
  file: UploadFile = File(...),
170
+ length: float = Form(None), # Make these optional
171
+ width: float = Form(None),
172
+ height: float = Form(None),
173
+ name: str = Form(None),
174
+ autoSuggest: bool = Form(False)
175
  ):
176
  if not file:
177
  raise HTTPException(status_code=400, detail="No file uploaded")
178
 
179
+ print("truck name ", name)
180
  ext = file.filename.split('.')[-1].lower()
181
  if ext == 'csv':
182
  data = pd.read_csv(file.file)
 
195
  Box(row['PieceLength'], row['PieceBreadth'], row['PieceHeight'], row.get('Quantity', 1), f"{row['PieceNo']}-{row['Priority']}")
196
  for _, row in data.iterrows()
197
  ]
198
+
199
+ if autoSuggest:
200
+ # Suggest a truck that can fit all the boxes
201
+ suggested_truck = suggest_truck(boxes)
202
+ if suggested_truck:
203
+ length = suggested_truck['dimensions']['length']
204
+ width = suggested_truck['dimensions']['width']
205
+ height = suggested_truck['dimensions']['height']
206
+ else:
207
+ raise HTTPException(status_code=400, detail="No suitable truck found")
208
+
209
  # Convert truck dimensions from feet to inches
210
  truck_length = length * 12 # Convert to inches
211
  truck_width = width * 12 # Convert to inches
 
227
  }
228
  for box, pos in packed_positions
229
  ]
 
 
 
230
 
231
+ return {
232
+ "boxes": box_data,
233
+ "truck": {
234
+ "name": suggested_truck["name"] if autoSuggest else name,
235
+ "dimensions": {
236
+ "length": length,
237
+ "width": width,
238
+ "height": height
239
+ }
240
+ }
241
+ }