-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47a3903
commit ef4b20d
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
Pattern/code/code_for_using_dataModel.WaterDistributionManagementEPANET_Pattern.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
# # This code allows you to install a orion-ld broker in a linux system | ||
# # The manuals are here https://github.com/FIWARE/context.Orion-LD/tree/develop/doc/manuals-ld | ||
# | ||
# # INSTALL NGSI LD broker (OrionLD) | ||
# sudo docker pull mongo:3.6 | ||
# sudo docker pull fiware/orion-ld | ||
# sudo docker network create fiware_default | ||
# sudo docker run -d --name=mongo-db --network=fiware_default --expose=27017 mongo:3.6 --bind_ip_all --smallfiles | ||
# sudo docker run -d --name fiware-orionld -h orion --network=fiware_default -p 1026:1026 fiware/orion-ld -dbhost mongo-db | ||
# | ||
# # TO RELAUNCH (only if you have already installed a broker in the same machine) | ||
# sudo docker stop fiware-orionld | ||
# sudo docker rm fiware-orionld | ||
# sudo docker stop mongo-db | ||
# sudo docker rm mongo-db | ||
# sudo docker network rm fiware_default | ||
# | ||
# # CHECK INSTANCES | ||
# # Check the broker is running | ||
# curl -X GET 'http://localhost:1026/version' | ||
# | ||
# # Check what entities are in the broker | ||
# curl -X GET http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000 | ||
# | ||
# # now the python code you can use to insert some value in the context broker according to the data model | ||
# # Version Warning! | ||
# # This code is designed to work with the version 0.8 of pysmartdatamodels or later | ||
# # to work with earlier version you need to replace the import instruction for | ||
# # from pysmartdatamodels import pysmartdatamodels as sdm | ||
# | ||
# | ||
import pysmartdatamodels as sdm | ||
import subprocess | ||
serverUrl = "http://localhost:1026" # supposed that your broker is installed in localhost. Edit to match your configuration | ||
dataModel = "Pattern" | ||
subject = "dataModel.WaterDistributionManagementEPANET" | ||
multipliers = [0.5692, 0.4647, 0.4385, 0.3604, 0.3098, 0.3345] | ||
attribute = "multipliers" | ||
value = multipliers | ||
# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it | ||
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) | ||
|
||
startTime = "2020-02-20T17:43:00Z" | ||
attribute = "startTime" | ||
value = startTime | ||
# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it | ||
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) | ||
|
||
tag = "DMA1" | ||
attribute = "tag" | ||
value = tag | ||
# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it | ||
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) | ||
|
||
timeStep = 3600 | ||
attribute = "timeStep" | ||
value = timeStep | ||
# The next line creates the query for inserting this attribute in a NGSI-LD context broker if the attribute does not exist it creates it | ||
print(sdm.update_broker(dataModel, subject, attribute, value, serverUrl=serverUrl, updateThenCreate=True)) | ||
|
||
print(" In case you have installed the orion-ld broker (see comments on the header of this program)") | ||
print(" Execute this instruction to check that the entities has been inserted") | ||
command = ['curl', '-X', 'GET', 'http://localhost:1026/ngsi-ld/v1/entities?local=true&limit=1000'] | ||
result = subprocess.run(command, capture_output=True, text=True) | ||
print(result.stdout) |