Example #1
0
    def post(self, name=None):
        a = _get_input(["name", "unit"])
        _ensure_service_env(a.get("name"))
        unit = retrieve_dbo(Unit, a.get("unit"))
        sensor = retrieve_dbo(Sensor, a.get("name"), create=unit)
        sensor.unit = unit
        description, factor = a.get("description"), a.get("factor")
        if description:
            sensor.description = description
        if factor is not None:
            sensor.factor = factor
        db.session.add(sensor)
        db.session.commit()

        return a
Example #2
0
    def post(self, sensorname=None):
        a = _get_input(["value", "sensor"])
        _ensure_service_env(a.get("sensor"))
        data = Data(a.get("value"), retrieve_dbo(Sensor, a.get("sensor")))
        db.session.add(data)
        db.session.commit()

        return a
Example #3
0
 def get(self, sensorname=None):
     if sensorname:
         _ensure_service_env(sensorname)
         return [
             data.api_repr(as_num=True if sensorname != the_shouts else False)
             for data in retrieve_dbo(Sensor, sensorname).get_data().all()
         ]
     abort(400, error="please specify a sensor")
Example #4
0
    def post(self, name=None):
        a = _get_input(["name", "sensors"])
        collection = None
        if a.get("name") != the_non_collection:
            collection = retrieve_dbo(Collection, a.get("name"), create=True)
            description = a.get("description")
            if description:
                collection.description = description

        for s in a.get("sensors", []):
            sensor = retrieve_dbo(Sensor, s)
            if a.get("name") == the_non_collection:
                sensor.collection_id = None
            sensor.collection = collection
            db.session.add(sensor)
        db.session.commit()

        return a
Example #5
0
    def post(self, name=None):
        a = _get_input(["name"], opt=["axis", "description"])
        unit = retrieve_dbo(Unit, a.get("name"), create=True)
        axis, description = a.get("axis"), a.get("description")
        if axis is not None:
            unit.axis = axis
        if description:
            unit.description = description
        db.session.add(unit)
        db.session.commit()

        return a
Example #6
0
    def get(self, name=None):
        non_collection = None
        non_sensors = Sensor.query.filter(Sensor.collection == non_collection)
        if name:
            if name != the_non_collection:
                return retrieve_dbo(Collection, name).api_repr()
            return {
                "description": "The Non-Collection",
                "name": the_non_collection,
                "sensors": [s.name for s in non_sensors.all()],
            }

        res = [c.name for c in Collection.query.all()]
        return sorted(res + [the_non_collection] if non_sensors.count() else res)
Example #7
0
    def get(self, collectionname=None):
        def _chk_sens(s):
            return all([s.unit, s.unit.axis in the_axis.keys(), s.get_data().first()])

        non_collection = None
        if collectionname:
            collection = (
                non_collection if collectionname == the_non_collection else retrieve_dbo(Collection, collectionname)
            )
            return [
                sensor.flot_repr()
                for sensor in Sensor.query.filter(Sensor.collection == collection).order_by(Sensor.name.asc()).all()
                if _chk_sens(sensor)
            ]
        return sorted(
            set(
                [
                    sensor.collection.name if sensor.collection != non_collection else the_non_collection
                    for sensor in Sensor.query.all()
                    if _chk_sens(sensor)
                ]
            )
        )
Example #8
0
 def get(self, name=None):
     if name:
         return retrieve_dbo(Unit, name).api_repr()
     return [u.name for u in Unit.query.all()]
Example #9
0
 def get(self, name=None):
     if name:
         _ensure_service_env(name)
         return retrieve_dbo(Sensor, name).api_repr(as_num=True if name != the_shouts else False)
     return [s.name for s in Sensor.query.all()]