Exemplo n.º 1
0
    # To make the instance valid we need to add values to our rule fields. We
    # look herefore at the subtypes of RuleFields.

    # ### 3.1.1 DataFields:
    #
    # Each ComplexDataProperty in our vocabulary with the
    # type "simple" was converted to this field type. (All for normal classes)
    # As values it takes basic types as string, int, bool,..

    my_building.goalTemperature.add(23)
    my_building.name.add("Main Building")

    # we can check again if all DataFields are now valid:
    print("\u0332".join("DataFields of my_building:"))
    for field in my_building.get_data_fields():
        print(f"Name: {field.name}, Rule: {field.rule}, Values: "
              f"{field.get_all_raw()}, Valid: {field.is_valid()}")
    print("")

    # Datafields can also specify rules with Datatype enums, in that case we
    # can either directly add the string, or use the enum of the model
    # In each case only the string value gets saved without enum information
    # Each enum value has the prefix value_ to prevent name clashes
    sensor = Sensor(id="sensor1")
    sensor.measures.add(MeasurementType.value_Air_Quality)
    sensor.measures.add("Air_Quality")
    print("\u0332".join("DataFields with enum values:"))
    print(f"Raw Values: {sensor.measures.get_all_raw()}")
    print(f"Values: {sensor.measures.get_all()}")
    print("")