This commit is contained in:
Csaba 2024-03-21 16:02:40 +01:00
commit 0284f29ce4
3 changed files with 17 additions and 9 deletions

View file

@ -14,7 +14,15 @@ from amarillo.configuration import configure_services
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
enhancer_configured = False
def configure_enhancer_services(): def configure_enhancer_services():
#Make sure configuration only happens once
global enhancer_configured
if enhancer_configured:
logger.info("Enhancer is already configured")
return
configure_services() configure_services()
logger.info("Load stops...") logger.info("Load stops...")
@ -45,5 +53,5 @@ def configure_enhancer_services():
container['carpools'].delete(carpool.agency, carpool.id) container['carpools'].delete(carpool.agency, carpool.id)
logger.info("Restored carpools: %s", container['carpools'].get_all_ids()) logger.info("Restored carpools: %s", container['carpools'].get_all_ids())
logger.info("Starting scheduler")
gtfs_generator.start_schedule() enhancer_configured = True

View file

@ -70,7 +70,7 @@ def run_enhancer():
logger.info("Goodbye Enhancer") logger.info("Goodbye Enhancer")
def setup(app): def setup(app):
thread = Thread(target=run_enhancer) thread = Thread(target=run_enhancer, daemon=True)
thread.start() thread.start()

View file

@ -1,5 +1,5 @@
from amarillo.plugins.enhancer.models.gtfs import GtfsTimeDelta, GtfsStopTime from amarillo.plugins.enhancer.models.gtfs import GtfsTimeDelta, GtfsStopTime
from amarillo.models.Carpool import MAX_STOPS_PER_TRIP, Carpool, Weekday, StopTime, PickupDropoffType from amarillo.models.Carpool import MAX_STOPS_PER_TRIP, Carpool, Weekday, StopTime, PickupDropoffType, Driver, RidesharingInfo
from amarillo.services.config import config from amarillo.services.config import config
from amarillo.plugins.enhancer.services.gtfs_constants import * from amarillo.plugins.enhancer.services.gtfs_constants import *
from amarillo.plugins.enhancer.services.routing import RoutingService, RoutingException from amarillo.plugins.enhancer.services.routing import RoutingService, RoutingException
@ -17,8 +17,7 @@ logger = logging.getLogger(__name__)
class Trip: class Trip:
# TODO: add driver attributes, additional ridesharing info def __init__(self, trip_id, route_name, headsign, url, calendar, departureTime, path, agency, lastUpdated, stop_times, driver: Driver, additional_ridesharing_info: RidesharingInfo, bbox):
def __init__(self, trip_id, route_name, headsign, url, calendar, departureTime, path, agency, lastUpdated, stop_times, bbox):
if isinstance(calendar, set): if isinstance(calendar, set):
self.runs_regularly = True self.runs_regularly = True
self.weekdays = [ self.weekdays = [
@ -44,6 +43,8 @@ class Trip:
self.stops = [] self.stops = []
self.lastUpdated = lastUpdated self.lastUpdated = lastUpdated
self.stop_times = stop_times self.stop_times = stop_times
self.driver = driver
self.additional_ridesharing_info = additional_ridesharing_info
self.bbox = bbox self.bbox = bbox
self.route_name = route_name self.route_name = route_name
self.trip_headsign = headsign self.trip_headsign = headsign
@ -204,7 +205,7 @@ class TripTransformer:
def __init__(self, stops_store): def __init__(self, stops_store):
self.stops_store = stops_store self.stops_store = stops_store
def transform_to_trip(self, carpool): def transform_to_trip(self, carpool : Carpool):
stop_times = self._convert_stop_times(carpool) stop_times = self._convert_stop_times(carpool)
route_name = carpool.stops[0].name + " nach " + carpool.stops[-1].name route_name = carpool.stops[0].name + " nach " + carpool.stops[-1].name
headsign= carpool.stops[-1].name headsign= carpool.stops[-1].name
@ -216,8 +217,7 @@ class TripTransformer:
max([pt[0] for pt in path.coordinates]), max([pt[0] for pt in path.coordinates]),
max([pt[1] for pt in path.coordinates])) max([pt[1] for pt in path.coordinates]))
# TODO: pass driver and ridesharing info object to the Trip constructor trip = Trip(trip_id, route_name, headsign, str(carpool.deeplink), carpool.departureDate, carpool.departureTime, carpool.path, carpool.agency, carpool.lastUpdated, stop_times, carpool.driver, carpool.additional_ridesharing_info, bbox)
trip = Trip(trip_id, route_name, headsign, str(carpool.deeplink), carpool.departureDate, carpool.departureTime, carpool.path, carpool.agency, carpool.lastUpdated, stop_times, bbox)
return trip return trip