def index(): datacenter_node = get_node_by_id("datacenter") datacenter_production_node = get_node_by_id_prod("overall_production") cluster_hardware = get_node_by_id("hardware_cluster") datacenter_consumption = _get_last_node_consumption(datacenter_node) datacenter_production = _get_last_node_consumption_prod(datacenter_production_node) cluster_hardware_consumption = _get_last_node_consumption(cluster_hardware) # # pue_ratio = datacenter_consumption / cluster_hardware_consumption _datacenter_data = db_aggregated_multitree_sensor_data(sensor_name="datacenter", start_date="now()-8d", end_date="now()", how="hourly") _cluster_data = db_aggregated_multitree_sensor_data(sensor_name="hardware_cluster", start_date="now()-8d", end_date="now()", how="hourly") _pue_data = { "end_date": _cluster_data.get("end_date"), "start_date": _cluster_data.get("start_date"), "means": [x / y for (x, y) in zip(_datacenter_data.get("means"), _cluster_data.get("means")) if x != None and y != None] } pue_ratio = np.mean(_pue_data.get("means")) last_temperature_mean = db_last_temperature_mean() # Last external temperature value extenal_temperature_sensors = get_temperature_sensors_infrastructure().get("room.top", {}).get("sensors", []) if len(extenal_temperature_sensors) > 0: extenal_temperature_sensor = extenal_temperature_sensors[-1] # Exponential backoff to_find the last temperature search_interval = 30 last_external_temperature_mean = None while last_external_temperature_mean is None and search_interval < 24 * 60: start_date = "now() - %sm" % search_interval end_date = "now() - %sm" % (search_interval - 30) last_temperatures = db_sensor_data(extenal_temperature_sensor, start_date=start_date, end_date=end_date) last_temperatures_values = last_temperatures.get("values", []) if len(last_temperatures_values) > 0: last_external_temperature_mean = last_temperatures_values[-1] else: search_interval = search_interval * 2 else: last_external_temperature_mean = "No external temperature sensor" sensors_count = get_sensors_count() return render_template("index.html.jinja2", pue_ratio=pue_ratio, datacenter_consumption=datacenter_consumption, datacenter_production=datacenter_production, cluster_hardware_consumption=cluster_hardware_consumption, last_temperature_mean=last_temperature_mean, last_external_temperature_mean=last_external_temperature_mean, sensors_count=sensors_count)
def production_drop_nested_query_and_dependencies(node, recreate_all): from core.data.production import get_root_nodes, get_tree, get_node_by_id current_node = node["node"] if "node" in node else node current_tree = get_tree(current_node) cq_name = "cq_%s" % (current_node["id"]) sub_query_sets = [] if "target" in current_node: sub_query_sets = [current_node["target"]] else: if "simplified_children" in current_node: for child in current_node["simplified_children"]: child_node = get_node_by_id(child) infos = production_drop_nested_query_and_dependencies(child_node, recreate_all) sub_query_sets += infos["sub_query_sets"] for child in current_tree["children"]: infos = production_drop_nested_query_and_dependencies(child, recreate_all) sub_query_sets += infos["sub_query_sets"] pseudo_query = "drop %s *" % (cq_name) # #print(pseudo_query) cq_drop_cqs_and_series_names(cq_name) return {"query_name": cq_name, "sub_query_sets": sub_query_sets}
def production_build_nested_query_and_dependencies(node, recreate_all): from core.data.production import get_root_nodes, get_tree, get_node_by_id current_node = node["node"] if "node" in node else node current_tree = get_tree(current_node) cq_name = "cq_%s" % (current_node["id"]) sub_query_sets = [] if "target" in current_node: sub_query_sets = [current_node["target"]] else: if False and "simplified_children" in current_node: for child in current_node["simplified_children"]: child_node = get_node_by_id(child) infos = production_build_nested_query_and_dependencies(child_node, recreate_all) sub_query_sets += infos["sub_query_sets"] else: for child in current_tree["children"]: infos = production_build_nested_query_and_dependencies(child, recreate_all) sub_query_sets += infos["sub_query_sets"] pseudo_query = "insert into %s * from sensors where sensor in [%s]" % (cq_name, ",".join(sub_query_sets)) # #print(pseudo_query) if recreate_all: cq_create_continuous_query(cq_name, sub_query_sets) else: cq_rebuild_continuous_query(cq_name, sub_query_sets) return {"query_name": cq_name, "sub_query_sets": sub_query_sets}
def test_get_node_by_id(self): from core.data.multitree import get_node_by_id node = get_node_by_id("ecotype_1") self.assertEqual(node.get("id"), "ecotype_1") self.assertEqual(node.get("name"), "ecotype-1") self.assertEqual(node.get("children"), ["ecotype_1_Z1_51", "ecotype_1_Z1_50"])
def multitree_tree_query(node_id): starting_node = get_node_by_id(node_id) if starting_node is not None: tree = get_tree(starting_node, False) return jsonify(tree) else: return jsonify({ "status": "failure", "cause": "'%s' is not a valid node id :-(" % (node_id) })
def multitree_sensors_data_query(node_id): starting_node = get_node_by_id(node_id) if starting_node is not None: sensors = get_sensors_tree(starting_node) return jsonify(sensors) else: return jsonify({ "status": "failure", "cause": "'%s' is not a valid node id :-(" % (node_id) })
def power_infrastructure(): """Endpoint returning an hierarchical description of the Seduce infrastructure. --- tags: - power_infrastructure definitions: TreeDict: type: object properties: level: type: int node: type: object properties: id: type: string name: type: string root: type: boolean target: type: string required: false children: type: array items: type: string required: false children: type: array items: type: TreeDict responses: 200: description: A JSON object describing the Seduce infrastructure. schema: $ref: '#/definitions/TreeDict' examples: response: { "level": 0, "children": [ { "level": 1, "children": [ # a list of children nodes ], "node": { "children": [ "cooling_room" ], "id": "room", "name": "Room", "root": false } }, { "level": 1, "children": [ # a list of children nodes ], "node": { "children": [ "cooling_cluster", "hardware_cluster" ], "id": "cluster", "name": "Cluster", "root": false } } ], "node": { "children": [ "cluster", "room" ], "id": "datacenter", "name": "Datacenter", "root": true } } """ from core.data.multitree import get_node_by_id from core.data.multitree import get_tree root_node_id = "datacenter" starting_node = get_node_by_id(root_node_id) if starting_node is not None: tree = get_tree(starting_node, False) return jsonify(tree) else: return jsonify({ "status": "failure", "cause": "'%s' is not a valid node id :-(" % (root_node_id) })