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 Meta:
model = UserRoute
fields = ["id", "name", "description", "created"]
fields = ["id", "created"]
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:
data = response.json()
temp_feels = data["forecasts"][0]["parts"]["day"]["feels_like"]
weather = data["forecasts"][0]["parts"]["day_short"]["condition"]
return temp_feels, weather
days = []
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)
def recommendations(self, request, *args, **kwargs):
print("fuck")
return Response(data=get_personal_recomendations(request.user), status=200)
@action(methods=["GET"], detail=True)
@ -111,7 +112,7 @@ def build_events(self, request, *args, **kwargs):
data =serializer.data
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 = [
"attractions",
"museum",

View File

@ -441,7 +441,9 @@ def get_nearest_favorite(
)
if top_k == 1:
try:
return sorted_events[0]
except: return None
return sorted_events[0:top_k]
@ -607,11 +609,25 @@ def generate_path(
"other",
"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:
allowed_types = what_to_see
else:
allowed_types = list(set(allowed_types) & set(what_to_see))
print(allowed_types, hotel)
print(allowed_types)
if isinstance(hotel, City):
start_points_candidate = Restaurant.objects.filter(city=hotel).filter(
~Q(oid__in=disallowed_rests)
@ -708,15 +724,22 @@ def generate_path(
candidates = NearestEvent.objects.get(event=points[-1]).nearest.all()
try:
points.append(
get_nearest_favorite(
fav = get_nearest_favorite(
candidates, user, points[-1], points + disallowed_points
)
if fav is None:
raise ValueError()
points.append(
fav
)
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)
start_time += timedelta(seconds=transition_route["time"])
@ -851,55 +874,55 @@ def range_candidates(candidates, user, favorite_events):
lambda pref: flat_list(
list(
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": [
lambda pref: flat_list(
list(
map(
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": [
lambda pref: flat_list(
list(
map(
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": [
lambda pref: flat_list(
list(
map(
lambda cand: nearest_attraction(cand, 30),
pref.prefferred_attractions.all(),
lambda cand: nearest_attraction(cand, 10),
pref.prefferred_attractions.all()[0:4],
)
),
),
lambda pref: pref.prefferred_attractions.all(),
lambda pref: pref.prefferred_attractions.all()[0:4],
],
"museum": [
lambda pref: flat_list(
list(
map(
lambda cand: nearest_mus(cand, 30),
pref.prefferred_museums.all(),
lambda cand: nearest_mus(cand, 10),
pref.prefferred_museums.all()[0:4],
)
),
),
lambda pref: pref.prefferred_museums.all(),
lambda pref: pref.prefferred_museums.all()[0:10],
],
"shop": [
lambda pref: sample(list(Event.objects.filter(type="shop")), 10),
@ -934,7 +957,9 @@ def get_personal_recomendations(user):
res = []
for category_candidate in up.preferred_categories:
print(category_candidate)
candidates = candidates_generate_strategy[category_candidate][0](up)
print(len(candidates))
ranged = range_candidates(
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 = [
]