Skip to content
Snippets Groups Projects
Commit 595930b8 authored by Matthias Stefan Bodenbenner's avatar Matthias Stefan Bodenbenner
Browse files

- increased logging verbosity of streaming class

  - fixed streaming of semantic measurements
parent 61655cca
Branches
No related tags found
No related merge requests found
Pipeline #377225 passed
[![Build](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/lava/unified-device-interface/python/badges/master/pipeline.svg)](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/lava/unified-device-interface/python/commits/master) [![Build](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/lava/unified-device-interface/python/badges/master/pipeline.svg)](https://git-ce.rwth-aachen.de/wzl-mq-ms/forschung-lehre/lava/unified-device-interface/python/commits/master)
# Python Unified Device Interface # Python Unified Device Interface
Current stable version: 10.0.3 Current stable version: 10.0.4
## Installation ## Installation
1. Install the WZL-UDI package via pip 1. Install the WZL-UDI package via pip
...@@ -69,6 +69,10 @@ Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) ...@@ -69,6 +69,10 @@ Funded by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation)
## Recent changes ## Recent changes
**10.0.4** - 2024-03-21
- increased logging verbosity of streaming class
- fixed streaming of semantic measurements
**10.0.3** - 2024-03-21 **10.0.3** - 2024-03-21
- added license field to semantic provision of measurement range - added license field to semantic provision of measurement range
......
aiohttp==3.8.4 aiohttp==3.9.1
Deprecated==1.2.13 Deprecated==1.2.13
nest-asyncio==1.5.6 nest-asyncio==1.5.6
pytest==7.1.1 pytest==7.1.1
rdflib==7.0.0 rdflib==7.0.0
pytz==2024.1
sphinx==3.5.2 sphinx==3.5.2
sphinx-rtd-theme==1.0.0 sphinx-rtd-theme==1.0.0
wzl-mqtt~=2.6.1 wzl-mqtt~=2.6.1
\ No newline at end of file
...@@ -4,7 +4,7 @@ with open("README.md", "r", encoding="utf-8") as fh: ...@@ -4,7 +4,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read() long_description = fh.read()
setup(name='wzl-udi', setup(name='wzl-udi',
version='10.0.3', version='10.0.4',
url='https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python', url='https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python',
project_urls={ project_urls={
"Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python/-/issues", "Bug Tracker": "https://git-ce.rwth-aachen.de/wzl-mq-public/soil/python/-/issues",
......
...@@ -259,7 +259,6 @@ class Measurement(Variable): ...@@ -259,7 +259,6 @@ class Measurement(Variable):
data_graph.bind(Semantics.prefix, Semantics.namespace) data_graph.bind(Semantics.prefix, Semantics.namespace)
uncertainty_subject = Semantics.namespace[f'{self._semantic_name}MeasurementUncertainty'] uncertainty_subject = Semantics.namespace[f'{self._semantic_name}MeasurementUncertainty']
covariance = self.__getitem__('covariance', 0) covariance = self.__getitem__('covariance', 0)
print(covariance)
if covariance is not None: if covariance is not None:
rdf_covariance = self.serialize_value(data_graph, covariance) rdf_covariance = self.serialize_value(data_graph, covariance)
data_graph.add((uncertainty_subject, Namespaces.rdf.type, Namespaces.si.CoverageInterval)) data_graph.add((uncertainty_subject, Namespaces.rdf.type, Namespaces.si.CoverageInterval))
......
import datetime import datetime
import json import json
import traceback
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import List, Callable, Any, Union, Dict, Tuple from typing import List, Callable, Any, Union, Dict, Tuple
...@@ -20,8 +21,15 @@ logger = root_logger.get(__name__) ...@@ -20,8 +21,15 @@ logger = root_logger.get(__name__)
class JobError(Exception): class JobError(Exception):
def __init__(self): def __init__(self, message: str, predeccessor: Exception = None):
pass self._predecessor: predeccessor
self._message = message
@property
def message(self) -> str:
return self._message
class Job(ABC): class Job(ABC):
...@@ -73,7 +81,7 @@ class Job(ABC): ...@@ -73,7 +81,7 @@ class Job(ABC):
time = time if time is not None else datetime.datetime.now() time = time if time is not None else datetime.datetime.now()
return self._next is not None and self._next <= time and self._is_triggered() return self._next is not None and self._next <= time and self._is_triggered()
except Exception as e: except Exception as e:
raise JobError() raise JobError('is_triggered failed', predeccessor=e)
@abstractmethod @abstractmethod
def _is_triggered(self) -> bool: def _is_triggered(self) -> bool:
...@@ -97,7 +105,7 @@ class Job(ABC): ...@@ -97,7 +105,7 @@ class Job(ABC):
def data(self, model: Component = None) -> Dict: def data(self, model: Component = None) -> Dict:
if model is None: if model is None:
raise JobError() raise JobError('Can not retrieve data. Model is missing')
try: try:
uuids = self.topic.split('/') uuids = self.topic.split('/')
data = model.__getitem__(uuids).serialize([], False) data = model.__getitem__(uuids).serialize([], False)
...@@ -109,11 +117,11 @@ class Job(ABC): ...@@ -109,11 +117,11 @@ class Job(ABC):
data['timestamp'] = variable.serialize_time(datetime.datetime.now()) data['timestamp'] = variable.serialize_time(datetime.datetime.now())
return data return data
except Exception as e: except Exception as e:
raise JobError() raise JobError('Can not retrieve data. Due to another error.', predeccessor=e)
def semantic_data(self, model: Component = None) -> (str, rdflib.Graph): def semantic_data(self, model: Component = None) -> (str, rdflib.Graph):
if model is None: if model is None:
raise JobError() raise JobError('Can not retrieve semantic data. Model is missing')
try: try:
uuids = self.topic.split('/') uuids = self.topic.split('/')
element = model.__getitem__(uuids) element = model.__getitem__(uuids)
...@@ -122,7 +130,7 @@ class Job(ABC): ...@@ -122,7 +130,7 @@ class Job(ABC):
data += element.serialize_semantics(ResourceType.observation) data += element.serialize_semantics(ResourceType.observation)
measurement_subject = \ measurement_subject = \
list((data.subjects(predicate=Namespaces.rdf.type, object=Namespaces.soil.Measurement)))[0] list((data.subjects(predicate=Namespaces.rdf.type, object=Namespaces.sosa.Observation)))[0]
# replace value # replace value
data.remove((None, Namespaces.qudt.value, None)) data.remove((None, Namespaces.qudt.value, None))
...@@ -135,7 +143,7 @@ class Job(ABC): ...@@ -135,7 +143,7 @@ class Job(ABC):
return element.semantic_name, data return element.semantic_name, data
except Exception as e: except Exception as e:
raise JobError() raise JobError('Can not semantic retrieve data. Due to another error.', predeccessor=e)
class FixedJob(Job): class FixedJob(Job):
...@@ -291,6 +299,8 @@ class StreamScheduler(object): ...@@ -291,6 +299,8 @@ class StreamScheduler(object):
try: try:
self._publisher.get('tier1').publish(job.topic, message, 1) self._publisher.get('tier1').publish(job.topic, message, 1)
except ClientNotFoundError: except ClientNotFoundError:
logger.warn('Client not found error occured.')
logger.warn(traceback.format_exc())
self._publisher.publish(job.topic, message, 1) self._publisher.publish(job.topic, message, 1)
# try to send semantic data package # try to send semantic data package
...@@ -305,16 +315,19 @@ class StreamScheduler(object): ...@@ -305,16 +315,19 @@ class StreamScheduler(object):
try: try:
self._publisher.get('tier2').publish(url, message, 1) self._publisher.get('tier2').publish(url, message, 1)
except ClientNotFoundError: except ClientNotFoundError:
logger.warn('Client not found error occured.')
logger.warn(traceback.format_exc())
self._publisher.publish(url, message, 1) self._publisher.publish(url, message, 1)
except JobError: except JobError as e:
pass logger.error(e.message)
logger.error(traceback.format_exc())
job.schedule() job.schedule()
next = job.determine_next(next) next = job.determine_next(next)
except JobError: except JobError as e:
# logger.error(traceback.format_exc()) logger.error(e.message)
# job.stop() logger.error(traceback.format_exc())
pass pass
if next is None: if next is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment