Example #1
0
    def __init__(self, dispatcher):
        threading.Thread.__init__(self)

        from allocations import Allocations
        from matcher_queue import MatcherQueue
        from event_matcher import EventMatcher
        from tracker import Tracker
        from matchings import Matchings
        from service_matcher import ServiceMatcher

        queue = MatcherQueue()
        allocations = Allocations()
        tracker = Tracker()
        matchings = Matchings(allocations=allocations, tracker=tracker)
        event_matcher = EventMatcher(queue=queue, tracker=tracker)
        service_matcher = ServiceMatcher(queue=queue, matchings=matchings)

        self.matchings = matchings
        self.dispatcher = dispatcher
        self.event_matcher = event_matcher
        self.service_matcher = service_matcher
        self.matching_interval = timedelta(minutes=env.matcher_interval)
        self.windowed_gps = windowed_query(
            db_session.query(GPS), GPS.event_time, 1000)
        self.windowed_trust = windowed_query(
            db_session.query(Trust), Trust.event_time, 1000)
Example #2
0
    def __get_allocations(self):
        """Retrieves the allocations from the database.
        """

        query = db_session.query(Schedule).all()

        db_session.close()

        service_allocations = dict()
        unit_allocations = dict()

        for alloc in query:

            service = (alloc.headcode, alloc.origin_location, alloc.origin_departure)
            unit = alloc.unit

            if service not in service_allocations:
                service_allocations[service] = set()
            service_allocations[service].add(unit)

            if unit not in unit_allocations:
                unit_allocations[unit] = set()
            unit_allocations[unit].add(service)

        return (service_allocations, unit_allocations)
Example #3
0
 def clear_tables(self):
     db_session.query(ServiceMatching).delete()
     db_session.commit()
     db_session.close()
Example #4
0
def from_service_matching_pkey(pkey):
    service_matching = db_session.query(ServiceMatching).get(pkey)
    db_session.close()
    if service_matching is not None:
        return from_service_matching(service_matching)