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 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 ping_node(): for loc in Location.find(): try: n = loc.get_interface('Node') if n.id: logging.info("Pinging Node: {}".format(n.id)) n.publish(MQTT, "6,1") time.sleep(1) n.publish(MQTT, "6,0") time.sleep(1) except Exception as e: logging.error(e)
def run_interfaces(): for loc in Location.find(): try: logging.info("Monitoring Location: {}".format(loc.name)) for i in loc.interfaces: logging.info("Running Interface: {}".format(i.interface.__class__.__name__)) try: i.interface.run(INFLUX, MQ) except Exception as e: logging.error(e) logging.info("Finished Interface: {}".format(i.interface.__class__.__name__)) except Exception as e: logging.error(e) MQ.release()
def run_interfaces(): for loc in Location.find(): try: logging.info("Monitoring Location: {}".format(loc.name)) for i in loc.interfaces: if i.interface._enabled: logging.info("Running Interface: {}".format(i.interface.__class__.__name__)) try: i.interface.run(INFLUX, MQ) except Exception as e: logging.error(e) logging.info("Finished Interface: {}".format(i.interface.__class__.__name__)) except Exception as e: logging.error(e) MQ.release()
def compare_tlc(): diffs = {} for l in Location.find(): vibes = l.tlc if isinstance(vibes, dict): for k,v in vibes.iteritems(): if not isinstance(v,float): continue a = diffs.setdefault(k, {'min':999999, 'max':0}) if v > a['max']: a['max'] = v if v < a['min']: a['min'] = v largest = {k:(v['max']-v['min']) for k,v in diffs.iteritems()} largest = sorted(largest.items(), cmp=lambda x,y: cmp(x[1], y[1]), reverse=True) return largest
def get(self): locations = [loc for loc in Location.find()] interfaces = [ EnergyGateway, NetAtmo, HomeEnergyMonitor, Presence, Node, UPS, Wunderground, RTTP, PhilipsHue ] exchanges = [ Exchanges.node, Exchanges.energy, Exchanges.weather, Exchanges.presence, Exchanges.everything ] final = ['Clients', 'Triggers', 'Federation'] fnodes = [] links = [] res = g.INFLUX.query("SHOW MEASUREMENTS") measurements = [i for i in res.items()[0][1]] for f in final: add_node(fnodes, { 'name': f, 'id': "final.{}".format(f), 'type': 'final', }) for m in measurements: add_node(fnodes, { 'name': m['name'].split(".")[-1], 'id': "data.{}".format(m['name'].split(".")[-1]), 'type': 'data', 'startswith': [m['name']], }, startswith=m['name']) for i in interfaces: add_node( fnodes, { 'name': i.__name__, 'id': "interface.{}.{}".format(i.exchange.name, i.__name__), 'type': 'interface', }) for e in exchanges: add_node( fnodes, { 'name': e.name, 'id': "exchange.{}".format(e.name), 'type': 'exchange', }) ev_id = get_node_index(fnodes, 'exchange.everything') for loc in locations: add_node(fnodes, { 'name': loc.name, 'id': str(loc._id), 'type': 'location' }) add_link( links, { 'source': len(fnodes) - 1, 'target': get_node_index(fnodes, 'interface.presence.Presence'), 'value': .01 }) for i in loc.interfaces: if not i.interface._last_run: continue e_name = i.interface.exchange.name i_index = get_node_index( fnodes, "interface.{}.{}".format(e_name, i.interface.__class__.__name__)) e_id = get_node_index(fnodes, "exchange.{}".format(e_name)) add_link(links, { 'source': len(fnodes) - 1, 'target': i_index, 'value': .01, }) data_points = get_indexes_startswith( fnodes, i.interface.measurement_key) for dp in data_points: add_link(links, { 'source': i_index, 'target': dp, 'value': .01 }) add_link(links, { 'source': dp, 'target': e_id, 'value': .01 }) add_link(links, { 'source': dp, 'target': ev_id, 'value': .01 }) add_link( links, { 'source': get_node_index(fnodes, 'exchange.energy'), 'target': get_node_index(fnodes, 'final.Clients'), 'value': .01 }) add_link( links, { 'source': get_node_index(fnodes, 'exchange.presence'), 'target': get_node_index(fnodes, 'final.Clients'), 'value': .01 }) add_link( links, { 'source': get_node_index(fnodes, 'exchange.node'), 'target': get_node_index(fnodes, 'final.Clients'), 'value': .01 }) add_link( links, { 'source': get_node_index(fnodes, 'exchange.weather'), 'target': get_node_index(fnodes, 'final.Clients'), 'value': .01 }) add_link( links, { 'source': get_node_index(fnodes, 'exchange.everything'), 'target': get_node_index(fnodes, 'final.Triggers'), 'value': .01 }) add_link( links, { 'source': get_node_index(fnodes, 'exchange.everything'), 'target': get_node_index(fnodes, 'final.Federation'), 'value': .01 }) io = get_node_index(fnodes, 'data.inoffice') if not io: add_node(fnodes, { 'name': 'inoffice', 'id': 'data.inoffice', 'type': 'data' }) io = len(fnodes) - 1 add_link( links, { 'source': get_node_index(fnodes, 'interface.presence.Presence'), 'target': io, 'value': .01 }) add_link( links, { 'source': io, 'target': get_node_index(fnodes, 'exchange.presence'), 'value': .01 }) add_link(links, {'source': io, 'target': ev_id, 'value': .01}) return jsonify({'nodes': fnodes, 'links': links})
def get(self): locations = [loc for loc in Location.find()] interfaces = [EnergyGateway, NetAtmo, HomeEnergyMonitor, Presence, Node, UPS, Wunderground, RTTP, PhilipsHue] exchanges = [Exchanges.node, Exchanges.energy, Exchanges.weather, Exchanges.presence, Exchanges.everything] final = ["Clients", "Triggers", "Federation"] fnodes = [] links = [] res = g.INFLUX.query("SHOW MEASUREMENTS") measurements = [i for i in res.items()[0][1]] for f in final: add_node(fnodes, {"name": f, "id": "final.{}".format(f), "type": "final"}) for m in measurements: add_node( fnodes, { "name": m["name"].split(".")[-1], "id": "data.{}".format(m["name"].split(".")[-1]), "type": "data", "startswith": [m["name"]], }, startswith=m["name"], ) for i in interfaces: add_node( fnodes, {"name": i.__name__, "id": "interface.{}.{}".format(i.exchange.name, i.__name__), "type": "interface"}, ) for e in exchanges: add_node(fnodes, {"name": e.name, "id": "exchange.{}".format(e.name), "type": "exchange"}) ev_id = get_node_index(fnodes, "exchange.everything") for loc in locations: add_node(fnodes, {"name": loc.name, "id": str(loc._id), "type": "location"}) add_link( links, { "source": len(fnodes) - 1, "target": get_node_index(fnodes, "interface.presence.Presence"), "value": 0.01, }, ) for i in loc.interfaces: if not i.interface._last_run: continue e_name = i.interface.exchange.name i_index = get_node_index(fnodes, "interface.{}.{}".format(e_name, i.interface.__class__.__name__)) e_id = get_node_index(fnodes, "exchange.{}".format(e_name)) add_link(links, {"source": len(fnodes) - 1, "target": i_index, "value": 0.01}) data_points = get_indexes_startswith(fnodes, i.interface.measurement_key) for dp in data_points: add_link(links, {"source": i_index, "target": dp, "value": 0.01}) add_link(links, {"source": dp, "target": e_id, "value": 0.01}) add_link(links, {"source": dp, "target": ev_id, "value": 0.01}) add_link( links, { "source": get_node_index(fnodes, "exchange.energy"), "target": get_node_index(fnodes, "final.Clients"), "value": 0.01, }, ) add_link( links, { "source": get_node_index(fnodes, "exchange.presence"), "target": get_node_index(fnodes, "final.Clients"), "value": 0.01, }, ) add_link( links, { "source": get_node_index(fnodes, "exchange.node"), "target": get_node_index(fnodes, "final.Clients"), "value": 0.01, }, ) add_link( links, { "source": get_node_index(fnodes, "exchange.weather"), "target": get_node_index(fnodes, "final.Clients"), "value": 0.01, }, ) add_link( links, { "source": get_node_index(fnodes, "exchange.everything"), "target": get_node_index(fnodes, "final.Triggers"), "value": 0.01, }, ) add_link( links, { "source": get_node_index(fnodes, "exchange.everything"), "target": get_node_index(fnodes, "final.Federation"), "value": 0.01, }, ) io = get_node_index(fnodes, "data.inoffice") if not io: add_node(fnodes, {"name": "inoffice", "id": "data.inoffice", "type": "data"}) io = len(fnodes) - 1 add_link(links, {"source": get_node_index(fnodes, "interface.presence.Presence"), "target": io, "value": 0.01}) add_link(links, {"source": io, "target": get_node_index(fnodes, "exchange.presence"), "value": 0.01}) add_link(links, {"source": io, "target": ev_id, "value": 0.01}) return jsonify({"nodes": fnodes, "links": links})