Exemple #1
0
def create(date=datetime.datetime.today()):
    # Retrieve data from database first
    DataRequest('agency', '/agency/agency.json').get()
    DataRequest('holiday', '/route/holiday.json').get()
    DataRequest('joint', '/route/joint.json').get()
    DataRequest('route', '/route/route.json').get()
    DataRequest('schedule', '/route/schedule.json').get()
    DataRequest('segment', '/route/segment.json').get()
    DataRequest('segment_order', '/route/segment_order.json').get()
    DataRequest('service', '/route/service.json').get()
    DataRequest('stop', '/stop/stop.json').get()
    DataRequest('stop_seq', '/route/stop_seq.json').get()

    # Load dependent data
    Stop.load()
    load_segments()
    Service.load()

    # Then process by loading the obtained data
    Joint.load()
    SegmentOrder.load()
    Schedule.load()
    Joint.process()
    Route.set_route_query()
    StopTime.publish_matrix()
    Driver.export()
    Trip.export()
    StopTime.export()
    feed = DateRange.get_obj_by_date(date).get_default_feed()
    DateRange.export()
    return feed
Exemple #2
0
def load(date=datetime.datetime.today()):
    Stop.load()
    load_segments()
    Service.load()
    Joint.load()
    SegmentOrder.load()
    Schedule.load()
    DateRange.load()
    Driver.load()
    Trip.load()
    StopTime.load()
    Route.set_route_query()
    return DateRange.get_obj_by_date(date).get_default_feed()
Exemple #3
0
    def generate_trips(self, loc, driver):
        segment, start_loc = self.get_segment_loc(loc)
        end_loc = start_loc
        start = copy.deepcopy(self.start)
        end = copy.deepcopy(self.end)
        while start < end:

            # Calculate end_loc
            # Find the end time which is the start time + Segment.trip_length - start_loc time
            trip_end = start + datetime.timedelta(seconds=(segment.trip_length-start_loc))
            if trip_end > end:
                end_loc = start_loc + (end - start).total_seconds()
            else:
                end_loc = segment.trip_length

            # Set trip
            Trip(**{
                'id': '-'.join(str(s) for s in [self.joint.id, self.id, segment.id, segment.trip_generator]),
                'schedule': self.id,
                'route': segment.route,
                'service': self.joint.service.id,
                'segment': segment.id,
                'head_sign': 'to {}'.format(segment.direction),
                'direction': segment.dir_type_num,
                'start_loc': start_loc,
                'end_loc': end_loc,
                'start_time': start.strftime('%Y-%m-%d %H:%M:%S'),
                'driver': driver
            }).create_stop_times(segment.query_stop_seqs(start_loc, end_loc), self.joint.service)
            segment.trip_generator += 1

            # Set driver start location -- SHOULD THIS ONLY APPLY IF START NOT EXISTING? OTHERWISE OVERWRITING?
            driver.start = segment.query_min_stop_seq(start_loc, end_loc)

            # Calculate next start
            start_loc = 0
            start = trip_end
            segment = self.order[segment] if trip_end < end else segment
            end_loc = 0 if trip_end == end else end_loc

        # Set self.end_locs
        self.end_locs[self.get_schedule_loc(segment, end_loc)] = driver