Spaces:
Sleeping
Sleeping
OnlyBiggg commited on
Commit ·
835d9e6
1
Parent(s): 0461c2d
fix
Browse files
app/dialogflow/api/v1/dialogflow.py
CHANGED
|
@@ -234,20 +234,33 @@ async def price(request: Request):
|
|
| 234 |
@router.post('/trip/route/list')
|
| 235 |
async def booking_trip(request: Request) -> Response:
|
| 236 |
body = await request.json()
|
|
|
|
|
|
|
|
|
|
| 237 |
raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day = dialog_service.get_param_from_dialogflow(body)
|
| 238 |
|
| 239 |
-
|
|
|
|
|
|
|
| 240 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
|
|
|
| 241 |
ticket_count = int(raw_ticket_number) if raw_ticket_number else 1
|
| 242 |
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
try:
|
| 250 |
-
data = await dialog_service.search_trip(from_time, to_time,
|
| 251 |
total = len(data)
|
| 252 |
if total > 0:
|
| 253 |
trips = []
|
|
|
|
| 234 |
@router.post('/trip/route/list')
|
| 235 |
async def booking_trip(request: Request) -> Response:
|
| 236 |
body = await request.json()
|
| 237 |
+
session_info = body.get("sessionInfo", {})
|
| 238 |
+
parameters = session_info.get("parameters")
|
| 239 |
+
|
| 240 |
raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day = dialog_service.get_param_from_dialogflow(body)
|
| 241 |
|
| 242 |
+
origin_office = parameters.get("origin_office")
|
| 243 |
+
dest_office = parameters.get("dest_office")
|
| 244 |
+
|
| 245 |
from_time, to_time = dialog_service.process_dates_to_timestamp(raw_date)
|
| 246 |
+
|
| 247 |
ticket_count = int(raw_ticket_number) if raw_ticket_number else 1
|
| 248 |
|
| 249 |
+
if origin_office:
|
| 250 |
+
origin_code, origin_id = await dialog_service.find_id_and_code_provine_by_name_office(origin_office)
|
| 251 |
+
origin_ids = await dialog_service.find_id_office_by_name_office(origin_office)
|
| 252 |
+
else:
|
| 253 |
+
origin_code = await origin_codes.get(raw_departure_city)
|
| 254 |
+
if dest_office:
|
| 255 |
+
dest_code, dest_id = await dialog_service.find_id_and_code_provine_by_name_office(dest_office)
|
| 256 |
+
dest_ids = await dialog_service.find_id_office_by_name_office(dest_office)
|
| 257 |
+
else:
|
| 258 |
+
dest_code = await origin_codes.get(raw_destination_city)
|
| 259 |
+
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)
|
| 260 |
+
|
| 261 |
+
|
| 262 |
try:
|
| 263 |
+
data = await dialog_service.search_trip(from_time, to_time, route_ids, ticket_count)
|
| 264 |
total = len(data)
|
| 265 |
if total > 0:
|
| 266 |
trips = []
|
app/dialogflow/services/dialog_service.py
CHANGED
|
@@ -34,13 +34,26 @@ class DialogService:
|
|
| 34 |
return raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day
|
| 35 |
|
| 36 |
@staticmethod
|
| 37 |
-
async def
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
route_ids = []
|
| 40 |
if isinstance(response, list):
|
| 41 |
-
route_ids = [route.get("routeId",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return route_ids
|
| 43 |
-
|
| 44 |
@staticmethod
|
| 45 |
async def seats_trip(route_id: int, trip_id:int, departure_date: str, departure_time: str, kind: str):
|
| 46 |
try:
|
|
@@ -168,9 +181,50 @@ class DialogService:
|
|
| 168 |
return data
|
| 169 |
return None
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
|
| 172 |
async def get_origin_city_from_office(self, origin_office: str):
|
| 173 |
-
data = self.search_pickup_points(origin=origin_office)
|
| 174 |
if data.get["origin"]:
|
| 175 |
origins = data["origin"]
|
| 176 |
for origin in origins:
|
|
@@ -184,7 +238,7 @@ class DialogService:
|
|
| 184 |
return None
|
| 185 |
|
| 186 |
async def get_destination_city_from_office(self, dest_office: str):
|
| 187 |
-
data = self.search_pickup_points(dest=dest_office)
|
| 188 |
if data.get("dest"):
|
| 189 |
dests = data["dest"]
|
| 190 |
for dest in dests:
|
|
|
|
| 34 |
return raw_departure_city, raw_destination_city, raw_ticket_number, raw_date, raw_time_of_day
|
| 35 |
|
| 36 |
@staticmethod
|
| 37 |
+
async def search_route_ids_one_way(origin_code: str = None, from_id: int = None, orign_ids: int = None, des_code: str = None, to_id: str = None, dest_ids: str = None):
|
| 38 |
+
params = {
|
| 39 |
+
"OriginCode": origin_code,
|
| 40 |
+
"FromId": from_id,
|
| 41 |
+
"OriginIds": orign_ids,
|
| 42 |
+
"DestCode": des_code,
|
| 43 |
+
"ToId": to_id,
|
| 44 |
+
"DestIds": dest_ids
|
| 45 |
+
}
|
| 46 |
+
response = await api.get(f'/metadata/office/routes' , params=params)
|
| 47 |
route_ids = []
|
| 48 |
if isinstance(response, list):
|
| 49 |
+
route_ids = [route.get("routeId", None) for route in response]
|
| 50 |
+
return route_ids
|
| 51 |
+
|
| 52 |
+
async def search_all_route_ids(self, origin_code: str = None, from_id: int = None, orign_ids: int = None, des_code: str = None, to_id: str = None, dest_ids: str = None)
|
| 53 |
+
route_ids_origin_dest = await self.search_route_ids_one_way(origin_code, from_id, orign_ids, des_code, to_id, dest_ids)
|
| 54 |
+
route_ids_dest_origin = await self.search_route_ids_one_way(des_code, to_id, dest_ids, origin_code, from_id, orign_ids)
|
| 55 |
+
route_ids = list(set(route_ids_origin_dest + route_ids_dest_origin))
|
| 56 |
return route_ids
|
|
|
|
| 57 |
@staticmethod
|
| 58 |
async def seats_trip(route_id: int, trip_id:int, departure_date: str, departure_time: str, kind: str):
|
| 59 |
try:
|
|
|
|
| 181 |
return data
|
| 182 |
return None
|
| 183 |
|
| 184 |
+
async def find_id_office_by_name_office(self, office_name: str):
|
| 185 |
+
data = await self.search_pickup_points(origin=office_name)
|
| 186 |
+
if data.get["origin"]:
|
| 187 |
+
origins = data["origin"]
|
| 188 |
+
for origin in origins:
|
| 189 |
+
if origin.get("group"):
|
| 190 |
+
groups = origin["group"]
|
| 191 |
+
for group in groups:
|
| 192 |
+
if group.get("name"):
|
| 193 |
+
name = group["name"]
|
| 194 |
+
if name == office_name:
|
| 195 |
+
return group["officeId"]
|
| 196 |
+
return None
|
| 197 |
+
|
| 198 |
+
async def find_id_provine_by_name_office(self, office_name: str):
|
| 199 |
+
data = await self.search_pickup_points(origin=office_name)
|
| 200 |
+
if data.get["origin"]:
|
| 201 |
+
origins = data["origin"]
|
| 202 |
+
for origin in origins:
|
| 203 |
+
if origin.get("group"):
|
| 204 |
+
groups = origin["group"]
|
| 205 |
+
for group in groups:
|
| 206 |
+
if group.get("name"):
|
| 207 |
+
name = group["name"]
|
| 208 |
+
if name == office_name:
|
| 209 |
+
return group["provinceId"]
|
| 210 |
+
return None
|
| 211 |
+
|
| 212 |
+
async def find_id_and_code_provine_by_name_office(self, office_name: str):
|
| 213 |
+
data = await self.search_pickup_points(origin=office_name)
|
| 214 |
+
if data.get["origin"]:
|
| 215 |
+
origins = data["origin"]
|
| 216 |
+
for origin in origins:
|
| 217 |
+
if origin.get("group"):
|
| 218 |
+
groups = origin["group"]
|
| 219 |
+
for group in groups:
|
| 220 |
+
if group.get("name"):
|
| 221 |
+
name = group["name"]
|
| 222 |
+
if name == office_name:
|
| 223 |
+
return group["provinceId"], group["provinceCode"]
|
| 224 |
+
return None
|
| 225 |
|
| 226 |
async def get_origin_city_from_office(self, origin_office: str):
|
| 227 |
+
data = await self.search_pickup_points(origin=origin_office)
|
| 228 |
if data.get["origin"]:
|
| 229 |
origins = data["origin"]
|
| 230 |
for origin in origins:
|
|
|
|
| 238 |
return None
|
| 239 |
|
| 240 |
async def get_destination_city_from_office(self, dest_office: str):
|
| 241 |
+
data = await self.search_pickup_points(dest=dest_office)
|
| 242 |
if data.get("dest"):
|
| 243 |
dests = data["dest"]
|
| 244 |
for dest in dests:
|