You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by bo...@apache.org on 2022/12/28 14:08:36 UTC

[streampipes] 03/03: introduce `BaseElement` for a cleaner class hierarchy

This is an automated email from the ASF dual-hosted git repository.

bossenti pushed a commit to branch chore/refactor-class-hierarchy-python-client
in repository https://gitbox.apache.org/repos/asf/streampipes.git

commit fdfd9ded5a6619518726bf7a04205b110241ff8e
Author: bossenti <bo...@posteo.de>
AuthorDate: Wed Dec 28 15:08:17 2022 +0100

    introduce `BaseElement` for a cleaner class hierarchy
    
    Signed-off-by: bossenti <bo...@posteo.de>
---
 .../endpoint/data_lake_measure.py                  |  2 +-
 .../streampipes_client/model/common.py             | 37 ++++++++++++----------
 .../model/container/data_streams.py                |  2 +-
 .../streampipes_client/model/resource/__init__.py  |  2 ++
 .../model/resource/data_lake_series.py             |  4 +++
 .../model/resource/data_stream.py                  |  6 ++++
 .../streampipes_client/model/resource/resource.py  |  4 +--
 7 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/streampipes-client-python/streampipes_client/endpoint/data_lake_measure.py b/streampipes-client-python/streampipes_client/endpoint/data_lake_measure.py
index e2effde8d..d9f37dd0b 100644
--- a/streampipes-client-python/streampipes_client/endpoint/data_lake_measure.py
+++ b/streampipes-client-python/streampipes_client/endpoint/data_lake_measure.py
@@ -24,7 +24,7 @@ from typing import Tuple, Type
 from streampipes_client.endpoint.endpoint import APIEndpoint
 from streampipes_client.model.container import DataLakeMeasures
 from streampipes_client.model.container.resource_container import ResourceContainer
-from streampipes_client.model.resource.data_lake_series import DataLakeSeries
+from streampipes_client.model.resource import DataLakeSeries
 
 __all__ = [
     "DataLakeMeasureEndpoint",
diff --git a/streampipes-client-python/streampipes_client/model/common.py b/streampipes-client-python/streampipes_client/model/common.py
index 36813b97b..83f1b00dd 100644
--- a/streampipes-client-python/streampipes_client/model/common.py
+++ b/streampipes-client-python/streampipes_client/model/common.py
@@ -24,6 +24,7 @@ from typing import List, Optional
 from pydantic import BaseModel, Field, StrictBool, StrictInt, StrictStr
 
 __all__ = [
+    "BaseElement",
     "BasicModel",
     "EventSchema",
 ]
@@ -40,8 +41,6 @@ def _snake_to_camel_case(snake_case_string: str) -> str:
 class BasicModel(BaseModel):
     """Basic model class used for the whole Python StreamPipes data model."""
 
-    element_id: Optional[StrictStr]
-
     class Config:
         """Configuration class for Pydantic.
         Defines alias generator to convert field names from camelCase (API) to snake_case (Python codebase).
@@ -50,16 +49,22 @@ class BasicModel(BaseModel):
         alias_generator = _snake_to_camel_case
 
 
-class EventPropertyQualityRequirement(BasicModel):
+class BaseElement(BasicModel):
+    """Structure of a basic element in the StreamPipes backend"""
+
+    element_id: Optional[StrictStr]
+
+
+class EventPropertyQualityRequirement(BaseElement):
     """
     Data model of an `EventPropertyQualityRequirement` in compliance to the StreamPipes Backend.
     """
 
-    minimum_property_quality: Optional[BasicModel] = Field(alias="eventPropertyQualityDefinition")
-    maximum_property_quality: Optional[BasicModel] = Field(alias="eventPropertyQualityDefinition")
+    minimum_property_quality: Optional[BaseElement] = Field(alias="eventPropertyQualityDefinition")
+    maximum_property_quality: Optional[BaseElement] = Field(alias="eventPropertyQualityDefinition")
 
 
-class ValueSpecification(BasicModel):
+class ValueSpecification(BaseElement):
     """
     Data model of an `ValueSpecification` in compliance to the StreamPipes Backend.
     """
@@ -69,7 +74,7 @@ class ValueSpecification(BasicModel):
     step: Optional[float]
 
 
-class EventProperty(BasicModel):
+class EventProperty(BaseElement):
     """
     Data model of an `EventProperty` in compliance to the StreamPipes Backend.
     """
@@ -79,7 +84,7 @@ class EventProperty(BasicModel):
     runtime_name: StrictStr
     required: StrictBool
     domain_properties: List[StrictStr]
-    event_property_qualities: List[BasicModel] = Field(alias="eventPropertyQualities")
+    event_property_qualities: List[BaseElement] = Field(alias="eventPropertyQualities")
     requires_event_property_qualities: List[EventPropertyQualityRequirement]
     property_scope: Optional[StrictStr]
     index: StrictInt
@@ -89,7 +94,7 @@ class EventProperty(BasicModel):
     value_specification: Optional[ValueSpecification]
 
 
-class EventSchema(BasicModel):
+class EventSchema(BaseElement):
     """
     Data model of an `EventSchema` in compliance to the StreamPipes Backend.
     """
@@ -97,7 +102,7 @@ class EventSchema(BasicModel):
     event_properties: List[EventProperty]
 
 
-class ApplicationLink(BasicModel):
+class ApplicationLink(BaseElement):
     """
     Data model of an `ApplicationLink` in compliance to the StreamPipes Backend.
     """
@@ -109,7 +114,7 @@ class ApplicationLink(BasicModel):
     application_link_type: Optional[StrictStr]
 
 
-class TopicDefinition(BasicModel):
+class TopicDefinition(BaseElement):
     """
     Data model of a `TopicDefinition` in compliance to the StreamPipes Backend.
     """
@@ -117,7 +122,7 @@ class TopicDefinition(BasicModel):
     actual_topic_name: StrictStr
 
 
-class TransportProtocol(BasicModel):
+class TransportProtocol(BaseElement):
     """
     Data model of a `TransportProtocol` in compliance to the StreamPipes Backend.
     """
@@ -127,7 +132,7 @@ class TransportProtocol(BasicModel):
     port: StrictInt
 
 
-class TransportFormat(BasicModel):
+class TransportFormat(BaseElement):
     """
     Data model of a `TransportFormat` in compliance to the StreamPipes Backend.
     """
@@ -135,7 +140,7 @@ class TransportFormat(BasicModel):
     rdf_type: Optional[List[Optional[StrictStr]]]
 
 
-class EventGrounding(BasicModel):
+class EventGrounding(BaseElement):
     """
     Data model of an `EventGrounding` in compliance to the StreamPipes Backend.
     """
@@ -144,7 +149,7 @@ class EventGrounding(BasicModel):
     transport_formats: Optional[List[Optional[TransportFormat]]]
 
 
-class MeasurementCapability(BasicModel):
+class MeasurementCapability(BaseElement):
     """
     Data model of a `MeasurementCapability` in compliance to the StreamPipes Backend.
     """
@@ -152,7 +157,7 @@ class MeasurementCapability(BasicModel):
     capability: Optional[StrictStr]
 
 
-class MeasurementObject(BasicModel):
+class MeasurementObject(BaseElement):
     """
     Data model of a `MeasurementObject` in compliance to the StreamPipes Backend.
     """
diff --git a/streampipes-client-python/streampipes_client/model/container/data_streams.py b/streampipes-client-python/streampipes_client/model/container/data_streams.py
index 2c89209b2..ea7f5086c 100644
--- a/streampipes-client-python/streampipes_client/model/container/data_streams.py
+++ b/streampipes-client-python/streampipes_client/model/container/data_streams.py
@@ -21,8 +21,8 @@ Implementation of a resource container for the data streams endpoint.
 from typing import Type
 
 from streampipes_client.model.container.resource_container import ResourceContainer
-from streampipes_client.model.resource.resource import Resource
 from streampipes_client.model.resource.data_stream import DataStream
+from streampipes_client.model.resource.resource import Resource
 
 __all__ = [
     "DataStreams",
diff --git a/streampipes-client-python/streampipes_client/model/resource/__init__.py b/streampipes-client-python/streampipes_client/model/resource/__init__.py
index 7fae83595..3aa99e02d 100644
--- a/streampipes-client-python/streampipes_client/model/resource/__init__.py
+++ b/streampipes-client-python/streampipes_client/model/resource/__init__.py
@@ -16,9 +16,11 @@
 #
 
 from .data_lake_measure import DataLakeMeasure
+from .data_lake_series import DataLakeSeries
 from .data_stream import DataStream
 
 __all__ = [
     "DataLakeMeasure",
+    "DataLakeSeries",
     "DataStream",
 ]
diff --git a/streampipes-client-python/streampipes_client/model/resource/data_lake_series.py b/streampipes-client-python/streampipes_client/model/resource/data_lake_series.py
index e211361a8..60d4d994e 100644
--- a/streampipes-client-python/streampipes_client/model/resource/data_lake_series.py
+++ b/streampipes-client-python/streampipes_client/model/resource/data_lake_series.py
@@ -24,6 +24,10 @@ import pandas as pd
 from pydantic import StrictInt, StrictStr
 from streampipes_client.model.resource.resource import Resource
 
+__all__ = [
+    "DataLakeSeries",
+]
+
 
 class StreamPipesUnsupportedDataLakeSeries(Exception):
     """Exception to be raised when the returned data lake series
diff --git a/streampipes-client-python/streampipes_client/model/resource/data_stream.py b/streampipes-client-python/streampipes_client/model/resource/data_stream.py
index 9c50938f5..dc6f565ff 100644
--- a/streampipes-client-python/streampipes_client/model/resource/data_stream.py
+++ b/streampipes-client-python/streampipes_client/model/resource/data_stream.py
@@ -40,6 +40,12 @@ class DataStream(Resource):
     """
 
     def convert_to_pandas_representation(self):
+        """Returns the dictionary representation of a data stream to be used when creating a pandas Dataframe.
+
+        Returns
+        -------
+        Dictionary
+        """
         return {
             **self.dict(
                 exclude={
diff --git a/streampipes-client-python/streampipes_client/model/resource/resource.py b/streampipes-client-python/streampipes_client/model/resource/resource.py
index 5cb2d354d..e52a01609 100644
--- a/streampipes-client-python/streampipes_client/model/resource/resource.py
+++ b/streampipes-client-python/streampipes_client/model/resource/resource.py
@@ -22,14 +22,14 @@ A resource defines the data model that is used by a resource container (`model.c
 from abc import ABC, abstractmethod
 from typing import Dict
 
-from streampipes_client.model.common import BasicModel
+from streampipes_client.model.common import BaseElement
 
 __all__ = [
     "Resource",
 ]
 
 
-class Resource(ABC, BasicModel):
+class Resource(ABC, BaseElement):
     """General and abstract implementation for a resource.
     A resource defines the data model used by a resource container (`model.container.resourceContainer`).
     It inherits from Pydantic's BaseModel to get all its superpowers,