From c731886dc6bdcfb8299c15f0dc2e7a4fc9fdf8b3 Mon Sep 17 00:00:00 2001 From: ilia Date: Sat, 27 May 2023 23:59:50 +0300 Subject: [PATCH] change schema to save --- passfinder/events/api/views.py | 67 +++++++++++--------- passfinder/recomendations/service/service.py | 5 +- 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/passfinder/events/api/views.py b/passfinder/events/api/views.py index 0bc09e3..68538cb 100644 --- a/passfinder/events/api/views.py +++ b/passfinder/events/api/views.py @@ -111,38 +111,47 @@ def post(self, request): region = None - if city_id: - region = get_object_or_404(City, oid=city_id) - else: - region = choice(City.objects.annotate(points_count=Count('points')).filter(title__in=city_in_hotels).filter(points_count__gt=400)) - if not start_date and end_date: - tour_length = choice([timedelta(days=i) for i in range(1, 4)]) - start_date = end_date - tour_length - if not end_date and start_date: - tour_length = choice([timedelta(days=i) for i in range(1, 4)]) - end_date = end_date + tour_length - if not end_date and not start_date: - max_date = datetime.now() + timedelta(days=15) - start_date = choice([max_date - timedelta(days=i) for i in range(1, 5)]) - tour_length = choice([timedelta(days=i) for i in range(1, 4)]) - end_date = start_date + tour_length + res = [] - print(request.user, region, start_date, end_date) + for _ in range(5): - tour = generate_tour( - request.user, - region, - start_date, - end_date, - avg_velocity=movement_mapping[movement], - stars=hotel_stars, - hotel_type=hotel_type, - where_eat=where_eat, - what_to_see=what_to_see - ) - print(len(tour[1])) + if city_id: + region = get_object_or_404(City, oid=city_id) + else: + region = choice(City.objects.annotate(points_count=Count('points')).filter(title__in=city_in_hotels).filter(points_count__gt=400)) + if not start_date and end_date: + tour_length = choice([timedelta(days=i) for i in range(1, 4)]) + start_date = end_date - tour_length + if not end_date and start_date: + tour_length = choice([timedelta(days=i) for i in range(1, 4)]) + end_date = end_date + tour_length + if not end_date and not start_date: + max_date = datetime.now() + timedelta(days=15) + start_date = choice([max_date - timedelta(days=i) for i in range(1, 5)]) + tour_length = choice([timedelta(days=i) for i in range(1, 4)]) + end_date = start_date + tour_length - return Response(data=tour[0]) + print(request.user, region, start_date, end_date) + + tour = generate_tour( + request.user, + region, + start_date, + end_date, + avg_velocity=movement_mapping[movement], + stars=hotel_stars, + hotel_type=hotel_type, + where_eat=where_eat, + what_to_see=what_to_see + ) + res.append({ + 'city': region.title, + 'date_from': start_date, + 'date_to': end_date, + 'path': tour[0] + }) + + return Response(data=res) class ListRegionApiView(ListAPIView): diff --git a/passfinder/recomendations/service/service.py b/passfinder/recomendations/service/service.py index cdb6700..dee0b7e 100644 --- a/passfinder/recomendations/service/service.py +++ b/passfinder/recomendations/service/service.py @@ -482,7 +482,8 @@ def generate_point(point: BasePoint): "type": "point", "point": event_data, "point_type": "point", - "time": timedelta(minutes=90+choice(range(-10, 90, 10))).seconds + "time": timedelta(minutes=90+choice(range(-10, 90, 10))).seconds, + "distance": 0 } @@ -555,6 +556,8 @@ def generate_hotel(hotel: Hotel): "type": "point", "point": hotel_data, "point_type": "hotel", + "time": 0, + "distance": 0 }