コード例 #1
0
def make_mock_kirin_item(vj_id,
                         date,
                         status='canceled',
                         new_stop_time_list=[],
                         disruption_id=None):
    feed_message = gtfs_realtime_pb2.FeedMessage()
    feed_message.header.gtfs_realtime_version = '1.0'
    feed_message.header.incrementality = gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
    feed_message.header.timestamp = 0

    entity = feed_message.entity.add()
    entity.id = disruption_id or "id={}".format(uuid.uuid1())
    trip_update = entity.trip_update

    trip = trip_update.trip
    trip.trip_id = vj_id  #
    trip.start_date = date

    if status == 'canceled':
        trip.schedule_relationship = gtfs_realtime_pb2.TripDescriptor.CANCELED
    elif status == 'delayed':
        trip.schedule_relationship = gtfs_realtime_pb2.TripDescriptor.SCHEDULED
        for st in new_stop_time_list:
            stop_time_update = trip_update.stop_time_update.add()
            stop_time_update.stop_id = st[0]
            stop_time_update.arrival.time = st[1]
            stop_time_update.departure.time = st[2]
            if len(st) > 3:
                stop_time_update.Extensions[kirin_pb2.stoptime_message] = st[3]
    else:
        #TODO
        pass

    return feed_message.SerializeToString()
コード例 #2
0
def make_mock_kirin_item(vj_id,
                         date,
                         status='canceled',
                         new_stop_time_list=[]):
    feed_message = gtfs_realtime_pb2.FeedMessage()
    feed_message.header.gtfs_realtime_version = '1.0'
    feed_message.header.incrementality = gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
    feed_message.header.timestamp = 0

    entity = feed_message.entity.add()
    entity.id = "96231_2015-07-28_0"
    trip_update = entity.trip_update

    trip = trip_update.trip
    trip.trip_id = vj_id  #
    trip.start_date = date

    if status == 'canceled':
        trip.schedule_relationship = gtfs_realtime_pb2.TripDescriptor.CANCELED
    elif status == 'delayed':
        trip.schedule_relationship = gtfs_realtime_pb2.TripDescriptor.SCHEDULED
        for st in new_stop_time_list:
            stop_time_update = trip_update.stop_time_update.add()
            stop_time_update.stop_id = st[0]
            stop_time_update.arrival.time = st[1]
            stop_time_update.departure.time = st[2]
    else:
        #TODO
        pass

    return feed_message.SerializeToString()
コード例 #3
0
ファイル: kirin_realtime_tests.py プロジェクト: Xzya/navitia
def make_mock_kirin_item(vj_id,
                         date,
                         status='canceled',
                         new_stop_time_list=[],
                         disruption_id=None):
    feed_message = gtfs_realtime_pb2.FeedMessage()
    feed_message.header.gtfs_realtime_version = '1.0'
    feed_message.header.incrementality = gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
    feed_message.header.timestamp = 0

    entity = feed_message.entity.add()
    entity.id = disruption_id or "{}".format(uuid.uuid1())
    trip_update = entity.trip_update

    trip = trip_update.trip
    trip.trip_id = vj_id
    trip.start_date = date
    trip.Extensions[kirin_pb2.contributor] = rt_topic

    if status == 'canceled':
        trip.schedule_relationship = gtfs_realtime_pb2.TripDescriptor.CANCELED
    elif status == 'modified':
        trip.schedule_relationship = gtfs_realtime_pb2.TripDescriptor.SCHEDULED
        for st in new_stop_time_list:
            stop_time_update = trip_update.stop_time_update.add()
            stop_time_update.stop_id = st.stop_id
            stop_time_update.arrival.time = st.arrival
            stop_time_update.arrival.delay = st.arrival_delay
            stop_time_update.departure.time = st.departure
            stop_time_update.departure.delay = st.departure_delay

            def get_relationship(is_skipped):
                if is_skipped:
                    return gtfs_realtime_pb2.TripUpdate.StopTimeUpdate.SKIPPED
                return gtfs_realtime_pb2.TripUpdate.StopTimeUpdate.SCHEDULED

            stop_time_update.arrival.Extensions[
                kirin_pb2.stop_time_event_relationship] = get_relationship(
                    st.arrival_skipped)
            stop_time_update.departure.Extensions[
                kirin_pb2.stop_time_event_relationship] = get_relationship(
                    st.departure_skipped)
            if st.message:
                stop_time_update.Extensions[
                    kirin_pb2.stoptime_message] = st.message
    else:
        # TODO
        pass

    return feed_message.SerializeToString()
コード例 #4
0
def make_mock_chaos_item(disruption_name,
                         impacted_obj,
                         impacted_obj_type,
                         start,
                         end,
                         message_text='default_message',
                         is_deleted=False,
                         blocking=False,
                         start_period="20100412T165200",
                         end_period="20200412T165200"):
    feed_message = gtfs_realtime_pb2.FeedMessage()
    feed_message.header.gtfs_realtime_version = '1.0'
    feed_message.header.incrementality = gtfs_realtime_pb2.FeedHeader.DIFFERENTIAL
    feed_message.header.timestamp = 0

    feed_entity = feed_message.entity.add()
    feed_entity.id = disruption_name
    feed_entity.is_deleted = is_deleted

    disruption = feed_entity.Extensions[chaos_pb2.disruption]

    disruption.id = disruption_name
    disruption.cause.id = "CauseTest"
    disruption.cause.wording = "CauseTest"
    disruption.reference = "DisruptionTest"
    disruption.publication_period.start = utils.str_to_time_stamp(start_period)
    disruption.publication_period.end = utils.str_to_time_stamp(end_period)

    # Tag
    tag = disruption.tags.add()
    tag.name = "rer"
    tag.id = "rer"
    tag = disruption.tags.add()
    tag.name = "metro"
    tag.id = "rer"

    if not impacted_obj or not impacted_obj_type:
        return feed_message.SerializeToString()

    # Impacts
    impact = disruption.impacts.add()
    impact.id = "impact_" + disruption_name + "_1"
    enums_impact = gtfs_realtime_pb2.Alert.DESCRIPTOR.enum_values_by_name
    if blocking:
        impact.severity.effect = enums_impact["NO_SERVICE"].number
        impact.severity.id = 'blocking'
        impact.severity.priority = 10
        impact.severity.wording = "blocking"
        impact.severity.color = "#FFFF00"
    else:
        impact.severity.effect = enums_impact["UNKNOWN_EFFECT"].number
        impact.severity.id = ' not blocking'
        impact.severity.priority = 1
        impact.severity.wording = "not blocking"
        impact.severity.color = "#FFFFF0"

    # ApplicationPeriods
    application_period = impact.application_periods.add()
    application_period.start = utils.str_to_time_stamp(start_period)
    application_period.end = utils.str_to_time_stamp(end_period)

    # PTobject
    type_col = {
        "network": chaos_pb2.PtObject.network,
        "stop_area": chaos_pb2.PtObject.stop_area,
        "line": chaos_pb2.PtObject.line,
        "line_section": chaos_pb2.PtObject.line_section,
        "route": chaos_pb2.PtObject.route
    }

    ptobject = impact.informed_entities.add()
    ptobject.uri = impacted_obj
    ptobject.pt_object_type = type_col.get(impacted_obj_type,
                                           chaos_pb2.PtObject.unkown_type)
    if ptobject.pt_object_type == chaos_pb2.PtObject.line_section:
        line_section = ptobject.pt_line_section
        line_section.line.uri = impacted_obj
        line_section.line.pt_object_type = chaos_pb2.PtObject.line
        pb_start = line_section.start_point
        pb_start.uri = start
        pb_start.pt_object_type = chaos_pb2.PtObject.stop_area
        pb_end = line_section.end_point
        pb_end.uri = end
        pb_end.pt_object_type = chaos_pb2.PtObject.stop_area

    # Messages
    message = impact.messages.add()
    message.text = message_text
    message.channel.id = "sms"
    message.channel.name = "sms"
    message.channel.max_size = 60
    message.channel.content_type = "text"

    message = impact.messages.add()
    message.text = message_text
    message.channel.name = "email"
    message.channel.id = "email"
    message.channel.max_size = 250
    message.channel.content_type = "html"

    return feed_message.SerializeToString()