Exemple #1
0
        def __init__(self):
            Uri.__init__(self, is_collection, "lines")
            self.collections = [
                ("lines", NonNullList(fields.Nested(line,
                                                    display_null=False))),
                ("pagination", PbField(pagination)), ("error", PbField(error)),
                ("disruptions",
                 fields.List(NonNullNested(disruption_marshaller),
                             attribute="impacts")),
                ("feed_publishers",
                 NonNullList(fields.Nested(feed_publisher,
                                           display_null=False)))
            ]
            if current_app.config.get('USE_SERPY', False):
                collections = serialize_with(api.LinesSerializer)
            else:
                collections = marshal_with(OrderedDict(self.collections),
                                           display_null=False)
            self.method_decorators.insert(1, collections)

            self.parsers["get"].add_argument(
                "original_id",
                type=unicode,
                description="original uri of the object you"
                "want to query")
Exemple #2
0
 def __init__(self):
     Uri.__init__(self,
                  is_collection,
                  "pois",
                  output_type_serializer=api.PoisSerializer)
     self.collections = [
         ("pois", NonNullList(fields.Nested(poi, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     self.get_decorators.insert(1, get_obj_serializer(self))
     self.parsers["get"].add_argument(
         "original_id",
         type=six.text_type,
         help="original uri of the object you want to query")
     self.parsers["get"].add_argument(
         "bss_stands",
         type=BooleanType(),
         default=True,
         help="Show bss stands availability")
     args = self.parsers["get"].parse_args()
     if args["bss_stands"]:
         self.get_decorators.insert(2, ManageStands(self, 'pois'))
Exemple #3
0
 def __init__(self):
     Uri.__init__(self, is_collection, "pois")
     self.collections = [
         ("pois", NonNullList(fields.Nested(poi, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
     self.parsers["get"].add_argument(
         "original_id",
         type=unicode,
         description="original uri of the object you"
         "want to query")
     self.parsers["get"].add_argument(
         "bss_stands",
         type=boolean,
         default=True,
         description="Show bss stands availability")
     args = self.parsers["get"].parse_args()
     if args["bss_stands"]:
         self.method_decorators.insert(2, ManageStands(self, 'pois'))
Exemple #4
0
 def __init__(self):
     Uri.__init__(self, is_collection, "datasets")
     self.collections = [
         ("datasets",
          NonNullList(fields.Nested(dataset, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
Exemple #5
0
 def __init__(self):
     Uri.__init__(self,
                  is_collection,
                  "datasets",
                  output_type_serializer=api.DatasetsSerializer)
     self.collections = [
         ("datasets",
          NonNullList(fields.Nested(dataset, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     self.get_decorators.insert(1, get_obj_serializer(self))
Exemple #6
0
 def __init__(self):
     Uri.__init__(self, is_collection, "physical_modes")
     self.collections = [
         ("physical_modes",
          NonNullList(fields.Nested(physical_mode,
                                    display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     if current_app.config.get('USE_SERPY', False):
         collections = serialize_with(api.PhysicalModesSerializer)
     else:
         collections = marshal_with(OrderedDict(self.collections),
                                    display_null=False)
     self.method_decorators.insert(1, collections)
Exemple #7
0
 def __init__(self):
     Uri.__init__(self, is_collection, "networks")
     self.collections = [
         ("networks",
          NonNullList(fields.Nested(network, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     collections = marshal_with(OrderedDict(self.collections),
                                display_null=False)
     self.method_decorators.insert(1, collections)
     self.parsers["get"].add_argument(
         "original_id",
         type=unicode,
         description="original uri of the object you"
         "want to query")
Exemple #8
0
 def __init__(self):
     Uri.__init__(self,
                  is_collection,
                  "networks",
                  output_type_serializer=api.NetworksSerializer)
     self.collections = [
         ("networks",
          NonNullList(fields.Nested(network, display_null=False))),
         ("pagination", PbField(pagination)), ("error", PbField(error)),
         ("disruptions",
          fields.List(NonNullNested(disruption_marshaller),
                      attribute="impacts")),
         ("feed_publishers",
          NonNullList(fields.Nested(feed_publisher,
                                    display_null=False)))
     ]
     self.get_decorators.insert(1, get_obj_serializer(self))
     self.parsers["get"].add_argument(
         "original_id",
         type=six.text_type,
         help="original uri of the object you want to query")
Exemple #9
0
        def __init__(self):
            Uri.__init__(self,
                         is_collection,
                         "pois",
                         output_type_serializer=api.PoisSerializer)
            self.collections = [
                ("pois", NonNullList(fields.Nested(poi, display_null=False))),
                ("pagination", PbField(pagination)), ("error", PbField(error)),
                ("disruptions",
                 fields.List(NonNullNested(disruption_marshaller),
                             attribute="impacts")),
                ("feed_publishers",
                 NonNullList(fields.Nested(feed_publisher,
                                           display_null=False)))
            ]
            self.get_decorators.insert(1, get_obj_serializer(self))
            self.parsers["get"].add_argument(
                "original_id",
                type=six.text_type,
                help="original uri of the object you want to query")
            self.parsers["get"].add_argument(
                "bss_stands",
                type=BooleanType(),
                default=True,
                help="Show bss stands availability")
            self.parsers["get"].add_argument(
                "add_poi_infos[]",
                type=OptionValue(add_poi_infos_types),
                default=['bss_stands', 'car_park'],
                dest="add_poi_infos",
                action="append",
                help=
                "Show more information about the poi if it's available, for instance,"
                " show BSS/car park availability in the pois(BSS/car park) of "
                "response")

            args = self.parsers["get"].parse_args()
            if args["add_poi_infos"] or args["bss_stands"]:
                self.get_decorators.insert(2,
                                           ManageParkingPlaces(self, 'pois'))
Exemple #10
0
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Stay tuned using
# twitter @navitia
# IRC #navitia on freenode
# https://groups.google.com/d/forum/navitia
# www.navitia.io

from jormungandr.interfaces.v1.Calendars import calendar
from jormungandr.interfaces.v1 import fields
from jormungandr.interfaces.v1.fields import NonNullList, NonNullNested, NonNullProtobufNested, PbField, FirstComment, \
    comment

vehicle_journey = {
    "id": fields.fields.String(attribute="uri"),
    "name": fields.fields.String(),
    "disruptions": NonNullList(NonNullNested(fields.disruption_marshaller)),
    "journey_pattern": PbField(fields.journey_pattern),
    "stop_times": NonNullList(NonNullNested(fields.stop_time)),
    "comment": FirstComment(),
    # for compatibility issue we keep a 'comment' field where we output the first comment (TODO v2)
    "comments": NonNullList(NonNullNested(comment)),
    "codes": NonNullList(NonNullNested(fields.code)),
    "validity_pattern": NonNullProtobufNested(fields.validity_pattern),
    "calendars": NonNullList(NonNullNested(calendar)),
}
Exemple #11
0
from jormungandr.interfaces.parsers import depth_argument, default_count_arg_type, DateTimeFormat
from copy import deepcopy
from jormungandr.interfaces.v1.transform_id import transform_id
from jormungandr.exceptions import TechnicalError, InvalidArguments
from datetime import datetime
from jormungandr.parking_space_availability.parking_places_manager import ManageParkingPlaces
import ujson as json
from jormungandr.scenarios.utils import places_type
from navitiacommon.parser_args_type import TypeSchema, CoordFormat, CustomSchemaType, BooleanType, \
    OptionValue
from jormungandr.interfaces.common import add_poi_infos_types, handle_poi_infos
import six


places = {
    "places": NonNullList(NonNullNested(place)),
    "error": PbField(error, attribute='error'),
    "disruptions": fields.List(NonNullNested(disruption_marshaller), attribute="impacts"),
    "feed_publishers": fields.List(NonNullNested(feed_publisher))
}


class geojson_argument(CustomSchemaType):
    def __call__(self, value):
        decoded = json.loads(value)
        if not decoded:
            raise ValueError('invalid shape')

        return parser_args_type.geojson_argument(decoded)

    def schema(self):
Exemple #12
0
    "wednesday": fields.Boolean(),
    "thursday": fields.Boolean(),
    "friday": fields.Boolean(),
    "saturday": fields.Boolean(),
    "sunday": fields.Boolean(),
}

calendar_period = {"begin": fields.String(), "end": fields.String()}

calendar_exception = {"datetime": fields.String(attribute="date"), "type": enum_type()}
validity_pattern = {'beginning_date': fields.String(), 'days': fields.String()}
calendar = {
    "id": NonNullString(attribute="uri"),
    "name": NonNullString(),
    "week_pattern": NonNullNested(week_pattern),
    "active_periods": NonNullList(NonNullNested(calendar_period)),
    "exceptions": NonNullList(NonNullNested(calendar_exception)),
    "validity_pattern": NonNullProtobufNested(validity_pattern),
}

calendars = {
    "calendars": NonNullList(NonNullNested(calendar)),
    "error": PbField(error, attribute='error'),
    "pagination": NonNullNested(pagination),
    "disruptions": fields.List(NonNullNested(disruption_marshaller), attribute="impacts"),
    "feed_publishers": fields.List(NonNullNested(feed_publisher)),
}


class Calendars(ResourceUri):
    def __init__(self):
Exemple #13
0
from jormungandr import i_manager, timezone
from jormungandr.interfaces.v1.fields import PbField, error, network, line,\
    NonNullList, NonNullNested, pagination, stop_area
from jormungandr.interfaces.v1.VehicleJourney import vehicle_journey
from jormungandr.interfaces.v1.ResourceUri import ResourceUri
from jormungandr.interfaces.argument import ArgumentDoc
from jormungandr.interfaces.parsers import date_time_format, default_count_arg_type
from jormungandr.interfaces.v1.errors import ManageError
from datetime import datetime
import aniso8601
from datetime import timedelta
from jormungandr.interfaces.v1.fields import disruption_marshaller

disruption = {
    "network": PbField(network, attribute='network'),
    "lines": NonNullList(NonNullNested(line)),
    "stop_areas": NonNullList(NonNullNested(stop_area)),
    "vehicle_journeys": NonNullList(NonNullNested(vehicle_journey))
}

traffic = {
    "traffic_reports":
    NonNullList(NonNullNested(disruption)),
    "error":
    PbField(error, attribute='error'),
    "pagination":
    NonNullNested(pagination),
    "disruptions":
    fields.List(NonNullNested(disruption_marshaller), attribute="impacts"),
}
Exemple #14
0
    "date_time": SplitDateTime(date='date', time='time'),
    "additional_informations": additional_informations(),
    "links": stop_time_properties_links(),
    'data_freshness': enum_type(attribute='realtime_level'),
}

row = {
    "stop_point": PbField(stop_point),
    "date_times": fields.List(fields.Nested(date_time))
}

header = {
    "display_informations":
    PbField(display_informations_vj, attribute='pt_display_informations'),
    "additional_informations":
    NonNullList(PbEnum(response_pb2.SectionAdditionalInformationType)),
    "links":
    UrisToLinks()
}
table_field = {
    "rows": fields.List(fields.Nested(row)),
    "headers": fields.List(fields.Nested(header))
}

route_schedule_fields = {
    "table":
    PbField(table_field),
    "display_informations":
    PbField(display_informations_route, attribute='pt_display_informations'),
    "links":
    UrisToLinks(),
Exemple #15
0
from jormungandr.interfaces.v1.decorators import get_serializer

graphical_isochrone = {
    "geojson": JsonString(),
    "max_duration": fields.Integer(),
    "min_duration": fields.Integer(),
    'from': PbField(place, attribute='origin'),
    "to": PbField(place, attribute="destination"),
    'requested_date_time': DateTime(),
    'min_date_time': DateTime(),
    'max_date_time': DateTime()
}


graphical_isochrones = {
    "isochrones": NonNullList(NonNullNested(graphical_isochrone), attribute="graphical_isochrones"),
    "error": PbField(error, attribute='error'),
    "feed_publishers": fields.List(NonNullNested(feed_publisher)),
    "links": fields.List(Links()),
    "warnings": ListLit([fields.Nested(beta_endpoint)]),
    'context': context
}


class GraphicalIsochrone(JourneyCommon):

    def __init__(self):
        super(GraphicalIsochrone, self).__init__(output_type_serializer=GraphicalIsrochoneSerializer)
        parser_get = self.parsers["get"]
        parser_get.add_argument("min_duration", type=UnsignedInteger(), default=0)
        parser_get.add_argument("boundary_duration[]", type=UnsignedInteger(), action="append")
from jormungandr.interfaces.parsers import DateTimeFormat, default_count_arg_type
from jormungandr.interfaces.v1.decorators import get_obj_serializer
from jormungandr.interfaces.v1.errors import ManageError
from jormungandr.interfaces.v1.fields import PbField, line, pt_object, NonNullList, NonNullNested,\
    pagination, disruption_marshaller, error, ListLit, beta_endpoint
from jormungandr.interfaces.v1.ResourceUri import ResourceUri
from jormungandr.interfaces.v1.serializer import api

from flask.ext.restful import fields, reqparse
from flask.globals import g
from datetime import datetime
import six

line_report = {
    "line": PbField(line),
    "pt_objects": NonNullList(NonNullNested(pt_object)),
}

line_reports = {
    "line_reports":
    NonNullList(NonNullNested(line_report)),
    "error":
    PbField(error, attribute='error'),
    "pagination":
    NonNullNested(pagination),
    "disruptions":
    fields.List(NonNullNested(disruption_marshaller), attribute="impacts"),
    "warnings":
    ListLit([fields.Nested(beta_endpoint)]),
}
Exemple #17
0
from jormungandr.interfaces.parsers import depth_argument, default_count_arg_type, DateTimeFormat
from copy import deepcopy
from jormungandr.interfaces.v1.transform_id import transform_id
from jormungandr.exceptions import TechnicalError, InvalidArguments
from datetime import datetime
from jormungandr.parking_space_availability.parking_places_manager import ManageParkingPlaces
import ujson as json
from jormungandr.scenarios.utils import places_type
from navitiacommon.parser_args_type import TypeSchema, CoordFormat, CustomSchemaType, BooleanType, \
    OptionValue
from jormungandr.interfaces.common import add_poi_infos_types
import six

places = {
    "places":
    NonNullList(NonNullNested(place)),
    "error":
    PbField(error, attribute='error'),
    "disruptions":
    fields.List(NonNullNested(disruption_marshaller), attribute="impacts"),
    "feed_publishers":
    fields.List(NonNullNested(feed_publisher))
}


class geojson_argument(CustomSchemaType):
    def __call__(self, value):
        decoded = json.loads(value)
        if not decoded:
            raise ValueError('invalid shape')
Exemple #18
0
from flask.ext.restful import Resource, fields, marshal_with, reqparse, abort
from flask.ext.restful.inputs import boolean
from flask.globals import g
from jormungandr import i_manager, timezone
from jormungandr.interfaces.v1.fields import disruption_marshaller
from jormungandr.interfaces.v1.make_links import add_id_links
from jormungandr.interfaces.v1.fields import NonNullList, NonNullNested, PbField, error, pt_object, feed_publisher
from jormungandr.interfaces.v1.ResourceUri import ResourceUri
from jormungandr.interfaces.argument import ArgumentDoc
from jormungandr.interfaces.parsers import depth_argument, option_value, default_count_arg_type, date_time_format
from copy import deepcopy
import datetime

pt_objects = {
    "pt_objects":
    NonNullList(NonNullNested(pt_object), attribute='places'),
    "disruptions":
    fields.List(NonNullNested(disruption_marshaller), attribute="impacts"),
    "error":
    PbField(error, attribute='error'),
    "feed_publishers":
    fields.List(NonNullNested(feed_publisher))
}

pt_object_type_values = [
    "network", "commercial_mode", "line", "line_group", "route", "stop_area"
]


class Ptobjects(ResourceUri):
    def __init__(self, *args, **kwargs):
Exemple #19
0
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Stay tuned using
# twitter @navitia
# IRC #navitia on freenode
# https://groups.google.com/d/forum/navitia
# www.navitia.io

from jormungandr.interfaces.v1.Calendars import calendar
from jormungandr.interfaces.v1 import fields
from jormungandr.interfaces.v1.fields import NonNullList, NonNullNested, NonNullProtobufNested, PbField, FirstComment, \
    comment, DisruptionLinks

vehicle_journey = {
    "id": fields.fields.String(attribute="uri"),
    "name": fields.fields.String(),
    "disruptions": DisruptionLinks(),
    "journey_pattern": PbField(fields.journey_pattern),
    "stop_times": NonNullList(NonNullNested(fields.stop_time)),
    "comment": FirstComment(),
    # for compatibility issue we keep a 'comment' field where we output the first comment (TODO v2)
    "comments": NonNullList(NonNullNested(comment)),
    "codes": NonNullList(NonNullNested(fields.code)),
    "validity_pattern": NonNullProtobufNested(fields.validity_pattern),
    "calendars": NonNullList(NonNullNested(calendar)),
    "trip": NonNullProtobufNested(fields.trip),
}
Exemple #20
0
from jormungandr.interfaces.parsers import UnsignedInteger
from jormungandr.interfaces.v1.journey_common import JourneyCommon
from jormungandr.interfaces.v1.fields import DateTime, context
from jormungandr.interfaces.v1.serializer.api import HeatMapSerializer
from jormungandr.interfaces.v1.decorators import get_serializer

heat_map = {
    "heat_matrix": JsonString(),
    'from': PbField(place, attribute='origin'),
    "to": PbField(place, attribute="destination"),
    'requested_date_time': DateTime()
}


heat_maps = {
    "heat_maps": NonNullList(NonNullNested(heat_map)),
    "error": PbField(error, attribute='error'),
    "links": fields.List(Links()),
    "warnings": ListLit([fields.Nested(beta_endpoint)]),
    "feed_publishers": fields.List(NonNullNested(feed_publisher)),
    "context": context
}


class HeatMap(JourneyCommon):

    def __init__(self):
        super(HeatMap, self).__init__(output_type_serializer=HeatMapSerializer)
        parser_get = self.parsers["get"]
        parser_get.add_argument("resolution", type=UnsignedInteger(), default=500)
Exemple #21
0
# IRC #navitia on freenode
# https://groups.google.com/d/forum/navitia
# www.navitia.io
from __future__ import absolute_import, print_function, unicode_literals, division
from jormungandr.autocomplete.abstract_autocomplete import AbstractAutocomplete, GeoStatusResponse
from jormungandr.scenarios.utils import build_pagination, pb_type
from jormungandr.interfaces.v1.fields import NonNullList, place, NonNullNested, PbField, error, feed_publisher,\
    disruption_marshaller
from flask.ext.restful import marshal_with, fields, abort
import navitiacommon.request_pb2 as request_pb2
import navitiacommon.type_pb2 as type_pb2
from jormungandr.utils import date_to_timestamp

places = {
    "places":
    NonNullList(NonNullNested(place)),
    "error":
    PbField(error, attribute='error'),
    "disruptions":
    fields.List(NonNullNested(disruption_marshaller), attribute="impacts"),
    "feed_publishers":
    fields.List(NonNullNested(feed_publisher))
}


class Kraken(AbstractAutocomplete):
    @marshal_with(places)
    def get(self, request, instance):

        req = request_pb2.Request()
        req.requested_api = type_pb2.places
Exemple #22
0
 "id":
 fields.String(),
 "mode":
 enum_type(attribute="street_network.mode"),
 "duration":
 fields.Integer(),
 "from":
 section_place(place, attribute="origin"),
 "to":
 section_place(place, attribute="destination"),
 "links":
 SectionLinks(attribute="uris"),
 "display_informations":
 PbField(display_informations_vj, attribute='pt_display_informations'),
 "additional_informations":
 NonNullList(PbEnum(response_pb2.SectionAdditionalInformationType)),
 "geojson":
 SectionGeoJson(),
 "path":
 NonNullList(NonNullNested({
     "length": fields.Integer(),
     "name": fields.String(),
     "duration": fields.Integer(),
     "direction": fields.Integer()
 }),
             attribute="street_network.path_items"),
 "transfer_type":
 enum_type(),
 "stop_date_times":
 NonNullList(NonNullNested(stop_date_time)),
 "departure_date_time":