persistence for recurring api calls
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Build and push docker image / Build (pull_request) Successful in 1m48s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Build and push docker image / Build (pull_request) Successful in 1m48s
				
			This commit is contained in:
		@@ -1,4 +1,3 @@
 | 
			
		||||
import uuid
 | 
			
		||||
from .landmark import Landmark
 | 
			
		||||
from utils.get_time_separation import get_time
 | 
			
		||||
 | 
			
		||||
@@ -9,8 +8,7 @@ class LinkedLandmarks:
 | 
			
		||||
    """
 | 
			
		||||
    
 | 
			
		||||
    _landmarks = list[Landmark]
 | 
			
		||||
    total_time = int
 | 
			
		||||
    uuid = str
 | 
			
		||||
    total_time: int = 0
 | 
			
		||||
 | 
			
		||||
    def __init__(self, data: list[Landmark] = None) -> None:
 | 
			
		||||
        """
 | 
			
		||||
@@ -19,7 +17,6 @@ class LinkedLandmarks:
 | 
			
		||||
        Args:
 | 
			
		||||
            data (list[Landmark], optional): The list of landmarks that are linked together. Defaults to None.
 | 
			
		||||
        """
 | 
			
		||||
        self.uuid = uuid.uuid4()
 | 
			
		||||
        self._landmarks = data if data else []
 | 
			
		||||
        self._link_landmarks()
 | 
			
		||||
 | 
			
		||||
@@ -28,7 +25,6 @@ class LinkedLandmarks:
 | 
			
		||||
        """
 | 
			
		||||
        Create the links between the landmarks in the list by setting their .next_uuid and the .time_to_next attributes.
 | 
			
		||||
        """
 | 
			
		||||
        self.total_time = 0
 | 
			
		||||
        for i, landmark in enumerate(self._landmarks[:-1]):
 | 
			
		||||
            landmark.next_uuid = self._landmarks[i + 1].uuid
 | 
			
		||||
            time_to_next = get_time(landmark.location, self._landmarks[i + 1].location)
 | 
			
		||||
@@ -44,18 +40,4 @@ class LinkedLandmarks:
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    def __str__(self) -> str:
 | 
			
		||||
        return f"LinkedLandmarks, total time: {self.total_time} minutes, {len(self._landmarks)} stops: [{','.join([str(landmark) for landmark in self._landmarks])}]"
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    def asdict(self) -> dict:
 | 
			
		||||
        """
 | 
			
		||||
        Convert the linked landmarks to a json serializable dictionary.
 | 
			
		||||
        
 | 
			
		||||
        Returns:
 | 
			
		||||
            dict: A dictionary representation of the linked landmarks.
 | 
			
		||||
        """
 | 
			
		||||
        return {
 | 
			
		||||
            'uuid': self.uuid,
 | 
			
		||||
            'total_time': self.total_time,
 | 
			
		||||
            'landmarks': [landmark.dict() for landmark in self._landmarks]
 | 
			
		||||
        }
 | 
			
		||||
        return f"LinkedLandmarks [{' ->'.join([str(landmark) for landmark in self._landmarks])}]"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user