Beispiel #1
0
    def get(self, node_id):
        show_last = request.args.get("showLast")
        nodes = app.getNodeDBusObject()
        if not nodes.doesNodeExist(node_id):
            return UNKNOWN_NODE_RESPONSE

        all_property_histories = {}

        all_property_histories["offset"] = nodes.getHistoryOffset(node_id)
        for prop in nodes.getAdditionalProperties(node_id):
            all_property_histories[prop] = nodes.getAdditionalPropertyHistory(
                node_id, prop)

        all_property_histories["temperature"] = nodes.getTemperatureHistory(
            node_id)

        resources_gained = nodes.getResourcesGainedHistory(node_id)
        for key in resources_gained:
            all_property_histories["%s received" % key] = resources_gained[key]

        resources_produced = nodes.getResourcesProducedHistory(node_id)
        for key in resources_produced:
            all_property_histories["%s produced" %
                                   key] = resources_produced[str(key)]

        for key in all_property_histories:
            if show_last is not None and show_last and key != "offset":
                try:
                    all_property_histories[key] = all_property_histories[key][
                        -int(show_last):]
                except ValueError:
                    pass
        return all_property_histories
 def get(self):
     nodes = app.getNodeDBusObject()
     display_data = []
     for node_id in nodes.getAllNodeIds():  # type: ignore
         data = getNodeData(node_id)
         display_data.append(data)
     return display_data
 def get(self, node_id):
     nodes = app.getNodeDBusObject()
     data = getNodeData(node_id)
     if data is None:
         return UNKNOWN_NODE_RESPONSE
     data["surface_area"] = nodes.getSurfaceArea(node_id)  # type: ignore
     data["description"] = nodes.getDescription(node_id)  # type: ignore
     return data
 def put(self, node_id):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     if "performance" in request.form:
         new_performance = request.form["performance"]
     else:
         new_performance = json.loads(request.data)["performance"]
     nodes.setTargetPerformance(node_id, float(new_performance))
     return nodes.getPerformance(node_id)
 def get(self, node_id):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     data = {}
     data["surface_area"] = nodes.getSurfaceArea(node_id)
     data["description"] = nodes.getDescription(node_id)
     data["has_settable_performance"] = nodes.hasSettablePerformance(
         node_id)
     data["supported_modifiers"] = nodes.getSupportedModifiers(node_id)
     return data
 def get(self, node_id):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     result = nodes.getTemperatureHistory(node_id)  # type: ignore
     show_last = request.args.get("showLast")
     if show_last is not None and show_last:
         try:
             result = result[-int(show_last):]
         except ValueError:
             pass
     return result
    def post(self, node_id):
        nodes = app.getNodeDBusObject()
        if not nodes.doesNodeExist(node_id):
            return UNKNOWN_NODE_RESPONSE

        try:
            data = json.loads(request.data)
        except:
            return Response("Unable to format the provided data!", status=400)
        successful = nodes.addModifierToNode(node_id, data["modifier_name"])
        if not successful:
            return Response("Unknown modifier", status=400)
        return nodes.getActiveModifiers(node_id)
def getAdditionalPropertiesForNode(
        node_id: str) -> Optional[List[Dict[str, Union[str, float]]]]:
    nodes = app.getNodeDBusObject()
    if not nodes.doesNodeExist(node_id):
        return None
    additional_properties = nodes.getAdditionalProperties(node_id)
    result = []
    for prop in additional_properties:
        item = {}
        item["key"] = prop
        item["value"] = nodes.getAdditionalPropertyValue(node_id, prop)
        item["max_value"] = nodes.getMaxAdditionalPropertyValue(node_id, prop)
        result.append(item)
    return result
def getNodeData(node_id: str) -> Optional[Dict[str, Any]]:
    nodes = app.getNodeDBusObject()
    if node_id not in nodes.getAllNodeIds():
        return None

    required_resources = []

    for key, value in nodes.getResourcesRequired(node_id).items():
        required_resources.append({"resource_type": key, "value": value})

    received_resources = []
    for key, value in nodes.getResourcesReceived(node_id).items():
        received_resources.append({"resource_type": key, "value": value})

    optional_required_resources = []
    for key, value in nodes.getOptionalResourcesRequired(node_id).items():
        optional_required_resources.append({
            "resource_type": key,
            "value": value
        })

    resources_produced = []
    for key, value in nodes.getResourcesProduced(node_id).items():
        resources_produced.append({"resource_type": key, "value": value})

    data = {
        "node_id": node_id,
        "temperature": nodes.getTemperature(node_id),
        "enabled": nodes.isNodeEnabled(node_id),
        "active": nodes.isNodeActive(node_id),
        "performance": nodes.getPerformance(node_id),
        "target_performance": nodes.getTargetPerformance(node_id),
        "min_performance": nodes.getMinPerformance(node_id),
        "max_performance": nodes.getMaxPerformance(node_id),
        "max_safe_temperature": nodes.getMaxSafeTemperature(node_id),
        "heat_convection": nodes.getHeatConvectionCoefficient(node_id),
        "heat_emissivity": nodes.getHeatEmissivity(node_id),
        "health": nodes.getAdditionalPropertyValue(node_id, "health"),
        "is_temperature_dependant": nodes.getIsTemperatureDependant(node_id),
        "optimal_temperature": nodes.getOptimalTemperature(node_id),
        "resources_required": required_resources,
        "optional_resources_required": optional_required_resources,
        "resources_received": received_resources,
        "resources_produced": resources_produced,
        "additional_properties": getAdditionalPropertiesForNode(node_id),
        "effectiveness_factor": nodes.getEffectivenessFactor(node_id)
    }
    return data
 def get(self, node_id, additional_property):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     data = nodes.getAdditionalPropertyValue(node_id, additional_property)
     return data
 def get(self, node_id):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     return nodes.getActiveModifiers(node_id)
    def get(self, node_id):
        nodes = app.getNodeDBusObject()
        if not nodes.doesNodeExist(node_id):
            return UNKNOWN_NODE_RESPONSE

        return nodes.getOutgoingConnections(node_id)
 def get(self, node_id, prop):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     return nodes.getAdditionalPropertyHistory(node_id, prop)
 def get(self, node_id):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     return nodes.getTemperature(node_id)
 def get(self, node_id):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     return nodes.getTargetPerformance(node_id)
 def put(self, node_id):
     nodes = app.getNodeDBusObject()
     if not nodes.doesNodeExist(node_id):
         return UNKNOWN_NODE_RESPONSE
     nodes.setNodeEnabled(node_id, not nodes.isNodeEnabled(node_id))