Ejemplo n.º 1
0
class GraphicalIsrochoneSerializer(serpy.Serializer):

    geojson = JsonStrField(
        schema_metadata={
            'type': 'object',
            'properties': {
                'type': {
                    # Must be MultiPolygon
                    'enum': ['MultiPolygon']
                },
                'coordinates': {
                    'type': 'array',
                    'items': {
                        'type': 'array',
                        'items': point_2D_schema
                    }
                },
            },
        })
    max_duration = Field(schema_type=int)
    min_duration = Field(schema_type=int)
    origin = PlaceSerializer(label='from')
    to = PlaceSerializer(attr='destination', label='to')
    requested_date_time = DateTimeField()
    min_date_time = DateTimeField()
    max_date_time = DateTimeField()
Ejemplo n.º 2
0
class JourneySerializer(PbNestedSerializer):
    duration = jsonschema.Field(schema_type=int, display_none=True,
                                description='Duration of the journey (seconds)')
    nb_transfers = jsonschema.Field(schema_type=int, display_none=True,
                                    description='Number of transfers along the journey')
    departure_date_time = DateTimeField(description='Departure date and time of the journey')
    arrival_date_time = DateTimeField(description='Arrival date and time of the journey')
    requested_date_time = DateTimeField(deprecated=True)
    to = PlaceSerializer(deprecated=True, attr='destination')
    _from = PlaceSerializer(deprecated=True, attr='origin', label='from')
    type = jsonschema.Field(schema_type=str, display_none=True,
                            description='Used to qualify the journey (can be "best", "comfort", "non_pt_walk", ...')
    status = jsonschema.Field(schema_type=str, attr="most_serious_disruption_effect", display_none=True,
                              description='Status from the whole journey taking into account the most '
                                          'disturbing information retrieved on every object used '
                                          '(can be "NO_SERVICE", "SIGNIFICANT_DELAYS", ...')
    tags = StringListField(display_none=True)
    co2_emission = AmountSerializer(display_none=True)
    durations = DurationsSerializer()
    fare = FareSerializer(display_none=True)
    calendars = CalendarSerializer(many=True, display_none=False)
    sections = SectionSerializer(many=True, display_none=False)
    debug = jsonschema.MethodField(schema_type=JourneyDebugSerializer(), display_none=False)

    def get_debug(self, obj):
        if not hasattr(g, 'debug') or not g.debug:
            return None
        return JourneyDebugSerializer(obj, display_none=False).data
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 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
Ejemplo n.º 5
0
class HeatMapSerializer(serpy.Serializer):
    heat_matrix = JsonStrField(schema_type=HeatMatrixSchema)
    origin = PlaceSerializer(label='from')
    to = PlaceSerializer(attr='destination', label='to')
    requested_date_time = DateTimeField()
Ejemplo n.º 6
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
    )