def home(): """ For root route we display a simple volcano dashboard to view node and sensor data in a time series graph. """ # Query the node assets we tracked nodes = [] default_node = '' for node in asset.get_collection('/node'): nodes.append({ "key": node['uri'], "val": node['name'] }) if node['name'] == 'N10': default_node = node['uri'] # Query the sensor assets we tracked sensors = [] for sensor in asset.get_collection('/datatype'): sensors.append({ "key": sensor['tag'], "val": sensor['data_type'] + " (%s)" % (sensor['tag']) }) _cache_nodes_and_sensors(nodes, sensors) # Render the dashboard jinja2 template return render_template('home.html', sensors=json.dumps(natural_sort(sensors)), default_node=default_node, nodes=json.dumps(natural_sort(nodes)))
def node(guid): """ .. http:get:: /api/1.0/node/:guid Responds with metadata for a single node and its corresponding sensors. **Example request**: .. sourcecode:: http GET /api/1.0/node/762b8ff0-8679-11e6-a353-2f6c041e2491 HTTP/1.1 Host: predix-volcano.run.aws-usw02-pr.ice.predix.io Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json { "description": "\\N", "location": "\\N", "name": "N10", "sensors": [ { "uri": "/sensor/7635c920-8679-11e6-a353-2f6c041e2491" }, { "uri": "/sensor/763701a1-8679-11e6-a353-2f6c041e2491" }, ... ], "status": "OFFLINE", "uri": "/node/762b8ff0-8679-11e6-a353-2f6c041e2491", "volcano": "/volcano/35dc3e90-8679-11e6-bda3-ef77801087ee" } """ nodes = asset.get_collection("/node/%s" % (guid)) if len(nodes) == 1: node = nodes[0] uri = node['uri'] sensors = asset.get_collection('/sensor', filter="node=%s" % (uri), fields=['uri', 'name']) nodes[0].update({'sensors': sensors}) return jsonify(nodes[0])
def node(node_id, sensor_tags): """ For this route we display a simple volcano dashboard to view specified node and sensor data in a time series graph. """ # Query the node assets we tracked nodes = [] default_node = '' default_node_name = '' is_valid_node_id = False # used to validate node_id sensor_tags_lst = sensor_tags.split(",") # store sensor ids as list node_uri = '/node/' + node_id for node in asset.get_collection('/node'): nodes.append({ "key": node['uri'], "val": node['name'] }) if node['name'] == 'N10': default_node = node['uri'] if node_uri == node['uri']: # if node uri matched then node id is valid is_valid_node_id = True default_node = node_uri default_node_name = node['name'] if not is_valid_node_id: return generateResponse("Invalid node id", 401) # Query the sensor assets we tracked sensors = [] for sensor in asset.get_collection('/datatype'): sensors.append({ "key": sensor['tag'], "val": sensor['data_type'] + " (%s)" % (sensor['tag']) }) if sensor['tag'] in sensor_tags_lst: # Remove valid tag sensor_tags_lst.remove(sensor['tag']) if sensor_tags_lst != []: # sensor tag lists is not empty --> has invalid tags return generateResponse("Invalid sensor tag", 401) # Render the dashboard jinja2 template return render_template('home.html', sensors=json.dumps(natural_sort(sensors)), default_node=default_node, default_node_name=default_node_name, node_id=node_id, sensor_tags=sensor_tags, nodes=json.dumps(natural_sort(nodes)))
def sensor(guid): """ .. http:get:: /api/1.0/sensor/:guid Responds with metadata for a single sensor. **Example request**: .. sourcecode:: http GET /api/1.0/sensor/1248ff60-e707-11e6-89c8-314aa4f67f8c HTTP/1.1 Host: predix-volcano.run.aws-usw02-pr.ice.predix.io Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json { "data_frequency": "1800000", "data_type": "/datatype/ed5edee0-e701-11e6-83c1-01ce06e6d17f", "description": "\\N", "node": "/node/ede3ed60-e701-11e6-83c1-01ce06e6d17f", "status": "OFFLINE", "uri": "/sensor/1248ff60-e707-11e6-89c8-314aa4f67f8c" } """ sensors = asset.get_collection("/sensor/%s" % (guid)) return jsonify(sensors[0])
def datatype(guid): """ A specific datatype instance. .. http:get:: /api/1.0/datatype/:guid Responds with metadata for a single data type **Example request**: .. sourcecode:: http GET /api/1.0/datatype/35dcb3c2-8679-11e6-bda3-ef77801087ee HTTP/1.1 Host: predix-volcano.run.aws-usw02-pr.ice.predix.io Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json { "data_type": "humidity", "tag": "HUMA", "unit": "relative humidity", "uri": "/datatype/35dcb3c2-8679-11e6-bda3-ef77801087ee" } """ datatypes = asset.get_collection("/datatype/%s" % (guid)) return jsonify(datatypes[0])
def datatypes(): """ Resource representing data types available. .. http:get:: /api/1.0/datatypes Responds with a list of available datatypes. **Example request**: .. sourcecode:: http GET /api/1.0/datatypes HTTP/1.1 Host: predix-volcano.run.aws-usw02-pr.ice.predix.io Accept: application/json [ { "data_type": "temperature", "tag": "TCA", "unit": "celcius", "uri": "/datatype/35dcb3c0-8679-11e6-bda3-ef77801087ee" }, { "data_type": "pressure", "tag": "PA", "unit": "pascal", "uri": "/datatype/35dcb3c1-8679-11e6-bda3-ef77801087ee" }, ... ] """ datatypes = asset.get_collection('/datatype') return jsonify(datatypes)
def home(): """ For root route we display a simple volcano dashboard to view node and sensor data in a time series graph. """ # Query the node assets we tracked nodes = [] default_node = '' default_node_name = '' node_id = '' sensor_tags = 'HUMA,TCA' # Default sensors for node in asset.get_collection('/node'): nodes.append({ "key": node['uri'], "val": node['name'] }) if node['name'] == 'N10': default_node = node['uri'] default_node_name = node['name'] node_id = default_node.split("/")[-1] # get node id from uri # Query the sensor assets we tracked sensors = [] for sensor in asset.get_collection('/datatype'): sensors.append({ "key": sensor['tag'], "val": sensor['data_type'] + " (%s)" % (sensor['tag']) }) # Render the dashboard jinja2 template return render_template('home.html', sensors=json.dumps(natural_sort(sensors)), default_node=default_node, default_node_name=default_node_name, node_id=node_id, sensor_tags=sensor_tags, nodes=json.dumps(natural_sort(nodes)))
def nodes(): """ Resource representing sensor nodes -- a collection of sensors installed as part of a network at a single location. .. http:get:: /api/1.0/nodes Responds with a list of available nodes. **Example request**: .. sourcecode:: http GET /api/1.0/nodes HTTP/1.1 Host: predix-volcano.run.aws-usw02-pr.ice.predix.io Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json [ { "description": "\\N", "location": "\\N", "name": "N10", "status": "OFFLINE", "uri": "/node/762b8ff0-8679-11e6-a353-2f6c041e2491", "volcano": "/volcano/35dc3e90-8679-11e6-bda3-ef77801087ee" }, { "description": "\\N", "location": "\\N", "name": "N7", "status": "OFFLINE", "uri": "/node/762c5340-8679-11e6-a353-2f6c041e2491", "volcano": "/volcano/35dc3e90-8679-11e6-bda3-ef77801087ee" }, ... ] """ nodes = asset.get_collection('/node') return jsonify(nodes)
def sensors(): """ Resource representing individual sensors. .. http:get:: /api/1.0/sensors Responds with a list of available sensors. **Example request**: .. sourcecode:: http GET /api/1.0/sensors HTTP/1.1 Host: predix-volcano.run.aws-usw02-pr.ice.predix.io Accept: application/json **Example response**: .. sourcecode:: http HTTP/1.1 200 OK Content-Type: application/json [ { "data_frequency": "1800000", "data_type": "/datatype/ed5edee0-e701-11e6-83c1-01ce06e6d17f", "description": "\\N", "node": "/node/ede3ed60-e701-11e6-83c1-01ce06e6d17f", "status": "OFFLINE", "uri": "/sensor/1248ff60-e707-11e6-89c8-314aa4f67f8c" }, { "data_frequency": "1800000", "data_type": "/datatype/35dcdad2-8679-11e6-bda3-ef77801087ee", "description": "\\N", "node": "/node/762b8ff0-8679-11e6-a353-2f6c041e2491", "status": "OFFLINE", "uri": "/sensor/7635c920-8679-11e6-a353-2f6c041e2491" }, ... ] """ sensors = asset.get_collection('/sensor') return jsonify(sensors)