Beispiel #1
0
class DateTimeTypeSerializer(PbNestedSerializer):
    date_time = jsonschema.MethodField(schema_type=TimeOrDateTimeType,
                                       display_none=True)
    base_date_time = DateTimeField()
    additional_informations = pt.AdditionalInformation(
        attr='additional_informations', display_none=True)
    links = jsonschema.MethodField(schema_type=LinkSchema(many=True),
                                   display_none=True)
    data_freshness = EnumField(attr="realtime_level", display_none=True)
    occupancy = jsonschema.MethodField(schema_type=str, display_none=False)

    def get_occupancy(self, obj):
        return obj.occupancy if obj.HasField('occupancy') else None

    def get_links(self, obj):
        disruption_links = [
            create_internal_link(_type="disruption", rel="disruptions", id=uri)
            for uri in obj.impact_uris
        ]
        properties_links = pt.make_properties_links(obj.properties)
        return properties_links + disruption_links

    def get_date_time(self, obj):
        __date_time_null_value__ = 2**64 - 1
        if obj.time == __date_time_null_value__:
            return ""
        if obj.HasField('date'):
            return timestamp_to_str(obj.date + obj.time)
        return datetime.utcfromtimestamp(obj.time).strftime('%H%M%S')
Beispiel #2
0
class PlaceSerializer(GenericSerializer):
    id = serpy.Field(attr='uri')
    name = serpy.Field()
    quality = serpy.Field(required=False)
    stop_area = StopAreaSerializer(display_none=False)
    stop_point = StopPointSerializer(display_none=False)
    administrative_region = AdminSerializer(display_none=False)
    embedded_type = EnumField(attr='embedded_type')
Beispiel #3
0
class RouteScheduleSerializer(PbNestedSerializer):
    table = TableSerializer()
    display_informations = pt.RouteDisplayInformationSerializer(attr='pt_display_informations')
    geojson = MultiLineStringField(display_none=False)
    additional_informations = EnumField(attr="response_status", display_none=True)
    links = jsonschema.MethodField(schema_type=LinkSchema(many=True))

    def get_links(self, obj):
        return _get_links(obj)
Beispiel #4
0
class StopScheduleSerializer(PbNestedSerializer):
    stop_point = pt.StopPointSerializer()
    route = pt.RouteSerializer()
    additional_informations = EnumField(attr="response_status", display_none=True)
    display_informations = pt.RouteDisplayInformationSerializer(attr='pt_display_informations')
    date_times = DateTimeTypeSerializer(many=True, display_none=True)
    links = jsonschema.MethodField(schema_type=LinkSchema(many=True))

    def get_links(self, obj):
        return _get_links(obj)
Beispiel #5
0
class SectionSerializer(PbNestedSerializer):
    id = jsonschema.Field(schema_type=str, display_none=True)
    duration = jsonschema.Field(schema_type=int, display_none=True,
                                description='Duration of the section (seconds)')
    co2_emission = AmountSerializer(display_none=True)
    transfer_type = EnumField()
    departure_date_time = DateTimeField(attr='begin_date_time',
                                        description='Departure date and time of the section')
    arrival_date_time = DateTimeField(attr='end_date_time',
                                      description='Arrival date and time of the section')
    base_departure_date_time = DateTimeField(attr='base_begin_date_time',
                                             description='Base-schedule departure date and time of the section')
    base_arrival_date_time = DateTimeField(attr='base_end_date_time',
                                           description='Base-schedule arrival date and time of the section')
    to = jsonschema.MethodField(schema_type=PlaceSerializer(), attr='destination')

    def get_to(self, obj):
        if obj.HasField(str('type')):
            enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number
            ret_value = enum[getattr(obj, 'type')].name
            if ret_value == 'WAITING':
                return None
        return PlaceSerializer(obj.destination).data

    _from = jsonschema.MethodField(schema_type=PlaceSerializer(), attr='origin', label='from')
    def get__from(self, obj):
        if obj.HasField(str('type')):
            enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number
            ret_value = enum[getattr(obj, 'type')].name
            if ret_value == 'WAITING':
                return None
        return PlaceSerializer(obj.origin).data

    additional_informations = EnumListField(attr='additional_informations', pb_type=SectionAdditionalInformationType)
    geojson = SectionGeoJsonField(display_none=False, description='GeoJSON of the shape of the section')
    mode = NestedEnumField(attr='street_network.mode')
    type = SectionTypeEnum()

    display_informations = VJDisplayInformationSerializer(attr='pt_display_informations', display_none=False)

    links = jsonschema.MethodField(display_none=True, schema_type=LinkSchema(many=True))
    def get_links(self, obj):
        response = []
        if obj.HasField(str("uris")):
            for type_, value in obj.uris.ListFields():
                response.append({"type": type_.name, "id": value})
        if obj.HasField(str('pt_display_informations')):
            response.extend(base.make_notes(obj.pt_display_informations.notes))
        return response

    stop_date_times = StopDateTimeSerializer(many=True)
    path = PathSerializer(attr="street_network.path_items", many=True, display_none=False)
Beispiel #6
0
class DateTimeTypeSerializer(PbNestedSerializer):
    date_time = jsonschema.MethodField(schema_type=TimeOrDateTimeType, display_none=True)
    base_date_time = DateTimeField()
    additional_informations = pt.AdditionalInformation(attr='additional_informations', display_none=True)
    links = pt.PropertiesLinksSerializer(attr="properties")
    data_freshness = EnumField(attr="realtime_level", display_none=True)

    def get_date_time(self, obj):
        __date_time_null_value__ = 2**64 - 1
        if obj.time == __date_time_null_value__:
            return ""
        if obj.HasField('date'):
            return timestamp_to_str(obj.date + obj.time)
        return datetime.utcfromtimestamp(obj.time).strftime('%H%M%S')
Beispiel #7
0
class ImpactedStopSerializer(PbNestedSerializer):
    stop_point = serpy.MethodField(display_none=False)
    base_arrival_time = LocalTimeField(attr='base_stop_time.arrival_time')
    base_departure_time = LocalTimeField(attr='base_stop_time.departure_time')
    amended_arrival_time = LocalTimeField(
        attr='amended_stop_time.arrival_time')
    amended_departure_time = LocalTimeField(
        attr='amended_stop_time.departure_time')
    cause = serpy.Field()
    stop_time_effect = EnumField(attr='effect')

    def get_stop_point(self, obj):
        if obj.HasField(str('stop_point')):
            return StopPointSerializer(obj.stop_point, display_none=False).data
        else:
            return None
Beispiel #8
0
class DisruptionSerializer(PbNestedSerializer):
    id = serpy.Field(attr='uri')
    disruption_id = serpy.Field(attr='disruption_uri')
    impact_id = serpy.Field(attr='uri')
    title = serpy.Field(),
    application_periods = PeriodSerializer(many=True)
    status = EnumField(attr='status')
    updated_at = DateTimeField()
    tags = serpy.Serializer(many=True, display_none=False)
    cause = serpy.Field()
    severity = SeveritySerializer()
    messages = MessageSerializer(many=True)
    impacted_objects = ImpactedSerializer(many=True, display_none=False)
    uri = serpy.Field(attr='uri')
    disruption_uri = serpy.Field()
    contributor = serpy.Field()
Beispiel #9
0
class PtObjectSerializer(GenericSerializer):
    quality = serpy.Field(required=False)
    stop_area = serpy.MethodField(display_none=False)
    line = serpy.MethodField(display_none=False)
    network = serpy.MethodField(display_none=False)
    route = serpy.MethodField(display_none=False)
    commercial_mode = serpy.MethodField(display_none=False)
    trip = serpy.MethodField(display_none=False)
    embedded_type = EnumField(attr='embedded_type')

    def get_trip(self, obj):
        if obj.HasField(str('trip')):
            return TripSerializer(obj.trip, display_none=False).data
        else:
            return None

    def get_commercial_mode(self, obj):
        if obj.HasField(str('commercial_mode')):
            return CommercialModeSerializer(obj.commercial_mode,
                                            display_none=False).data
        else:
            return None

    def get_route(self, obj):
        if obj.HasField(str('route')):
            return RouteSerializer(obj.route, display_none=False).data
        else:
            return None

    def get_network(self, obj):
        if obj.HasField(str('network')):
            return NetworkSerializer(obj.network, display_none=False).data
        else:
            return None

    def get_line(self, obj):
        if obj.HasField(str('line')):
            return LineSerializer(obj.line, display_none=False).data
        else:
            return None

    def get_stop_area(self, obj):
        if obj.HasField(str('stop_area')):
            return StopAreaSerializer(obj.stop_area, display_none=False).data
        else:
            return None
Beispiel #10
0
class ErrorSerializer(PbNestedSerializer):
    id = EnumField(attr='id', display_none=True)
    message = StrField()
Beispiel #11
0
class IndividualInformationSerializer(PbNestedSerializer):
    alias = jsonschema.Field(schema_type=str, display_none=True)
    image = jsonschema.Field(schema_type=str, display_none=False)
    gender = EnumField(attr='gender', pb_type=GenderType)
    rating = IndividualRatingSerializer(display_none=False)
Beispiel #12
0
class ErrorSerializer(PbNestedSerializer):
    id = EnumField(attr='id')
    message = serpy.Field()
Beispiel #13
0
class SectionSerializer(PbNestedSerializer):
    id = jsonschema.Field(schema_type=str, display_none=True)
    duration = jsonschema.Field(
        schema_type=int, display_none=True, description='Duration of the section (seconds)'
    )
    co2_emission = AmountSerializer(display_none=True)
    transfer_type = EnumField(attr='transfer_type', pb_type=TransferType)
    departure_date_time = DateTimeField(
        attr='begin_date_time', description='Departure date and time of the section'
    )
    arrival_date_time = DateTimeField(attr='end_date_time', description='Arrival date and time of the section')
    base_departure_date_time = DateTimeField(
        attr='base_begin_date_time', description='Base-schedule departure date and time of the section'
    )
    base_arrival_date_time = DateTimeField(
        attr='base_end_date_time', description='Base-schedule arrival date and time of the section'
    )
    data_freshness = EnumField(attr="realtime_level", pb_type=RTLevel, display_none=False)
    to = jsonschema.MethodField(schema_type=PlaceSerializer(), attr='destination')

    def get_to(self, obj):
        if obj.HasField(str('type')):
            enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number
            ret_value = enum[getattr(obj, 'type')].name
            if ret_value == 'WAITING':
                return None
        return PlaceSerializer(obj.destination).data

    _from = jsonschema.MethodField(schema_type=PlaceSerializer(), attr='origin', label='from')

    def get__from(self, obj):
        if obj.HasField(str('type')):
            enum = obj.DESCRIPTOR.fields_by_name['type'].enum_type.values_by_number
            ret_value = enum[getattr(obj, 'type')].name
            if ret_value == 'WAITING':
                return None
        return PlaceSerializer(obj.origin).data

    additional_informations = EnumListField(
        attr='additional_informations', pb_type=SectionAdditionalInformationType
    )
    geojson = SectionGeoJsonField(display_none=False, description='GeoJSON of the shape of the section')
    mode = NestedEnumField(attr='street_network.mode', pb_type=StreetNetworkMode)
    type = SectionTypeEnum(attr='type', pb_type=SectionType)

    display_informations = VJDisplayInformationSerializer(attr='pt_display_informations', display_none=False)

    links = jsonschema.MethodField(display_none=True, schema_type=LinkSchema(many=True))

    def get_links(self, obj):
        response = []
        if obj.HasField(str("uris")):
            for type_, value in obj.uris.ListFields():
                response.append({"type": type_.name, "id": value})
        if obj.HasField(str('pt_display_informations')):
            response.extend(base.make_notes(obj.pt_display_informations.notes))
        if obj.HasField(str('ridesharing_information')):
            response.extend(
                [
                    {"type": "ridesharing_ad", "rel": l.key, "href": l.href, "internal": False}
                    for l in obj.ridesharing_information.links
                ]
            )

        return response

    stop_date_times = StopDateTimeSerializer(many=True)
    path = PathSerializer(attr="street_network.path_items", many=True, display_none=False)
    ridesharing_informations = RidesharingInformationSerializer(
        attr='ridesharing_information', display_none=False
    )
    ridesharing_journeys = jsonschema.MethodField(
        schema_type=lambda: JourneySerializer(display_none=False, many=True)
    )

    def get_ridesharing_journeys(self, obj):
        if not hasattr(obj, 'ridesharing_journeys') or not obj.ridesharing_journeys:
            return None
        return JourneySerializer(obj.ridesharing_journeys, display_none=False, many=True).data

    cycle_lane_length = PbIntField(display_none=False)
    elevations = ElevationSerializer(attr="street_network.elevations", many=True, display_none=False)
    dynamic_speeds = DynamicSpeedSerializer(attr="street_network.dynamic_speeds", many=True, display_none=False)
    vias = PathWaySerializer(many=True, display_none=False)
    street_informations = StreetInformationSerializer(
        attr="street_network.street_information", many=True, display_none=False
    )