def team(): ret = [] for user in request.oauth.client.users(): u = user.json() u['times'] = user.get_punchcard(g.INFLUX) ret.append(u) return jsonify(ret)
def get_locations(): locs = [] for loc in Location.find(): j = loc.json() net = loc.get_interface('NetAtmo') j['current'] = net.get_current(g.INFLUX) if net else {} locs.append(j) return jsonify(locs)
def weather(): q = "SELECT value FROM \"lablog\".\"15minute\".\"weather.temp-c\",\"lablog\".\"15minute\".\"weather.relative-humidity\" WHERE time > now() - 2d" res = g.INFLUX.query(q) ret = {} for k, v in res.items(): ret[k[0]] = [] for i in v: ret[k[0]].append(i) return jsonify(ret)
def energy(): q = "SELECT value FROM \"lablog\".\"15minute\".\"energy.smartmeter.power\" WHERE time > now() - 2d" res = g.INFLUX.query(q) ret = {} for k, v in res.items(): ret[k[0]] = [] for i in v: ret[k[0]].append(i) return jsonify(ret)
def ups(): q = "SELECT value FROM \"lablog\".\"15minute\".\"energy.ups.output_power\" WHERE time > now() - 2d GROUP BY \"line\"" res = g.INFLUX.query(q) ret = {} for s in res.raw['series']: n = "line-{}".format(s['tags']['line']) ret[n] = s['values'] logging.info(ret) return jsonify(ret)
def get_node_sensors(node_id): q = "SELECT value FROM \"lablog\".\"15minute\"./node.*/ WHERE time > now() - 2d AND node='{}'".format(node_id) res = g.INFLUX.query(q) ret = {} logging.info(res.raw) for k, v in res.items(): ret[k[0]] = [] for i in v: ret[k[0]].append(i) return jsonify(ret)
def post(self, location): location = Location(id=location) logging.info("Level: {} | X:{}, Y:{} | Beacon: {}".format(request.form.get('level'), request.form.get('x'), request.form.get('y'), request.form.get('beacon_id'))) b = Beacon.find_one({'id':request.form.get('beacon_id')}) if not b: b = Beacon() b.x = request.form.get('x') b.y = request.form.get('y') b.id = request.form.get('beacon_id') b.level = request.form.get('level') b.location = location b.save() return jsonify({'success':True, 'id':str(b._id)})
def get_node_sensors(node_id): q = "SELECT value FROM \"lablog\".\"15minute\"./node.*/ WHERE time > now() - 2d AND node='{}'".format( node_id) res = g.INFLUX.query(q) ret = {} logging.info(res.raw) for k, v in res.items(): ret[k[0]] = [] for i in v: ret[k[0]].append(i) return jsonify(ret)
def post(self, location): location = Location(id=location) logging.info("Level: {} | X:{}, Y:{} | Beacon: {}".format( request.form.get('level'), request.form.get('x'), request.form.get('y'), request.form.get('beacon_id'))) b = Beacon.find_one({'id': request.form.get('beacon_id')}) if not b: b = Beacon() b.x = request.form.get('x') b.y = request.form.get('y') b.id = request.form.get('beacon_id') b.level = request.form.get('level') b.location = location b.save() return jsonify({'success': True, 'id': str(b._id)})
def location_current(location_id): loc = Location(id=location_id) ret = {} for i in loc.interfaces: inter = i._get('interface')._value.get('cls').split(".")[-1] if inter == "NetAtmo": r = i.interface.get_current(g.INFLUX) for k,v in r.iteritems(): if k in ['netatmo.indoor.temperature', 'netatmo.indoor.humidity', 'netatmo.indoor.co2']: ret[k.split(".")[-1]] = v['current'][0]['value'] logging.info(ret) break return jsonify(ret)
def location_beacon(location_id): loc = Location(id=location_id) gb = loc.get_interface('GimbalBeacon') try: data = request.get_json() except: data = {} logging.info("Test: {}".format(data)) logging.info(gb) try: gb.go(g.INFLUX, g.MQ, data=data) gb._last_run = datetime.utcnow() gb.save() except Exception as e: logging.error(e.message) return jsonify({'success':True})
def location_current(location_id): loc = Location(id=location_id) ret = {} for i in loc.interfaces: inter = i._get('interface')._value.get('cls').split(".")[-1] if inter == "NetAtmo": r = i.interface.get_current(g.INFLUX) for k, v in r.iteritems(): if k in [ 'netatmo.indoor.temperature', 'netatmo.indoor.humidity', 'netatmo.indoor.co2' ]: ret[k.split(".")[-1]] = v['current'][0]['value'] logging.info(ret) break return jsonify(ret)
def me(): me = request.oauth.user.json() me['times'] = request.oauth.user.get_punchcard(g.INFLUX) return jsonify(me)
def get_nodes(): res = g.INFLUX.query(query="SHOW SERIES FROM \"node.light\"") nodes = [] for v in res.get_points(): nodes.append(v.get('node')) return jsonify({"nodes": nodes})
def location_data(location_id): loc = Location(id=location_id) data = loc.get_interface_data(g.INFLUX) return jsonify({'location':loc.json(), 'data':data})
def node_sensors(node_id): n = Node.find_one({'id': node_id}) n.go(g.INFLUX, g.MQ, data=request.data) n._last_run = datetime.utcnow() n.save() return jsonify({'success': True})
def get(self, location, level): loc = Location(id=location) beacons = Beacon.find({'location': loc._id, 'level': int(level)}) logging.info(beacons) return jsonify({'beacons': [b.json() for b in beacons]})
def node_sensors(node_id): n = Node.find_one({'id':node_id}) n.go(g.INFLUX, g.MQ, data=request.data) n._last_run = datetime.utcnow() n.save() return jsonify({'success':True})
def get_nodes(): res = g.INFLUX.query(query="SHOW SERIES FROM \"node.light\"") nodes = [] for v in res.get_points(): nodes.append(v.get('node')) return jsonify({"nodes":nodes})
def location_data(location_id): loc = Location(id=location_id) data = loc.get_interface_data(g.INFLUX) return jsonify({'location': loc.json(), 'data': data})
def get(self, location, level): loc = Location(id=location) beacons = Beacon.find({'location':loc._id, 'level':int(level)}) logging.info(beacons) return jsonify({'beacons':[b.json() for b in beacons]})