This commit is contained in:
ilia 2023-05-28 19:39:42 +03:00
parent 028cc72503
commit ac467f498e
4 changed files with 56 additions and 24 deletions

View File

@ -172,7 +172,7 @@ class InputRouteSerializer(serializers.Serializer):
class ListUserRouteSerializer(serializers.ModelSerializer): class ListUserRouteSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = UserRoute model = UserRoute
fields = ["id", "name", "description", "created"] fields = ["id", "created"]
class UserRouteDateSerializer(serializers.ModelSerializer): class UserRouteDateSerializer(serializers.ModelSerializer):

View File

@ -13,6 +13,9 @@ def get_position_weather(lat: float, lon: float) -> list[(str, str)]:
if response.status_code == 200: if response.status_code == 200:
data = response.json() data = response.json()
temp_feels = data["forecasts"][0]["parts"]["day"]["feels_like"] days = []
weather = data["forecasts"][0]["parts"]["day_short"]["condition"]
return temp_feels, weather for d in data["forecasts"]:
days.append((d["date"], d["parts"]["day_short"]["condition"]))
return days
return []

View File

@ -59,6 +59,7 @@ class PersonalRecommendation(viewsets.GenericViewSet):
@action(methods=["GET"], detail=False, serializer_class=SelfRecomendationSerializer) @action(methods=["GET"], detail=False, serializer_class=SelfRecomendationSerializer)
def recommendations(self, request, *args, **kwargs): def recommendations(self, request, *args, **kwargs):
print("fuck")
return Response(data=get_personal_recomendations(request.user), status=200) return Response(data=get_personal_recomendations(request.user), status=200)
@action(methods=["GET"], detail=True) @action(methods=["GET"], detail=True)
@ -111,7 +112,7 @@ def build_events(self, request, *args, **kwargs):
data =serializer.data data =serializer.data
what_to_see = data["what_to_see"] what_to_see = data["what_to_see"]
if what_to_see is None: if what_to_see is None or not len(what_to_see):
what_to_see = [ what_to_see = [
"attractions", "attractions",
"museum", "museum",

View File

@ -441,7 +441,9 @@ def get_nearest_favorite(
) )
if top_k == 1: if top_k == 1:
try:
return sorted_events[0] return sorted_events[0]
except: return None
return sorted_events[0:top_k] return sorted_events[0:top_k]
@ -607,11 +609,25 @@ def generate_path(
"other", "other",
"viewpoint", "viewpoint",
] ]
if not len(what_to_see):
what_to_see=[
"attractions",
"museum",
"movie",
"concert",
"artwork",
"plays",
"shop",
"gallery",
"theme_park",
"viewpoint",
"zoo",
]
if len(set(allowed_types) & set(what_to_see)) == 0: if len(set(allowed_types) & set(what_to_see)) == 0:
allowed_types = what_to_see allowed_types = what_to_see
else: else:
allowed_types = list(set(allowed_types) & set(what_to_see)) allowed_types = list(set(allowed_types) & set(what_to_see))
print(allowed_types, hotel) print(allowed_types)
if isinstance(hotel, City): if isinstance(hotel, City):
start_points_candidate = Restaurant.objects.filter(city=hotel).filter( start_points_candidate = Restaurant.objects.filter(city=hotel).filter(
~Q(oid__in=disallowed_rests) ~Q(oid__in=disallowed_rests)
@ -708,15 +724,22 @@ def generate_path(
candidates = NearestEvent.objects.get(event=points[-1]).nearest.all() candidates = NearestEvent.objects.get(event=points[-1]).nearest.all()
try: try:
points.append( fav = get_nearest_favorite(
get_nearest_favorite(
candidates, user, points[-1], points + disallowed_points candidates, user, points[-1], points + disallowed_points
) )
if fav is None:
raise ValueError()
points.append(
fav
) )
except: except:
points.append(get_nearest_favorite(candidates, user, points[-1], points)) fav = get_nearest_favorite(candidates, user, points[-1], points)
if fav is None:
return points, path, disallowed_rests
points.append(fav)
print(points, "points")
transition_route = generate_route(points[-1], points[-2], avg_velocity) transition_route = generate_route(points[-1], points[-2], avg_velocity)
start_time += timedelta(seconds=transition_route["time"]) start_time += timedelta(seconds=transition_route["time"])
@ -851,55 +874,55 @@ def range_candidates(candidates, user, favorite_events):
lambda pref: flat_list( lambda pref: flat_list(
list( list(
map( map(
lambda cand: nearest_plays(cand, 30), pref.preffered_plays.all() lambda cand: nearest_plays(cand, 10), pref.preffered_plays.all()[0:5]
) )
), ),
), ),
lambda pref: pref.preffered_plays.all(), lambda pref: pref.preffered_plays.all()[0:10],
], ],
"movie": [ "movie": [
lambda pref: flat_list( lambda pref: flat_list(
list( list(
map( map(
lambda cand: nearest_movie(cand, 30), lambda cand: nearest_movie(cand, 30),
pref.preffered_movies.all(), pref.preffered_movies.all()[0:4],
) )
), ),
), ),
lambda pref: pref.preffered_movies.all(), lambda pref: pref.preffered_movies.all()[0:10],
], ],
"concert": [ "concert": [
lambda pref: flat_list( lambda pref: flat_list(
list( list(
map( map(
lambda cand: nearest_concert(cand, 30), lambda cand: nearest_concert(cand, 30),
pref.preferred_concerts.all(), pref.preferred_concerts.all()[0:4],
) )
), ),
), ),
lambda pref: pref.preferred_concerts.all(), lambda pref: pref.preferred_concerts.all()[0:4],
], ],
"attractions": [ "attractions": [
lambda pref: flat_list( lambda pref: flat_list(
list( list(
map( map(
lambda cand: nearest_attraction(cand, 30), lambda cand: nearest_attraction(cand, 10),
pref.prefferred_attractions.all(), pref.prefferred_attractions.all()[0:4],
) )
), ),
), ),
lambda pref: pref.prefferred_attractions.all(), lambda pref: pref.prefferred_attractions.all()[0:4],
], ],
"museum": [ "museum": [
lambda pref: flat_list( lambda pref: flat_list(
list( list(
map( map(
lambda cand: nearest_mus(cand, 30), lambda cand: nearest_mus(cand, 10),
pref.prefferred_museums.all(), pref.prefferred_museums.all()[0:4],
) )
), ),
), ),
lambda pref: pref.prefferred_museums.all(), lambda pref: pref.prefferred_museums.all()[0:10],
], ],
"shop": [ "shop": [
lambda pref: sample(list(Event.objects.filter(type="shop")), 10), lambda pref: sample(list(Event.objects.filter(type="shop")), 10),
@ -934,7 +957,9 @@ def get_personal_recomendations(user):
res = [] res = []
for category_candidate in up.preferred_categories: for category_candidate in up.preferred_categories:
print(category_candidate)
candidates = candidates_generate_strategy[category_candidate][0](up) candidates = candidates_generate_strategy[category_candidate][0](up)
print(len(candidates))
ranged = range_candidates( ranged = range_candidates(
candidates, user, candidates_generate_strategy[category_candidate][1](up) candidates, user, candidates_generate_strategy[category_candidate][1](up)
) )
@ -973,4 +998,7 @@ def get_events(
) )
def remap_points(date: datetime.date, region: City, ) def remap_points(date: datetime.date, region: City, point: Event):
allowed_types = [
]