First version of explain. Creating a new parser was a wrong approach. Need to reimplement
This commit is contained in:
@@ -3,6 +3,7 @@ import time
|
||||
|
||||
from core.builtin_concepts import BuiltinConcepts
|
||||
from core.concept import Concept
|
||||
from core.sheerka.Services.SheerkaExecute import NO_MATCH
|
||||
from core.sheerka_logger import get_logger
|
||||
from sdp.sheerkaDataProvider import Event
|
||||
|
||||
@@ -261,6 +262,74 @@ class ExecutionContext:
|
||||
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _is_return_value(obj):
|
||||
return isinstance(obj, Concept) and obj.key == str(BuiltinConcepts.RETURN_VALUE)
|
||||
|
||||
def _at_least_one_success(self, return_values):
|
||||
status = False
|
||||
for ret_val in return_values:
|
||||
if not self._is_return_value(ret_val):
|
||||
return None
|
||||
status |= ret_val.status
|
||||
return status
|
||||
|
||||
def _all_success(self, return_values):
|
||||
status = True
|
||||
for ret_val in return_values:
|
||||
if not self._is_return_value(ret_val):
|
||||
return None
|
||||
status &= ret_val.status
|
||||
return status
|
||||
|
||||
def get_status(self):
|
||||
# In the function, I cannot use sheerka.isinstance() as self.sheerka may not be initialized
|
||||
# This is the case when ExecutionContext is deserialized
|
||||
|
||||
if "return_values" not in self.values:
|
||||
return None
|
||||
|
||||
if hasattr(self.values["return_values"], "__iter__"):
|
||||
values = self.values["return_values"]
|
||||
if len(values) == 0:
|
||||
return None
|
||||
|
||||
if isinstance(values, str):
|
||||
return "No Match" if values == NO_MATCH else values
|
||||
|
||||
if isinstance(values[0], dict):
|
||||
for result in values:
|
||||
if "return_value" not in result:
|
||||
return None
|
||||
if self._is_return_value(result["return_value"]):
|
||||
return result["return_value"].status
|
||||
return "No Match"
|
||||
else:
|
||||
return self._at_least_one_success(self.values["return_values"])
|
||||
|
||||
else:
|
||||
ret_val = self.values["return_values"]
|
||||
if not isinstance(ret_val, Concept) or not ret_val.key == str(BuiltinConcepts.RETURN_VALUE):
|
||||
return None
|
||||
return ret_val.status
|
||||
|
||||
def to_bag(self):
|
||||
"""
|
||||
Creates a dictionary with the useful properties of the concept
|
||||
It quicker to implement than creating the actual property mechanism with @property
|
||||
And it removes the visibility from the other attributes/methods
|
||||
"""
|
||||
bag = {}
|
||||
for k, v in self._bag.items():
|
||||
bag[k] = v
|
||||
bag["bag." + k] = v
|
||||
for prop in ("id", "who", "desc", "obj", "inputs", "values", "concepts"):
|
||||
bag[prop] = getattr(self, prop)
|
||||
bag["status"] = self.get_status()
|
||||
bag["elapsed"] = self.elapsed
|
||||
bag["digest"] = self.event.get_digest() if self.event else None
|
||||
return bag
|
||||
|
||||
@staticmethod
|
||||
def return_value_to_str(r):
|
||||
value = str(r.value)
|
||||
|
||||
Reference in New Issue
Block a user