示例#1
0
    def sensor_types():
        """Return a list of sensor types.

        .. :quickref: Get sensor types

        With no parameters, return all sensor types. Parameters can be used to
        filter sensor types according to one or more attributes.

        **Example request**::

          GET /sensor_types?controlledProperty=temperature HTTP/1.1

        **Example response**:

        .. sourcecode:: http

          HTTP/1.1 200 OK
          Content-Type: application/json

          [
           {
             "brandName": "Acme",
             "category": ["sensor"],
             "code": "c7afa96b-ca9a-5561-b57b-5187ad005d75",
             "controlledProperty": ["temperature"],
             "function": ["sensing"],
             "manufacturerName": "Acme Inc.",
             "modelName": "Acme multisensor DHT11",
             "name": "sensor_type_0",
             "type": "TemperatureSensorDTH11"
           }
          ]

        :query {attribute}: select sensors whose description has the specified
          value(s) for the chosen attribute (top-level JSON key, e.g.,
          brandName=Acme; controlledProperty=humidity,temperature)

        :resheader Content-Type: application/json
        :status 200: no error
        :returns: list of sensor types
        """
        if request.method == "GET":
            res = []
            for code, descr in db.list_sensor_types(request.args):
                descr["code"] = code
                res.append(descr)
            return jsonify(res)
        else:
            data = request.json
            codes = db.load_sensor_types(db.get_db(), data)
            return jsonify(codes)
示例#2
0
    def sensor_types():
        """Return a list of sensor types.

        .. :quickref: Get sensor types

        With no parameters, return all sensor types. Parameters can be used to
        filter sensor types according to one or more attributes.

        **Example request**::

          GET /sensor_types?controlledProperty=temperature HTTP/1.1

        **Example response**:

        .. sourcecode:: http

          HTTP/1.1 200 OK
          Content-Type: application/json

          [
           {
             "uuid": "0fd67c67-c9be-45c6-9719-4c4eada4be65",
             "type": "TemperatureSensorDTH11",
             "name": "temperature sensor in DHT11",
             "brandName": "Acme",
             "modelName": "Acme multisensor DHT11",
             "manufacturerName": "Acme Inc.",
             "category": ["sensor"],
             "function": ["sensing"],
             "controlledProperty": ["temperature"]
           }
          ]

        :query {attribute}: select sensors whose description has the specified
          value(s) for the chosen attribute (top-level JSON key, e.g.,
          name=SensorPro; controlledProperty=humidity,temperature)

        :resheader Content-Type: application/json
        :status 200: no error
        :returns: list of sensor types
        """
        if request.method == "GET":
            res = db.list_sensor_types(request.args)
            return jsonify(res)
        else:
            data = request.json
            db.load_sensor_types(db.get_db(), data)
            return jsonify({"loaded": len(data)})
示例#3
0
    def sensors():
        """Return a list of sensors.

        .. :quickref: Get sensors

        With no parameters, return all sensors. With ``type={uuid}``, select
        sensors of the specified type. When ``footprint``, ``after`` and
        ``before`` are specified, return all sensors that have reported an
        event in the corresponding spatio-temporal region. Sensors can also
        be filtered by generic attributes stored in the description field.

        Note: currently queries by footprint, type or attributes are mutually
         exclusive, i.e. they cannot be combined in a single query.



        **Example request**::

          GET /sensors?footprint=circle((9.22, 30.0), 1000)
                      &after=2019-05-02T11:00:00Z
                      &before=2019-05-02T11:50:25Z HTTP/1.1

        (unencoded URL)

        **Example response**:

        .. sourcecode:: http

          HTTP/1.1 200 OK
          Content-Type: application/json

          [{"code": "0fd67c67-c9be-45c6-9719-4c4eada4becc",
            "geometry": {
              "coordinates": [9.22100000642642, 30.0000000019687],
              "type": "Point"
            },
            "stypecode": "0fd67c67-c9be-45c6-9719-4c4eada4be65"},
           {"code": "0fd67c67-c9be-45c6-9719-4c4eada4beff",
            "geometry": {
              "coordinates": [9.22200000642623, 30.0030000019686],
              "type": "Point"
            },
            "stypecode": "0fd67c67-c9be-45c6-9719-4c4eada4bebe"}]

        :resheader Content-Type: application/json

        :query footprint: consider only sensors within footprint
          e.g., ``circle((9.3, 32), 1000)``

        :query after: consider only sensors reporting  after (included)
          this time, e.g., ``2019-02-21T11:03:25Z``

        :query before: consider only sensors reporting strictly before
          this time, e.g., ``2019-02-22T11:03:25Z``

        :query type: consider only sensors of this type (filter by stypecode)
        :query {attribute}: select sensors whose description has the
            specified value(s) for the chosen attribute
            (top-level JSON key, e.g., name=SensorName)

        :status 200: no error
        :returns: list of sensors
        """
        if request.method == "GET":
            args = {k: v for k, v in request.args.items()}
            if 'footprint' in args:
                args['footprint'] = convert_footprint(args['footprint'])
            res = db.list_sensors(args)
            return jsonify(res)
        else:
            data = request.json
            db.load_sensors(db.get_db(), data)
            return jsonify({"loaded": len(data)})
示例#4
0
 def measures():
     data = request.json
     db.load_measures(db.get_db(), data)
     return jsonify({"loaded": len(data)})
示例#5
0
    def sensors():
        """Return a list of sensors.

        .. :quickref: Get sensors

        With no parameters, return all sensors. When ``footprint``, ``after``
        and ``before`` are specified, return all sensors that have reported an
        event in the corresponding spatio-temporal region. Sensors can also be
        filtered by generic attributes stored in the description field.

        Note: currently queries by footprint or by attributes are mutually
        exclusive, i.e. they cannot be combined in a single query.

        **Example request**::

          GET /sensors?footprint=circle((9.22, 30.0), 1000)
                      &after=2019-05-02T11:00:00Z
                      &before=2019-05-02T11:50:25Z HTTP/1.1

        (unencoded URL)

        **Example response**:

        .. sourcecode:: http

          HTTP/1.1 200 OK
          Content-Type: application/json

          [{"code": "c034f147-8e54-50bd-97bb-9db1addcdc5a",
            "geometry": {"coordinates": [9.221, 30.0], "type": "Point"},
            "name": "sensor_0",
            "node": "node_0",
            "type": "sensor_type_0"},
           {"code": "c932ff51-6eec-5b73-abe1-4163f9e72cb3",
            "geometry": {"coordinates": [9.222, 30.003], "type": "Point"},
            "name": "sensor_1",
            "node": "node_0",
            "type": "sensor_type_1"}]

        :resheader Content-Type: application/json

        :query footprint: consider only sensors within footprint
          e.g., ``circle((9.3, 32), 1000)``

        :query after: consider only sensors reporting  after (included)
          this time, e.g., ``2019-02-21T11:03:25Z``

        :query before: consider only sensors reporting strictly before
          this time, e.g., ``2019-02-22T11:03:25Z``

        :query {attribute}: select sensors whose description has the
            specified value(s) for the chosen attribute
            (top-level JSON key, e.g., type=sensor_type_1)

        :status 200: no error
        :returns: list of sensors
        """
        if request.method == "GET":
            args = {k: v for k, v in request.args.items()}
            if 'footprint' in args:
                args['footprint'] = convert_footprint(args['footprint'])
            res = []
            for code, descr in db.list_sensors(args):
                descr["code"] = code
                res.append(descr)
            return jsonify(res)
        else:
            data = request.json
            codes = db.load_sensors(db.get_db(), data)
            return jsonify(codes)