Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
c722793
1
Parent(s):
9a28506
fix list trip
Browse files
app/dialogflow/api/v1/dialogflow.py
CHANGED
|
@@ -307,10 +307,8 @@ async def get_trip_list(request: Request) -> Response:
|
|
| 307 |
try:
|
| 308 |
data = await dialog_service.search_trip(from_time, to_time, route_ids, ticket_count)
|
| 309 |
if len(data) > 0:
|
| 310 |
-
################################## bug choox nay
|
| 311 |
|
| 312 |
if origin_office and dest_office:
|
| 313 |
-
## Chưa tìm được
|
| 314 |
trip_by_time_office = dialog_service.get_trip_by_time_and_office_id(data, time, origin_ids, dest_ids)
|
| 315 |
# Nếu có chuyến xe theo thời gian và văn phòng chỉ định
|
| 316 |
if trip_by_time_office:
|
|
@@ -322,15 +320,16 @@ async def get_trip_list(request: Request) -> Response:
|
|
| 322 |
|
| 323 |
# Nếu không có chuyến xe theo thời gian và văn phòng chỉ định
|
| 324 |
# Danh sách chuyến xe khớp với văn phòng đón hoặc văn phòng trả
|
| 325 |
-
|
| 326 |
-
elif origin_office:
|
| 327 |
-
|
| 328 |
-
elif dest_office:
|
| 329 |
-
|
| 330 |
-
else:
|
| 331 |
-
|
|
|
|
| 332 |
# Tìm 4 chuyến xe gần thời gian chỉ định nhất
|
| 333 |
-
trip_surrounding_time = dialog_service.
|
| 334 |
trip_dialogflow = []
|
| 335 |
|
| 336 |
for trip in trip_surrounding_time:
|
|
|
|
| 307 |
try:
|
| 308 |
data = await dialog_service.search_trip(from_time, to_time, route_ids, ticket_count)
|
| 309 |
if len(data) > 0:
|
|
|
|
| 310 |
|
| 311 |
if origin_office and dest_office:
|
|
|
|
| 312 |
trip_by_time_office = dialog_service.get_trip_by_time_and_office_id(data, time, origin_ids, dest_ids)
|
| 313 |
# Nếu có chuyến xe theo thời gian và văn phòng chỉ định
|
| 314 |
if trip_by_time_office:
|
|
|
|
| 320 |
|
| 321 |
# Nếu không có chuyến xe theo thời gian và văn phòng chỉ định
|
| 322 |
# Danh sách chuyến xe khớp với văn phòng đón hoặc văn phòng trả
|
| 323 |
+
# data_by_office = dialog_service.get_all_trip_by_office(data, origin_ids, dest_ids)
|
| 324 |
+
# elif origin_office:
|
| 325 |
+
# data_by_office = dialog_service.get_all_trip_by_office(data,origin_id=origin_ids)
|
| 326 |
+
# elif dest_office:
|
| 327 |
+
# data_by_office = dialog_service.get_all_trip_by_office(data, dest_id=dest_ids)
|
| 328 |
+
# else:
|
| 329 |
+
|
| 330 |
+
data_by_office = data
|
| 331 |
# Tìm 4 chuyến xe gần thời gian chỉ định nhất
|
| 332 |
+
trip_surrounding_time = dialog_service.get_surrounding_trip(data_by_office, time, num_trip=4)
|
| 333 |
trip_dialogflow = []
|
| 334 |
|
| 335 |
for trip in trip_surrounding_time:
|
app/dialogflow/services/dialog_service.py
CHANGED
|
@@ -165,16 +165,29 @@ class DialogService:
|
|
| 165 |
return result if result else trips
|
| 166 |
# Danh sách 4 chuyến đi xung quanh thời gian chỉ định
|
| 167 |
@staticmethod
|
| 168 |
-
def
|
| 169 |
-
if time
|
| 170 |
return []
|
| 171 |
|
| 172 |
time_trips = [ trip["raw_departure_time"] for trip in trips]
|
| 173 |
index = bisect_left(time_trips, time)
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
|
| 180 |
|
|
|
|
| 165 |
return result if result else trips
|
| 166 |
# Danh sách 4 chuyến đi xung quanh thời gian chỉ định
|
| 167 |
@staticmethod
|
| 168 |
+
def get_surrounding_trip(trips: list, time: str, num_trip: int = 4) -> list:
|
| 169 |
+
if not time or not trips or num_trip <= 0:
|
| 170 |
return []
|
| 171 |
|
| 172 |
time_trips = [ trip["raw_departure_time"] for trip in trips]
|
| 173 |
index = bisect_left(time_trips, time)
|
| 174 |
+
|
| 175 |
+
half = num_trip // 2
|
| 176 |
+
start = max(0, index - half)
|
| 177 |
+
end = min(len(trips), index + half + (num_trip % 2))
|
| 178 |
+
|
| 179 |
+
missing = num_trip - (end - start)
|
| 180 |
+
|
| 181 |
+
if missing > 0:
|
| 182 |
+
extra_start = min(missing, start)
|
| 183 |
+
start -= extra_start
|
| 184 |
+
missing -= extra_start
|
| 185 |
+
|
| 186 |
+
if missing > 0:
|
| 187 |
+
extra_end = min(missing, len(trips) - end)
|
| 188 |
+
end += extra_end
|
| 189 |
+
|
| 190 |
+
return trips[start:end]
|
| 191 |
|
| 192 |
|
| 193 |
|