summaryrefslogtreecommitdiff
path: root/lib/automata.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/automata.py')
-rwxr-xr-xlib/automata.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/automata.py b/lib/automata.py
index 2387734..6d90e4c 100755
--- a/lib/automata.py
+++ b/lib/automata.py
@@ -4,6 +4,7 @@ from functions import AnalyticFunction, NormalizationFunction
from utils import is_numeric
import itertools
import numpy as np
+import json, yaml
def _dict_to_list(input_dict: dict) -> list:
return [input_dict[x] for x in sorted(input_dict.keys())]
@@ -100,6 +101,8 @@ class State:
:returns: Generator object for depth-first search. Each access yields a list of (Transition, (arguments)) elements describing a single run through the PTA.
"""
+ # TODO parametergewahrer Trace-Filter, z.B. "setHeaterDuration nur wenn bme680 power mode => FORCED und GAS_ENABLED"
+
# A '$' entry in trace_filter indicates that the trace should (successfully) terminate here regardless of `depth`.
if trace_filter is not None and next(filter(lambda x: x == '$', map(lambda x: x[0], trace_filter)), None) is not None:
yield []
@@ -403,6 +406,15 @@ class PTA:
return normalized_param
@classmethod
+ def from_file(cls, model_file: str):
+ """Return PTA loaded from the provided JSON or YAML file."""
+ with open(model_file, 'r') as f:
+ if '.json' in model_file:
+ return cls.from_json(json.load(f))
+ else:
+ return cls.from_yaml(yaml.safe_load(f))
+
+ @classmethod
def from_json(cls, json_input: dict):
"""
Return a PTA created from the provided JSON data.