Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MES v 2.0.4 #31

Merged
merged 8 commits into from
Sep 20, 2023
60 changes: 22 additions & 38 deletions apps/recommendation/api/src/huggy/crud/offer.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,47 +97,31 @@ def get_nearest_offers(
)

start = time.time()
if user.latitude is not None and user.longitude is not None:
user_geolocated = True
user_point = WKTElement(f"POINT({user.latitude} {user.longitude})")
user_distance = func.ST_Distance(
user_point,
func.Geometry(
func.ST_MakePoint(
offer_table.venue_longitude,
offer_table.venue_latitude,
)
),
).label("user_distance")

if offer_table.is_geolocated:
user_distance_condition = [
offer_table.default_max_distance >= user_distance
]
offer_rank = (
func.row_number()
.over(partition_by=offer_table.item_id, order_by=user_distance)
.label("offer_rank")
)
else:
user_distance_condition = [1 == 1]
offer_rank = (
func.row_number()
.over(
partition_by=offer_table.item_id, order_by=offer_table.stock_price
)
.label("offer_rank")
# if user.latitude is not None and user.longitude is not None:
# user_geolocated = True
user_point = WKTElement(f"POINT({user.latitude} {user.longitude})")
user_distance = func.ST_Distance(
user_point,
func.Geometry(
func.ST_MakePoint(
offer_table.venue_longitude,
offer_table.venue_latitude,

)
),
).label("user_distance")

else:
user_geolocated = False
user_distance = None
user_distance_condition = [1 == 1]
offer_rank = (
func.row_number()
.over(partition_by=offer_table.item_id, order_by=offer_table.stock_price)
.label("offer_rank")
user_distance_condition = [
offer_table.default_max_distance >= func.coalesce(user_distance, 0)
]
offer_rank = (
func.row_number()
.over(
partition_by=offer_table.item_id,
order_by=func.coalesce(user_distance, offer_table.stock_price),
)
.label("offer_rank")
)

# print(f"user_geolocated : {user_geolocated}")
# print(f"user_distance : {user_distance}")
Expand Down
Loading