Skip to content
Snippets Groups Projects
Commit 1249c24f authored by Jiahang Chen's avatar Jiahang Chen
Browse files

Merge branch 'parenting' into 'master'

Add parent relationship between thing and features

See merge request !23
parents d14788e8 c930e5ac
Branches
Tags
1 merge request!23Add parent relationship between thing and features
Pipeline #607488 passed
Showing
with 112 additions and 56 deletions
......@@ -226,6 +226,7 @@ def build_sub_features(feature_ins, feature):
build_sub_features(sub_f_instance, sub_f)
else:
setattr(sub_f_instance, key, sub_f[key])
sub_f_instance.parent = feature_ins
feature_ins.subFeatures[sub_f_name] = sub_f_instance
......@@ -244,6 +245,7 @@ def build_sub_thing(feature_ins, feature):
sub_thing_ref = create_thing(model_json={"attributes": json_sub_thing})
sub_thing_name = json_sub_thing.get("name", None)
feature_ins.targets[sub_thing_name] = sub_thing_ref
sub_thing_ref.parent = feature_ins
def build(thing, model):
......@@ -266,11 +268,13 @@ def build(thing, model):
roles = attributes.get("roles", [])
for role in roles:
role_instance = build_role(role)
role_instance.parent = thing
thing.roles[role.get("class")] = role_instance
json_features = attributes.get("features", [])
for feature in json_features:
feature_ins = build_feature(feature=feature)
feature_ins.parent = thing
thing.features[feature.get("class")] = feature_ins
if ditto_features is not None:
......@@ -438,7 +442,8 @@ def _create_thing(model, grant_type="password",
attributes = model.get("attributes", None)
if attributes is None:
sys.exit("attributes are none")
thing_type = remove_namespace(attributes.get("class", ""))
thing_type = attributes.get("class", "")
thing_type = remove_namespace(thing_type)
thing_name = attributes.get("name", "")
APP_LOGGER.info("Build digital twin {} with id {}".format(thing_name, model.get("thingId", "")))
......
......@@ -7,19 +7,21 @@
from abc import ABC
from ml.identifier import ID
from ml.thing import Thing
class Feature(ABC):
"""The Feature class represents the base class for all functionalities
and values."""
def __init__(self, namespace, name="", identifier=""):
def __init__(self, namespace, name="", identifier="", parent=None):
"""Constructs a new Feature class object with the given name and
identifier.
:param name: Name of the feature
:param identifier: Identifier of the feature
"""
self.parent = parent
self.namespace = namespace
self.__name = name
self.__class_name = f"{self.namespace}::{self.__class__.__name__}"
......@@ -143,3 +145,13 @@ def to_json(self):
res = self.subFeatures[key].to_json()
self.__json_out["subFeatures"].append(res)
return self.__json_out
def get_my_thing(self):
tmp = self.parent
print("Searching for thing....")
print(type(tmp))
while not isinstance(tmp, Thing):
if tmp is None:
return None
tmp = tmp.parent
return tmp
"""This module implements the class AcceptsFellingJobs."""
from ml.fml40.features.properties.values.documents.jobs.felling_job import \
FellingJob
from ml.fml40.features.properties.values.documents.jobs.felling_job import FellingJob
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs
from ml.ml40.features.properties.values.documents.jobs.job_status import \
JobStatus
from ml.ml40.features.properties.values.documents.jobs.job_status import JobStatus
class AcceptsFellingJobs(AcceptsJobs):
"""This functionality signalizes that FellingJobs can be processed and
offers the possibility to remove and query it."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def acceptJob(self, job: FellingJob) -> bool:
"""Accepts the given FellingJob job. Returns true if the job has been
......
"""This module implements the class AcceptsFellingSupportJobs."""
from ml.fml40.features.properties.values.documents.jobs.fellung_support_job import \
FellingSupportJob
from ml.fml40.features.properties.values.documents.jobs.fellung_support_job import (
FellingSupportJob,
)
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs
......@@ -9,14 +10,16 @@ class AcceptsFellingSupportJobs(AcceptsJobs):
"""This functionality signalizes that FellingSupportJobs can be
processed."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def acceptJob(self, job: FellingSupportJob) -> bool:
"""Accepts the given FellingSupportJob job. Returns true if the job
......
"""This module implements the class AcceptsForwardingJobs."""
from ml.app_logger import APP_LOGGER
from ml.fml40.features.properties.values.documents.jobs.forwarding_job import \
ForwardingJob
from ml.fml40.features.properties.values.documents.jobs.forwarding_job import (
ForwardingJob,
)
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs
class AcceptsForwardingJobs(AcceptsJobs):
"""This functionality signalizes that ForwadingJobs can be processed."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def acceptJob(self, job: ForwardingJob) -> bool:
"""Accepts the given ForwardingJob. Returns true if the job has been
......
"""This module implements the class AcceptsLogMeasurements."""
from ml.fml40.features.properties.values.documents.reports.log_measurement import \
LogMeasurement
from ml.fml40.features.properties.values.documents.reports.log_measurement import (
LogMeasurement,
)
from ml.ml40.features.functionalities.functionality import Functionality
class AcceptsLogMeasurements(Functionality):
"""This functionality signalizes that LogMeasurements can be processed."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def acceptLogMeasurement(self, log_measurement: LogMeasurement) -> bool:
"""Accepts the given LogMeasurement. Returns true if the job has been
......
"""This module implements the class AcceptsLogTransportationJobs."""
from ml.fml40.features.properties.values.documents.jobs.log_transportation_job import \
LogTransportationJob
from ml.fml40.features.properties.values.documents.jobs.log_transportation_job import (
LogTransportationJob,
)
from ml.ml40.features.functionalities.accepts_jobs import AcceptsJobs
......@@ -9,14 +10,16 @@ class AcceptsLogTransportationJobs(AcceptsJobs):
"""This functionality signalizes that LogTransportationJobs can be
processed."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def acceptJob(self, job: LogTransportationJob) -> bool:
"""Accepts the given LogTransportationJob. Returns true if the job has
......
"""This module implements the class AcceptsMoistureMeasurement."""
from ml.fml40.features.properties.values.documents.reports.soil_moisture_measurement import \
SoilMoistureMeasurement
from ml.fml40.features.properties.values.documents.reports.soil_moisture_measurement import (
SoilMoistureMeasurement,
)
from ml.ml40.features.functionalities.functionality import Functionality
......@@ -9,14 +10,16 @@ class AcceptsMoistureMeasurement(Functionality):
"""This functionality signalizes that SoilMoistureMeasurements can be
processed."""
def __init__(self,namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def acceptMoistureMeasurement(self, input: SoilMoistureMeasurement):
"""Accepts the given SoilMoistureMeasurement."""
......
......@@ -7,14 +7,16 @@ class AcceptsMoveCommands(Functionality):
"""This functionality signalizes that the thing can be moved remotely
via S3I-B messages ."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def move(self, longitude: float, latitude: float):
"""Moves the thing to the position specified longitude and latitude.
......
from ml.fml40.features.properties.values.documents.reports.passability_report import \
PassabilityReport
from ml.fml40.features.properties.values.documents.reports.passability_report import (
PassabilityReport,
)
from ml.ml40.features.functionalities.functionality import Functionality
class AcceptsPassabilityReport(Functionality):
def __init__(self, namespace="fml40", name="", identifier=""):
super().__init__(namespace=namespace, name=name, identifier=identifier)
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def acceptsReport(self, report: PassabilityReport):
pass
......@@ -7,14 +7,16 @@ class AcceptsProximityAlert(Functionality):
"""This functionality signalizes that an alert is generated if things
are to close to this thing."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def proximityAlert(self, ids: list, distances: list):
print("Making Proximity Alert...")
......@@ -5,14 +5,16 @@ class AcceptsShieldCommands(Functionality):
"""This functionality signalizes that the thing's shield can be moved remotely
via S3I-B messages ."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def shieldDown(self, speed):
"""roll down the winch with specified speed
......
......@@ -6,11 +6,13 @@
class AcceptsSingleTreeFellingJobs(AcceptsJobs):
"""This functionality signalizes that single trees can be felled."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
......@@ -5,14 +5,16 @@ class AcceptsWinchCommands(Functionality):
"""This functionality signalizes that the thing's winch can be moved remotely
via S3I-B messages ."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def rollDown(self, speed):
"""roll down the winch with specified speed
......
......@@ -6,14 +6,16 @@
class ClassifiesTreeSpecies(Functionality):
"""This functionality allows the classification of tree species."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def calculateTreeSpeciesClassification(self, tree: bytes) -> bytes:
"""Returns the classification of the species of tree.
......
......@@ -2,5 +2,7 @@
class ConvertsDataFormats(Functionality):
def __init__(self, namespace="fml40", name="", identifier=""):
super().__init__(namespace=namespace, name=name, identifier=identifier)
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
from ml.fml40.features.functionalities.converts_data_formats import \
ConvertsDataFormats
from ml.fml40.features.functionalities.converts_data_formats import ConvertsDataFormats
class ConvertsForestGML(ConvertsDataFormats):
def __init__(self, namespace="fml40", name="", identifier=""):
super().__init__(namespace=namespace, name=name, identifier=identifier)
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
......@@ -4,14 +4,16 @@
class Cuts(Functionality):
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def cut(self):
pass
......@@ -9,14 +9,16 @@ class DeterminesPassability(Functionality):
"""This functionality signalizes that the passability can be
calculated."""
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def isPassableNow(self, input: float) -> bool:
"""Returns true if this object can be passed with the given weight
......
......@@ -4,14 +4,16 @@
class DisplaysHealthAlarms(Functionality):
def __init__(self, namespace="fml40", name="", identifier=""):
def __init__(self, namespace="fml40", name="", identifier="", parent=None):
"""Initializes the object.
:param name: Object name
:param identifier: Identifier
"""
super().__init__(namespace=namespace, name=name, identifier=identifier)
super().__init__(
namespace=namespace, name=name, identifier=identifier, parent=parent
)
def displayHealthAlarm(self):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment