Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
naiades
naiades-platform-poc
Commits
16211803
Commit
16211803
authored
Sep 09, 2020
by
Federico Sismondi
Browse files
Update() in data model for entities of DCA components
parent
36881f4f
Changes
2
Hide whitespace changes
Inline
Side-by-side
dca-carouge-watering/app.py
View file @
16211803
...
...
@@ -193,7 +193,7 @@ def _forward_reading_to_ctx_broker():
url
=
"{}/v2/entities/{}/attrs"
.
format
(
URL_BASE
,
entity_id
)
payload
=
{
'soilMoisture'
:
{
'value'
:
sensor_reading
},
'dateObserved'
:
{
'type'
:
'DateTime'
,
'value'
:
timestamp
},
#
'dateObserved': {'type': 'DateTime', 'value': timestamp},
}
r
=
client_request
.
patch
(
...
...
@@ -232,8 +232,6 @@ def _dump_raw_data_to_filesystem():
def
_dummy_post_handler
():
if
request
.
data
:
app
.
logger
.
info
(
"Request data: %s"
%
request
.
data
)
if
request
.
json
:
app
.
logger
.
info
(
"Request json: %s"
%
request
.
json
)
if
request
.
form
:
app
.
logger
.
info
(
"Request form: %s"
%
request
.
form
)
...
...
scripts-admin/create_entities.py
View file @
16211803
...
...
@@ -22,6 +22,7 @@ logger = logging.getLogger()
URL_BASE
=
'http://{}:1026'
.
format
(
os
.
getenv
(
'ORION_HOST'
))
def
get_ngsiv2_typed_description
(
val
):
if
isinstance
(
val
,
Point
):
return
{
'type'
:
'geo:json'
,
'value'
:
dict
(
val
)}
...
...
@@ -41,47 +42,40 @@ def get_ngsiv2_typed_description(val):
# Data model templates, they describe those MUST-HAVE attributes, extra attributes can be added later on using the API
extra_args
=
{
'WeatherObserved'
:
{
'dateObserved'
:
datetime
.
utcnow
(),
# mandatory
'location'
:
Point
([
0
,
0
]),
# mandatory
'source'
:
''
,
'illuminance'
:
0
,
'temperature'
:
0.0
,
'precipitation'
:
0
,
'atmosphericPressure'
:
0.0
,
'windSpeed'
:
0
,
'pressureTendency'
:
0.0
,
'relativeHumidity'
:
0
,
},
'WeatherForecast'
:
{
'dateIssued'
:
datetime
.
utcnow
(),
# mandatory
'location'
:
Point
([
0
,
0
]),
# mandatory
'dayMinimum'
:
{
'feelsLikeTemperature'
:
0
,
'temperature'
:
0
,
'relativeHumidity'
:
0.0
},
'dayMaximum'
:
{
'feelsLikeTemperature'
:
0
,
'temperature'
:
0
,
'relativeHumidity'
:
0.0
},
'precipitationProbability'
:
0.0
,
'windSpeed'
:
0
,
'validFrom'
:
datetime
.
fromtimestamp
(
0
),
'validTo'
:
datetime
.
fromtimestamp
(
0
),
},
'WeatherObserved'
:
{
'dateObserved'
:
datetime
.
utcnow
(),
# mandatory
'location'
:
Point
([
0
,
0
]),
# mandatory
'source'
:
''
,
'illuminance'
:
0
,
'temperature'
:
0.0
,
'precipitation'
:
0
,
'atmosphericPressure'
:
0.0
,
'windSpeed'
:
0
,
'pressureTendency'
:
0.0
,
'relativeHumidity'
:
0
,
},
'WeatherForecast'
:
{
'dateIssued'
:
datetime
.
utcnow
(),
# mandatory
'location'
:
Point
([
0
,
0
]),
# mandatory
'dayMinimum'
:
{
'feelsLikeTemperature'
:
0
,
'temperature'
:
0
,
'relativeHumidity'
:
0.0
},
'dayMaximum'
:
{
'feelsLikeTemperature'
:
0
,
'temperature'
:
0
,
'relativeHumidity'
:
0.0
},
'precipitationProbability'
:
0.0
,
'windSpeed'
:
0
,
'validFrom'
:
datetime
.
fromtimestamp
(
0
),
'validTo'
:
datetime
.
fromtimestamp
(
0
),
},
'FlowerBed'
:
{
'location'
:
Point
([
0
,
0
]),
# mandatory
'soilMoisture'
:
0.0
,
'moistureDeviceEui'
:
None
,
'boxOperatorComment'
:
''
,
'soilType'
:
None
,
'location'
:
Point
([
0
,
0
]),
# mandatory
'flowerType'
:
None
,
'sunExposure'
:
None
,
'windExposure'
:
None
,
'boxId'
:
None
,
'boxSize'
:
None
,
'dateLastWatering'
:
datetime
.
fromtimestamp
(
0
),
'nextWateringDeadline'
:
datetime
.
fromtimestamp
(
0
),
'nextWateringAmountRecommendation'
:
datetime
.
fromtimestamp
(
0
),
'installationDate'
:
datetime
.
fromtimestamp
(
0
),
'soilMoisture'
:
0.0
,
'moistureDeviceEui'
:
None
,
'boxId'
:
None
,
'boxSize'
:
None
,
'boxOperatorComment'
:
''
,
}
}
...
...
@@ -140,7 +134,8 @@ for urn, pilots in entities:
try
:
entities_map
[
pilot
].
append
({
'id'
:
urn
,
'type'
:
data_type
,
**
{
attr_n
:
get_ngsiv2_typed_description
(
attr_v
)
for
attr_n
,
attr_v
in
extra_args
[
data_type
].
items
()}
**
{
attr_n
:
get_ngsiv2_typed_description
(
attr_v
)
for
attr_n
,
attr_v
in
extra_args
[
data_type
].
items
()}
})
except
KeyError
:
raise
KeyError
(
'Unrecognized pilot {}'
.
format
(
pilot
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment