Skip to content

Commit

Permalink
feat: add config parameter max_age_carpool_offers_in_days (default=180)
Browse files Browse the repository at this point in the history
  • Loading branch information
hbruch committed May 6, 2024
1 parent f5642cd commit 0c33f5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions amarillo/services/carpools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from datetime import datetime
from typing import Dict
from amarillo.models.Carpool import Carpool
from amarillo.services.config import config
from amarillo.services.trips import TripStore
from amarillo.utils.utils import yesterday, is_older_than_days

logger = logging.getLogger(__name__)

class CarpoolService():
MAX_OFFER_AGE_IN_DAYS = 180

def __init__(self, trip_store):


def __init__(self, trip_store, max_age_carpool_offers_in_days: int = 180):
self.max_age_carpool_offers_in_days = max_age_carpool_offers_in_days
self.trip_store = trip_store
self.carpools: Dict[str, Carpool] = {}

Expand All @@ -22,10 +22,10 @@ def is_outdated(self, carpool):
* it's completly in the past (if it's a single date offer).
As we know the start time but not latest arrival, we deem
offers starting the day before yesterday as outdated
* it's last update occured before MAX_OFFER_AGE_IN_DAYS
* it's last update occured before self.max_age_carpool_offers_in_days
"""
runs_once = not isinstance(carpool.departureDate, set)
return (is_older_than_days(carpool.lastUpdated.date(), self.MAX_OFFER_AGE_IN_DAYS) or
return (is_older_than_days(carpool.lastUpdated.date(), self.max_age_carpool_offers_in_days) or
(runs_once and carpool.departureDate < yesterday()))

def purge_outdated_offers(self):
Expand Down
1 change: 1 addition & 0 deletions amarillo/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class Config(BaseSettings):
env: str = 'DEV'
graphhopper_base_url: str = 'https://api.mfdz.de/gh'
stop_sources_file: str = 'conf/stop_sources.json'
max_age_carpool_offers_in_days: int = 180

config = Config(_env_file='config', _env_file_encoding='utf-8')

0 comments on commit 0c33f5a

Please sign in to comment.