From 84b1f81cc938ed54a1bd5bd17880f08a18e94608 Mon Sep 17 00:00:00 2001 From: maksim Date: Sun, 9 Jun 2024 16:42:05 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- genetic_algorithm/genetic_algorithm.py | 1 + router_flight.py | 6 +++--- schemas.py | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/genetic_algorithm/genetic_algorithm.py b/genetic_algorithm/genetic_algorithm.py index 2f53d2c..ff5697b 100644 --- a/genetic_algorithm/genetic_algorithm.py +++ b/genetic_algorithm/genetic_algorithm.py @@ -185,6 +185,7 @@ def genetic_algorithm(start, end, graph, flights_data, type, departure_date, pop for flight in flights_data: if flight['departurePoint'] == path[i] and flight['destinationPoint'] == path[i + 1]: path_data.append({ + "id": flight['id'], "departurePoint": flight['departurePoint'], "destinationPoint": flight['destinationPoint'] }) diff --git a/router_flight.py b/router_flight.py index 4a19a8f..d95448d 100644 --- a/router_flight.py +++ b/router_flight.py @@ -11,7 +11,7 @@ router = APIRouter( ) -@router.post("/get/", response_model=List[TripOption]) +@router.post("/get/", response_model=List[List[TripOption]]) async def get_flight(request: TripRequest): graphTo, graphBack, start_point, end_point, flightsDataTo, flightsDataBack, departure_date, departure_date_return = load_graph_from_request( request) @@ -28,7 +28,7 @@ async def get_flight(request: TripRequest): for back_trip in resultFrom: to_segments = [FlightSegment(**segment) for segment in to_trip["to"]] back_segments = [FlightSegment(**segment) for segment in back_trip["back"]] - trip_options.append(TripOption(to=to_segments, back=back_segments)) + trip_options.append([TripOption(to=to_segments, back=back_segments)]) return trip_options @@ -38,7 +38,7 @@ async def get_flight(request: TripRequest): if not resultTo: raise HTTPException(status_code=404, detail="No valid paths found") - trip_options = [TripOption(to=[FlightSegment(**segment) for segment in trip["to"]], back=[]) for trip in + trip_options = [[TripOption(to=[FlightSegment(**segment) for segment in trip["to"]], back=[])] for trip in resultTo] return trip_options diff --git a/schemas.py b/schemas.py index 954a90f..b53590c 100644 --- a/schemas.py +++ b/schemas.py @@ -47,6 +47,7 @@ class Review(BaseModel): name_ru: str class FlightSegment(BaseModel): + id: int departurePoint: str destinationPoint: str