Exemple #1
0
async def get_all_metadata_source(sourceId: str) -> List[Metadatum]:
    if sourceId.endswith("temp") and "plantA" in sourceId:
        return [
            Metadatum(key="Max Value", value=300.0, dataType="float"),
            Metadatum(key="Min Value", value=-100.0, dataType="float"),
            Metadatum(key="Last Self-Check Okay",
                      value=True,
                      dataType="boolean"),
            get_metadatum_from_store(sourceId, "Sensor Config"),
        ]
    if sourceId.endswith("temp") and "plantB" in sourceId:
        return [
            Metadatum(key="Max Value", value=150.0, dataType="float"),
            Metadatum(key="Min Value", value=-30.0, dataType="float"),
            Metadatum(key="Last Self-Check Okay",
                      value=True,
                      dataType="boolean"),
            get_metadatum_from_store(sourceId, "Sensor Config"),
        ]
    if sourceId.endswith("anomaly_score") and "plantA" in sourceId:
        return [
            Metadatum(key="Max Value", value=1.0, dataType="float"),
            Metadatum(key="Min Value", value=0.0, dataType="float"),
            get_metadatum_from_store(sourceId, "Overshooting Allowed"),
        ]
    if sourceId.endswith("anomaly_score") and "plantB" in sourceId:
        return [
            Metadatum(key="Max Value", value=1.0, dataType="float"),
            Metadatum(key="Min Value", value=0.0, dataType="float"),
            get_metadatum_from_store(sourceId, "Overshooting Allowed"),
        ]

    return []
Exemple #2
0
async def get_all_metadata_thingNode(thingNodeId: str) -> List[Metadatum]:
    if thingNodeId == "root.plantA":
        return [
            Metadatum(key="Temperature Unit", value="F", dataType="string"),
            Metadatum(key="Pressure Unit", value="psi", dataType="string"),
            Metadatum(
                # a metadatum that is not an explicit source and calculated dynamically
                key="Plant Age in Years",
                value=calculate_age(datetime.date(2012, 12, 7)),
                dataType="int",
            ),
            # this metadatum is a sink leaf but as a source only available attached to the thingNode
            get_metadatum_from_store(thingNodeId, "Anomaly State"),
        ]
    if thingNodeId == "root.plantB":
        return [
            Metadatum(key="Temperature Unit", value="C", dataType="string"),
            Metadatum(key="Pressure Unit", value="bar", dataType="string"),
            Metadatum(
                # a metadatum that is not an explicit source and calculated dynamically
                key="Plant Age in Years",
                value=calculate_age(datetime.date(2017, 8, 22)),
                dataType="int",
            ),
            # this metadatum is a sink leaf but as a source only available attached to the thingNode
            get_metadatum_from_store(thingNodeId, "Anomaly State"),
        ]
    return []
Exemple #3
0
async def get_all_metadata_thingNode(thingNodeId: str):
    if thingNodeId == "root.plantA":
        return [
            {"key": "Temperature Unit", "value": "F", "dataType": "string"},
            {"key": "Pressure Unit", "value": "psi", "dataType": "string"},
            {  # a metadatum that is not an explicit source and calculated dynamically
                "key": "Plant Age in Years",
                "value": calculate_age(datetime.date(2012, 12, 7)),
                "dataType": "int",
            },
            # this metadatum is a sink leaf but as a source only available attached to the thingNode
            get_metadatum_from_store(thingNodeId, "Anomaly State"),
        ]
    if thingNodeId == "root.plantB":
        return [
            {"key": "Temperature Unit", "value": "C", "dataType": "string"},
            {"key": "Pressure Unit", "value": "bar", "dataType": "string"},
            {  # a metadatum that is not an explicit source and calculated dynamically
                "key": "Plant Age in Years",
                "value": calculate_age(datetime.date(2017, 8, 22)),
                "dataType": "int",
            },
            # this metadatum is a sink leaf but as a source only available attached to the thingNode
            get_metadatum_from_store(thingNodeId, "Anomaly State"),
        ]
    return []
Exemple #4
0
async def get_all_metadata_sink(sinkId: str):
    if sinkId.endswith("anomaly_score") and "plantA" in sinkId:
        return [
            {
                "key": "Max Value",
                "value": 1.0,
                "dataType": "float"
            },
            {
                "key": "Min Value",
                "value": 0.0,
                "dataType": "float"
            },
            get_metadatum_from_store(sinkId, "Overshooting Allowed"),
        ]
    if sinkId.endswith("anomaly_score") and "plantB" in sinkId:
        return [
            {
                "key": "Max Value",
                "value": 1.0,
                "dataType": "float"
            },
            {
                "key": "Min Value",
                "value": 0.0,
                "dataType": "float"
            },
            get_metadatum_from_store(sinkId, "Overshooting Allowed"),
        ]
    return []
Exemple #5
0
async def get_metadata_thingNode_by_key(thingNodeId: str,
                                        key: str) -> Metadatum:
    # pylint: disable=too-many-return-statements
    key = unquote(key)
    if thingNodeId == "root.plantA":
        if key == "Temperature Unit":
            return Metadatum(
                key="Temperature Unit",
                value="F",
                dataType="string",
            )
        if key == "Pressure Unit":
            return Metadatum(
                key="Pressure Unit",
                value="psi",
                dataType="string",
            )
        if key == "Plant Age in Years":
            return Metadatum(
                key="Plant Age in Years",
                value=calculate_age(datetime.date(2012, 12, 7)),
                dataType="int",
            )
        if key == "Anomaly State":
            return get_metadatum_from_store(thingNodeId, "Anomaly State")

    if thingNodeId == "root.plantB":
        if key == "Temperature Unit":
            return Metadatum(
                key="Temperature Unit",
                value="C",
                dataType="string",
            )
        if key == "Pressure Unit":
            return Metadatum(
                key="Pressure Unit",
                value="bar",
                dataType="string",
            )
        if key == "Plant Age in Years":
            return Metadatum(
                key="Plant Age in Years",
                value=calculate_age(datetime.date(2017, 8, 22)),
                dataType="int",
            )
        if key == "Anomaly State":
            return get_metadatum_from_store(thingNodeId, "Anomaly State")
    raise HTTPException(
        404,
        f"Could not find metadatum attached/at thingNode {thingNodeId} with key {key}",
    )
Exemple #6
0
async def get_all_metadata_sink(sinkId: str) -> List[Metadatum]:
    if sinkId.endswith("anomaly_score") and "plantA" in sinkId:
        return [
            Metadatum(key="Max Value", value=1.0, dataType="float"),
            Metadatum(key="Min Value", value=0.0, dataType="float"),
            get_metadatum_from_store(sinkId, "Overshooting Allowed"),
        ]
    if sinkId.endswith("anomaly_score") and "plantB" in sinkId:
        return [
            Metadatum(key="Max Value", value=1.0, dataType="float"),
            Metadatum(key="Min Value", value=0.0, dataType="float"),
            get_metadatum_from_store(sinkId, "Overshooting Allowed"),
        ]
    return []
Exemple #7
0
async def get_metadata_source_by_key(sourceId: str, key: str):
    # pylint: disable=too-many-return-statements,too-many-branches
    key = unquote(key)
    if sourceId.endswith("temp") and "plantA" in sourceId:
        if key == "Max Value":
            return {"key": "Max Value", "value": 300.0, "dataType": "float"}
        if key == "Min Value":
            return {"key": "Min Value", "value": -100.0, "dataType": "float"}
        if key == "Last Self-Check Okay":
            return {
                "key": "Last Self-Check Okay",
                "value": True,
                "dataType": "boolean"
            }
        if key == "Sensor Config":
            return get_metadatum_from_store(sourceId, "Sensor Config")

    elif sourceId.endswith("temp") and "plantB" in sourceId:
        if key == "Max Value":
            return {"key": "Max Value", "value": 150.0, "dataType": "float"}
        if key == "Min Value":
            return {"key": "Min Value", "value": -30.0, "dataType": "float"}
        if key == "Last Self-Check Okay":
            return {
                "key": "Last Self-Check Okay",
                "value": True,
                "dataType": "boolean"
            }
        if key == "Sensor Config":
            return get_metadatum_from_store(sourceId, "Sensor Config")

    if sourceId.endswith("anomaly_score") and "plantA" in sourceId:
        if key == "Max Value":
            return {"key": "Max Value", "value": 1.0, "dataType": "float"}
        if key == "Min Value":
            return {"key": "Min Value", "value": 0.0, "dataType": "float"}
        if key == "Overshooting Allowed":
            return get_metadatum_from_store(sourceId, "Overshooting Allowed")

    elif sourceId.endswith("anomaly_score") and "plantB" in sourceId:
        if key == "Max Value":
            return {"key": "Max Value", "value": 1.0, "dataType": "float"}
        if key == "Min Value":
            return {"key": "Min Value", "value": 0.0, "dataType": "float"}
        if key == "Overshooting Allowed":
            return get_metadatum_from_store(sourceId, "Overshooting Allowed")
    raise HTTPException(
        404,
        f"Could not find metadatum attached to source {sourceId} with key {key}"
    )
Exemple #8
0
async def get_metadata_sink_by_key(sinkId: str, key: str) -> Metadatum:
    key = unquote(key)

    if sinkId.endswith("anomaly_score") and "plantA" in sinkId:
        if key == "Max Value":
            return Metadatum(key="Max Value", value=1.0, dataType="float")
        if key == "Min Value":
            return Metadatum(key="Min Value", value=0.0, dataType="float")
        if key == "Overshooting Allowed":
            return get_metadatum_from_store(sinkId, "Overshooting Allowed")

    elif sinkId.endswith("anomaly_score") and "plantB" in sinkId:
        if key == "Max Value":
            return Metadatum(key="Max Value", value=1.0, dataType="float")
        if key == "Min Value":
            return Metadatum(key="Min Value", value=0.0, dataType="float")
        if key == "Overshooting Allowed":
            return get_metadatum_from_store(sinkId, "Overshooting Allowed")

    raise HTTPException(
        404,
        f"Could not find metadatum attached to sink {sinkId} with key {key}")
Exemple #9
0
async def post_metadata_sink_by_key(sinkId: str, key: str,
                                    metadatum: PostMetadatum):
    key = unquote(key)
    if sinkId.endswith("anomaly_score") and key == "Overshooting Allowed":

        old_metadatum = get_metadatum_from_store(sinkId, key)

        new_metadatum = metadatum.dict()

        new_metadatum["dataType"] = old_metadatum["dataType"]
        new_metadatum["isSink"] = old_metadatum.get("isSink", True)

        set_metadatum_in_store(sinkId, key, new_metadatum)
        return {"message": "success"}
    return HTTPException(
        404,
        f"There is no writable metadatum at sink {sinkId} with key {key}",
    )
Exemple #10
0
async def post_metadata_source_by_key(sourceId: str, key: str,
                                      metadatum: PostMetadatum):
    key = unquote(key)
    if sourceId.endswith("temp") and key == "Sensor Config":

        old_metadatum = get_metadatum_from_store(sourceId, key)

        new_metadatum = metadatum.dict()

        new_metadatum["dataType"] = old_metadatum["dataType"]
        new_metadatum["isSink"] = old_metadatum.get("isSink", True)

        set_metadatum_in_store(sourceId, key, new_metadatum)
        return {"message": "success"}
    return HTTPException(
        404,
        f"There is no writable metadatum at source {sourceId} with key {key}",
    )
Exemple #11
0
async def post_metadata_thingNode_by_key(
        thingNodeId: str, key: str,
        metadatum: PostMetadatum) -> Union[dict, HTTPException]:
    key = unquote(key)
    if thingNodeId in ["root.plantA", "root.plantB"]:

        old_metadatum = get_metadatum_from_store(thingNodeId, key)

        new_metadatum = metadatum.dict()

        new_metadatum["dataType"] = old_metadatum["dataType"]
        new_metadatum["isSink"] = old_metadatum.get("isSink", True)

        set_metadatum_in_store(thingNodeId, key, new_metadatum)
        return {"message": "success"}

    return HTTPException(
        404,
        f"There is no writable metadatum at thingNode {thingNodeId} with key {key}",
    )
Exemple #12
0
async def post_metadata_sink_by_key(
        sinkId: str, key: str,
        metadatum: PostMetadatum) -> Union[dict, HTTPException]:
    key = unquote(key)
    if sinkId.endswith("anomaly_score") and key == "Overshooting Allowed":

        old_metadatum = get_metadatum_from_store(sinkId, key)

        new_metadatum = Metadatum(
            key=metadatum.key,
            value=metadatum.value,
            dataType=old_metadatum.dataType,
            isSink=old_metadatum.isSink or True,
        )

        set_metadatum_in_store(sinkId, key, new_metadatum)
        return {"message": "success"}
    return HTTPException(
        404,
        f"There is no writable metadatum at sink {sinkId} with key {key}",
    )
Exemple #13
0
async def post_metadata_source_by_key(
        sourceId: str, key: str,
        metadatum: PostMetadatum) -> Union[dict, HTTPException]:
    key = unquote(key)
    if sourceId.endswith("temp") and key == "Sensor Config":

        old_metadatum = get_metadatum_from_store(sourceId, key)

        new_metadatum = Metadatum(
            key=metadatum.key,
            value=metadatum.value,
            dataType=old_metadatum.dataType,
            isSink=old_metadatum.isSink or True,
        )

        set_metadatum_in_store(sourceId, key, new_metadatum)
        return {"message": "success"}
    return HTTPException(
        404,
        f"There is no writable metadatum at source {sourceId} with key {key}",
    )
Exemple #14
0
async def get_all_metadata_source(sourceId: str):
    if sourceId.endswith("temp") and "plantA" in sourceId:
        return [
            {
                "key": "Max Value",
                "value": 300.0,
                "dataType": "float"
            },
            {
                "key": "Min Value",
                "value": -100.0,
                "dataType": "float"
            },
            {
                "key": "Last Self-Check Okay",
                "value": True,
                "dataType": "boolean"
            },
            get_metadatum_from_store(sourceId, "Sensor Config"),
        ]
    if sourceId.endswith("temp") and "plantB" in sourceId:
        return [
            {
                "key": "Max Value",
                "value": 150.0,
                "dataType": "float"
            },
            {
                "key": "Min Value",
                "value": -30.0,
                "dataType": "float"
            },
            {
                "key": "Last Self-Check Okay",
                "value": True,
                "dataType": "boolean"
            },
            get_metadatum_from_store(sourceId, "Sensor Config"),
        ]
    if sourceId.endswith("anomaly_score") and "plantA" in sourceId:
        return [
            {
                "key": "Max Value",
                "value": 1.0,
                "dataType": "float"
            },
            {
                "key": "Min Value",
                "value": 0.0,
                "dataType": "float"
            },
            get_metadatum_from_store(sourceId, "Overshooting Allowed"),
        ]
    if sourceId.endswith("anomaly_score") and "plantB" in sourceId:
        return [
            {
                "key": "Max Value",
                "value": 1.0,
                "dataType": "float"
            },
            {
                "key": "Min Value",
                "value": 0.0,
                "dataType": "float"
            },
            get_metadatum_from_store(sourceId, "Overshooting Allowed"),
        ]

    return []