Skip to content

Commit

Permalink
chore: tiny adjustment of the tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
djs0109 committed Apr 24, 2024
1 parent 9a2c3b4 commit a6e1e91
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
# # Exercise 8: MultiEntity and Expression Language
# The MultiEntity plugin Allows the devices provisioned in the IoTAgent to map their
attributes to more than one entity, # declaring the target entity through the
# The MultiEntity plugin allows the devices provisioned in the IoTAgent to map their
attributes to more than one entity, declaring the target entity through the
Configuration or Device provisioning APIs.
# The IoTAgent Library provides an expression language for measurement transformation,
Expand All @@ -27,6 +27,7 @@

from filip.clients.ngsi_v2 import IoTAClient, ContextBrokerClient
from filip.models.base import FiwareHeader
from filip.models.ngsi_v2.context import ContextEntity, NamedContextAttribute
from filip.models.ngsi_v2.iot import (Device, ServiceGroup, TransportProtocol,
PayloadProtocol, DeviceAttribute,
ExpressionLanguage)
Expand Down Expand Up @@ -77,8 +78,9 @@

# TODO: Create a device with two attributes 'location' and 'fillingLevel' that use
# expressions. These attributes are based on the attributes 'longitude',
# 'latitude' and 'level'. 'location' is an array with 'longitude' and 'latitude'.
# 'fillingLevel' is 'level' divided by 100
# 'latitude' and 'level', while:
# 1. 'location' is an array with 'longitude' and 'latitude'.
# 2. 'fillingLevel' is 'level' divided by 100
device1 = Device(device_id="waste_container_001",
entity_name="urn:ngsi-ld:WasteContainer:001",
entity_type="WasteContainer",
Expand All @@ -88,10 +90,10 @@
)
iota_client.post_device(device=device1)

# TODO: Setting expression language to JEXL at Device level with other attributes.
# The attribute 'value' (Number) is itself multiplied by 5. The attribute
# 'consumption' (Text) is the trimmed version of the attribute 'spaces' (Text).
# The attribute 'iso_time' (Text) is the current 'timestamp' (Number) transformed into the ISO format.
# TODO: Setting expression language to JEXL at Device level with five attributes, while
# 1. The attribute 'value' (Number) is itself multiplied by 5. The attribute
# 2. 'consumption' (Text) is the trimmed version of the attribute 'spaces' (Text).
# 3. The attribute 'iso_time' (Text) is the current 'timestamp' (Number) transformed into the ISO format.
device2 = Device(device_id="waste_container_002",
entity_name="urn:ngsi-ld:WasteContainer:002",
entity_type="WasteContainer",
Expand All @@ -114,10 +116,26 @@

client.disconnect()

# TODO: Create a weather station device with multi entity attributes (Number). 'v'
# is multiplied by 100 and is a standard attribute. 'v1' and 'v2' are multiplied
# by 100 and are multi entity attributes of type SubWeatherStation. The name of
# each attribute is 'vol'.
# Printing context entities of OCB
for context_entity in cb_client.get_entity_list(entity_types=["WasteContainer"]):
print(context_entity.model_dump_json(indent=4))

# Creating two SubWeatherStation entities
entity1 = ContextEntity(id="urn:ngsi-ld:SubWeatherStation:001",
type="SubWeatherStation")
entity1.add_attributes(attrs=[NamedContextAttribute(name="vol", type="Number")])
cb_client.post_entity(entity1)

entity2 = ContextEntity(id="urn:ngsi-ld:SubWeatherStation:002",
type="SubWeatherStation")
entity2.add_attributes(attrs=[NamedContextAttribute(name="vol", type="Number")])
cb_client.post_entity(entity2)

# TODO: Create a weather station device with multi entity attributes (Number).
# 'v' is multiplied by 100 and is a standard attribute.
# 'v1' and 'v2' are multiplied by 100 and should be linked with entities of
# the SubWeatherStation.
# The name of each attribute is 'vol'.
device3 = Device(device_id="weather_station_001",
entity_name="urn:ngsi-ld:WeatherStation:001",
entity_type="WeatherStation",
Expand All @@ -140,7 +158,6 @@
time.sleep(2)

# Printing context entities of OCB
for context_entity in cb_client.get_entity_list(entity_types=["WasteContainer",
"WeatherStation",
for context_entity in cb_client.get_entity_list(entity_types=["WeatherStation",
"SubWeatherStation"]):
print(context_entity.model_dump_json(indent=4))
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""
# # Exercise 8: MultiEntity and Expression Language
# The MultiEntity plugin Allows the devices provisioned in the IoTAgent to map their
attributes to more than one entity, # declaring the target entity through the
# The MultiEntity plugin allows the devices provisioned in the IoTAgent to map their
attributes to more than one entity, declaring the target entity through the
Configuration or Device provisioning APIs.
# The IoTAgent Library provides an expression language for measurement transformation,
Expand Down Expand Up @@ -73,8 +73,9 @@

# TODO: Create a device with two attributes 'location' and 'fillingLevel' that use
# expressions. These attributes are based on the attributes 'longitude',
# 'latitude' and 'level'. 'location' is an array with 'longitude' and 'latitude'.
# 'fillingLevel' is 'level' divided by 100
# 'latitude' and 'level', while:
# 1. 'location' is an array with 'longitude' and 'latitude'.
# 2. 'fillingLevel' is 'level' divided by 100
device1 = Device(device_id="waste_container_001",
entity_name="urn:ngsi-ld:WasteContainer:001",
entity_type="WasteContainer",
Expand All @@ -91,10 +92,10 @@
)
iota_client.post_device(device=device1)

# TODO: Setting expression language to JEXL at Device level with other attributes.
# The attribute 'value' (Number) is itself multiplied by 5. The attribute
# 'consumption' (Text) is the trimmed version of the attribute 'spaces' (Text).
# The attribute 'iso_time' (Text) is the current 'timestamp' (Number) transformed into the ISO format.
# TODO: Setting expression language to JEXL at Device level with five attributes, while
# 1. The attribute 'value' (Number) is itself multiplied by 5. The attribute
# 2. 'consumption' (Text) is the trimmed version of the attribute 'spaces' (Text).
# 3. The attribute 'iso_time' (Text) is the current 'timestamp' (Number) transformed into the ISO format.
device2 = Device(device_id="waste_container_002",
entity_name="urn:ngsi-ld:WasteContainer:002",
entity_type="WasteContainer",
Expand Down Expand Up @@ -129,7 +130,11 @@

client.disconnect()

# Creating SubWeatherStation entities
# Printing context entities of OCB
for context_entity in cb_client.get_entity_list(entity_types=["WasteContainer"]):
print(context_entity.model_dump_json(indent=4))

# Creating two SubWeatherStation entities
entity1 = ContextEntity(id="urn:ngsi-ld:SubWeatherStation:001",
type="SubWeatherStation")
entity1.add_attributes(attrs=[NamedContextAttribute(name="vol", type="Number")])
Expand All @@ -140,10 +145,11 @@
entity2.add_attributes(attrs=[NamedContextAttribute(name="vol", type="Number")])
cb_client.post_entity(entity2)

# TODO: Create a weather station device with multi entity attributes (Number). 'v'
# is multiplied by 100 and is a standard attribute. 'v1' and 'v2' are multiplied
# by 100 and are multi entity attributes of type SubWeatherStation. The name of
# each attribute is 'vol'.
# TODO: Create a weather station device with multi entity attributes (Number).
# 'v' is multiplied by 100 and is a standard attribute.
# 'v1' and 'v2' are multiplied by 100 and should be linked with entities of
# the SubWeatherStation.
# The name of each attribute is 'vol'.
device3 = Device(device_id="weather_station_001",
entity_name="urn:ngsi-ld:WeatherStation:001",
entity_type="WeatherStation",
Expand Down Expand Up @@ -178,7 +184,6 @@
time.sleep(2)

# Printing context entities of OCB
for context_entity in cb_client.get_entity_list(entity_types=["WasteContainer",
"WeatherStation",
for context_entity in cb_client.get_entity_list(entity_types=["WeatherStation",
"SubWeatherStation"]):
print(context_entity.model_dump_json(indent=4))

0 comments on commit a6e1e91

Please sign in to comment.