shorter lines
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m27s
Run linting on the backend code / Build (pull_request) Failing after 36s
Run testing on the backend code / Build (pull_request) Failing after 1m25s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 15s
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m27s
Run linting on the backend code / Build (pull_request) Failing after 36s
Run testing on the backend code / Build (pull_request) Failing after 1m25s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 15s
This commit is contained in:
@@ -70,13 +70,14 @@ class Landmark(BaseModel) :
|
||||
str: A formatted string with the landmark's type, name, location, attractiveness score,
|
||||
time to the next landmark (if available), and whether the landmark is secondary.
|
||||
"""
|
||||
time_to_next_str = f", time_to_next={self.time_to_reach_next}" if self.time_to_reach_next else ""
|
||||
t_to_next_str = f", time_to_next={self.time_to_reach_next}" if self.time_to_reach_next else ""
|
||||
is_secondary_str = ", secondary" if self.is_secondary else ""
|
||||
type_str = '(' + self.type + ')'
|
||||
if self.type in ["start", "finish", "nature", "shopping"] :
|
||||
type_str += '\t '
|
||||
|
||||
return f'Landmark{type_str}: [{self.name} @{self.location}, score={self.attractiveness}{time_to_next_str}{is_secondary_str}]'
|
||||
return (f'Landmark{type_str}: [{self.name} @{self.location}, '
|
||||
f'score={self.attractiveness}{t_to_next_str}{is_secondary_str}]')
|
||||
|
||||
def distance(self, value: 'Landmark') -> float:
|
||||
"""
|
||||
@@ -113,4 +114,6 @@ class Landmark(BaseModel) :
|
||||
# in particular, if two objects are equal, their hash must be equal
|
||||
# uuid and osm_id are just shortcuts to avoid comparing all the properties
|
||||
# if they are equal, we know that the name is also equal and in turn the hash is equal
|
||||
return self.uuid == value.uuid or self.osm_id == value.osm_id or (self.name == value.name and self.distance(value) < 0.001)
|
||||
return (self.uuid == value.uuid or
|
||||
self.osm_id == value.osm_id or
|
||||
(self.name == value.name and self.distance(value) < 0.001))
|
||||
|
@@ -6,9 +6,11 @@ from ..utils.get_time_separation import get_time
|
||||
class LinkedLandmarks:
|
||||
"""
|
||||
A list of landmarks that are linked together, e.g. in a route.
|
||||
Each landmark serves as a node in the linked list, but since we expect these to be consumed through the rest API,
|
||||
a pythonic reference to the next landmark is not well suited. Instead we use the uuid of the next landmark
|
||||
to reference the next landmark in the list. This is not very efficient, but appropriate for the expected use case
|
||||
Each landmark serves as a node in the linked list, but since we expect
|
||||
these to be consumed through the rest API, a pythonic reference to the next
|
||||
landmark is not well suited. Instead we use the uuid of the next landmark
|
||||
to reference the next landmark in the list. This is not very efficient,
|
||||
but appropriate for the expected use case
|
||||
("short" trips with onyl few landmarks).
|
||||
"""
|
||||
|
||||
@@ -21,7 +23,8 @@ class LinkedLandmarks:
|
||||
where the first landmark is the starting point and the last landmark is the end point.
|
||||
|
||||
Args:
|
||||
data (list[Landmark], optional): The list of landmarks that are linked together. Defaults to None.
|
||||
data (list[Landmark], optional): The list of landmarks that are linked together.
|
||||
Defaults to None.
|
||||
"""
|
||||
self._landmarks = data if data else []
|
||||
self._link_landmarks()
|
||||
@@ -29,7 +32,8 @@ class LinkedLandmarks:
|
||||
|
||||
def _link_landmarks(self) -> None:
|
||||
"""
|
||||
Create the links between the landmarks in the list by setting their .next_uuid and the .time_to_next attributes.
|
||||
Create the links between the landmarks in the list by setting their
|
||||
.next_uuid and the .time_to_next attributes.
|
||||
"""
|
||||
|
||||
# Mark secondary landmarks as such
|
||||
@@ -57,12 +61,12 @@ class LinkedLandmarks:
|
||||
if len(scores) >= 10:
|
||||
threshold_score = scores[9]
|
||||
else:
|
||||
# If there are fewer than 10 landmarks, use the lowest score in the list as the threshold
|
||||
# If there are fewer than 10 landmarks, use the lowest score as the threshold
|
||||
threshold_score = min(scores) if scores else 0
|
||||
|
||||
# Update 'is_secondary' for landmarks with attractiveness below the threshold score
|
||||
for landmark in self._landmarks:
|
||||
if landmark.attractiveness < threshold_score and landmark.type not in ["start", "finish"]:
|
||||
if (landmark.attractiveness < threshold_score and landmark.type not in ["start", "finish"]):
|
||||
landmark.is_secondary = True
|
||||
|
||||
|
||||
|
@@ -36,8 +36,11 @@ class Trip(BaseModel):
|
||||
|
||||
# Store the trip in the cache
|
||||
cache_client.set(f"trip_{trip.uuid}", trip)
|
||||
# make sure to await the result (noreply=False). Otherwise the cache might not be inplace when the trip is actually requested
|
||||
cache_client.set_many({f"landmark_{landmark.uuid}": landmark for landmark in landmarks}, expire=3600, noreply=False)
|
||||
|
||||
# Make sure to await the result (noreply=False).
|
||||
# Otherwise the cache might not be inplace when the trip is actually requested.
|
||||
cache_client.set_many({f"landmark_{landmark.uuid}": landmark for landmark in landmarks},
|
||||
expire=3600, noreply=False)
|
||||
# is equivalent to:
|
||||
# for landmark in landmarks:
|
||||
# cache_client.set(f"landmark_{landmark.uuid}", landmark, expire=3600)
|
||||
|
Reference in New Issue
Block a user