Spaces:
Sleeping
Sleeping
OnlyBiggg
commited on
Commit
·
377b8bd
1
Parent(s):
1f8c0c2
fix
Browse files
app/dialogflow/api/v1/dialogflow.py
CHANGED
|
@@ -90,8 +90,13 @@ async def confirm(request: Request):
|
|
| 90 |
@router.post('/routes')
|
| 91 |
async def route(request: Request):
|
| 92 |
body = await request.json()
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
|
|
|
| 95 |
|
| 96 |
ticket_count = int(raw_ticket_number) if raw_ticket_number else 1
|
| 97 |
|
|
@@ -101,15 +106,24 @@ async def route(request: Request):
|
|
| 101 |
else:
|
| 102 |
date = raw_date.strftime('%m-%d-%Y')
|
| 103 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
payload = {
|
| 110 |
"from_time": from_time,
|
| 111 |
"to_time": to_time,
|
| 112 |
-
"route_ids":
|
| 113 |
"ticket_count": 1,
|
| 114 |
"sort_by": ["price", "departure_time"]
|
| 115 |
}
|
|
@@ -169,21 +183,35 @@ async def route(request: Request):
|
|
| 169 |
@router.post('/price')
|
| 170 |
async def price(request: Request):
|
| 171 |
body = await request.json()
|
|
|
|
|
|
|
|
|
|
| 172 |
raw_departure_city, raw_destination_city, _, raw_date, _ = dialog_service.get_param_from_dialogflow(body)
|
| 173 |
|
| 174 |
if raw_date is None:
|
| 175 |
from_time, to_time = dialog_service.process_dates_to_timestamp()
|
| 176 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
payload = {
|
| 184 |
"from_time": from_time,
|
| 185 |
"to_time": to_time,
|
| 186 |
-
"route_ids":
|
| 187 |
"ticket_count": 1,
|
| 188 |
"sort_by": ["price", "departure_time"]
|
| 189 |
}
|
|
@@ -408,16 +436,25 @@ async def is_valid_select_time(request: Request) -> Response:
|
|
| 408 |
|
| 409 |
raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day = dialog_service.get_param_from_dialogflow(body)
|
| 410 |
|
| 411 |
-
date = raw_date.strftime('%m-%d-%Y')
|
| 412 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
| 413 |
ticket_count = int(raw_ticket_number) if raw_ticket_number else 1
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 421 |
|
| 422 |
time_list: List[Dict[str, any]] = parameters.get("time_list", [])
|
| 423 |
time_select = parameters.get("time-select", None)
|
|
@@ -428,7 +465,7 @@ async def is_valid_select_time(request: Request) -> Response:
|
|
| 428 |
for time in time_list:
|
| 429 |
if time_select == time["time"]:
|
| 430 |
id = int(time["id"])
|
| 431 |
-
trip = await dialog_service.search_trip_by_id(id, from_time, to_time,
|
| 432 |
departure_date = trip["raw_departure_date"]
|
| 433 |
parameters = {
|
| 434 |
"is_valid_time": True,
|
|
|
|
| 90 |
@router.post('/routes')
|
| 91 |
async def route(request: Request):
|
| 92 |
body = await request.json()
|
| 93 |
+
session_info = body.get("sessionInfo", {})
|
| 94 |
+
parameters = session_info.get("parameters")
|
| 95 |
+
|
| 96 |
+
origin_office = parameters.get("origin_office")
|
| 97 |
+
dest_office = parameters.get("dest_office")
|
| 98 |
|
| 99 |
+
raw_departure_city, raw_destination_city, raw_ticket_number , raw_date, _ = dialog_service.get_param_from_dialogflow(body)
|
| 100 |
|
| 101 |
ticket_count = int(raw_ticket_number) if raw_ticket_number else 1
|
| 102 |
|
|
|
|
| 106 |
else:
|
| 107 |
date = raw_date.strftime('%m-%d-%Y')
|
| 108 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
| 109 |
+
|
| 110 |
+
origin_code, origin_id, origin_ids, dest_code, dest_id, dest_ids = None, None, None, None, None, None
|
| 111 |
+
if origin_office:
|
| 112 |
+
origin_code, origin_id = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 113 |
+
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 114 |
+
elif raw_departure_city:
|
| 115 |
+
origin_code = origin_codes.get(raw_departure_city)
|
| 116 |
+
if dest_office:
|
| 117 |
+
dest_code, dest_id = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 118 |
+
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 119 |
+
elif raw_destination_city:
|
| 120 |
+
dest_code = origin_codes.get(raw_destination_city)
|
| 121 |
+
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 122 |
+
|
| 123 |
payload = {
|
| 124 |
"from_time": from_time,
|
| 125 |
"to_time": to_time,
|
| 126 |
+
"route_ids": route_ids,
|
| 127 |
"ticket_count": 1,
|
| 128 |
"sort_by": ["price", "departure_time"]
|
| 129 |
}
|
|
|
|
| 183 |
@router.post('/price')
|
| 184 |
async def price(request: Request):
|
| 185 |
body = await request.json()
|
| 186 |
+
session_info = body.get("sessionInfo", {})
|
| 187 |
+
parameters = session_info.get("parameters")
|
| 188 |
+
|
| 189 |
raw_departure_city, raw_destination_city, _, raw_date, _ = dialog_service.get_param_from_dialogflow(body)
|
| 190 |
|
| 191 |
if raw_date is None:
|
| 192 |
from_time, to_time = dialog_service.process_dates_to_timestamp()
|
| 193 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
| 194 |
|
| 195 |
+
origin_office = parameters.get("origin_office")
|
| 196 |
+
dest_office = parameters.get("dest_office")
|
| 197 |
+
|
| 198 |
+
origin_code, origin_id, origin_ids, dest_code, dest_id, dest_ids = None, None, None, None, None, None
|
| 199 |
+
if origin_office:
|
| 200 |
+
origin_code, origin_id = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 201 |
+
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 202 |
+
elif raw_departure_city:
|
| 203 |
+
origin_code = origin_codes.get(raw_departure_city)
|
| 204 |
+
if dest_office:
|
| 205 |
+
dest_code, dest_id = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 206 |
+
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 207 |
+
elif raw_destination_city:
|
| 208 |
+
dest_code = origin_codes.get(raw_destination_city)
|
| 209 |
+
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 210 |
+
|
| 211 |
payload = {
|
| 212 |
"from_time": from_time,
|
| 213 |
"to_time": to_time,
|
| 214 |
+
"route_ids": route_ids,
|
| 215 |
"ticket_count": 1,
|
| 216 |
"sort_by": ["price", "departure_time"]
|
| 217 |
}
|
|
|
|
| 436 |
|
| 437 |
raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day = dialog_service.get_param_from_dialogflow(body)
|
| 438 |
|
|
|
|
| 439 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
| 440 |
ticket_count = int(raw_ticket_number) if raw_ticket_number else 1
|
| 441 |
+
|
| 442 |
+
origin_office = parameters.get("origin_office")
|
| 443 |
+
dest_office = parameters.get("dest_office")
|
| 444 |
+
|
| 445 |
+
origin_code, origin_id, origin_ids, dest_code, dest_id, dest_ids = None, None, None, None, None, None
|
| 446 |
+
if origin_office:
|
| 447 |
+
origin_code, origin_id = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 448 |
+
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 449 |
+
elif raw_departure_city:
|
| 450 |
+
origin_code = origin_codes.get(raw_departure_city)
|
| 451 |
+
if dest_office:
|
| 452 |
+
dest_code, dest_id = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 453 |
+
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 454 |
+
elif raw_destination_city:
|
| 455 |
+
dest_code = origin_codes.get(raw_destination_city)
|
| 456 |
+
route_ids = await dialog_service.search_all_route_ids(origin_code=origin_code, from_id=origin_id, orign_ids=origin_ids, dest_code=dest_code, to_id=dest_id, dest_ids=dest_ids)
|
| 457 |
+
|
| 458 |
|
| 459 |
time_list: List[Dict[str, any]] = parameters.get("time_list", [])
|
| 460 |
time_select = parameters.get("time-select", None)
|
|
|
|
| 465 |
for time in time_list:
|
| 466 |
if time_select == time["time"]:
|
| 467 |
id = int(time["id"])
|
| 468 |
+
trip = await dialog_service.search_trip_by_id(id, from_time, to_time, route_ids, ticket_count)
|
| 469 |
departure_date = trip["raw_departure_date"]
|
| 470 |
parameters = {
|
| 471 |
"is_valid_time": True,
|