summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2021-04-20 11:55:22 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2021-04-20 11:55:22 +0200
commit5b43e9b07d48bb65771a66760128fc85afc1b95e (patch)
tree8cd11b1162d6ba44f3047a2e6f2281fe99a5385c /lib
parentf48482529e34cc5d9f7d11681febb57905251b47 (diff)
proper kconfig-webconf export
Diffstat (limited to 'lib')
-rw-r--r--lib/functions.py22
-rw-r--r--lib/model.py7
-rw-r--r--lib/parameters.py3
3 files changed, 32 insertions, 0 deletions
diff --git a/lib/functions.py b/lib/functions.py
index 33ecaca..81f6ab5 100644
--- a/lib/functions.py
+++ b/lib/functions.py
@@ -191,6 +191,9 @@ class ModelFunction:
return self.function_error["mae"]
return self.value_error["mae"]
+ def webconf_function_map(self):
+ return list()
+
def to_json(self):
"""Convert model to JSON."""
ret = {
@@ -300,6 +303,12 @@ class SplitFunction(ModelFunction):
param_value = param_list[self.param_index]
return self.child[param_value].eval(param_list)
+ def webconf_function_map(self):
+ ret = list()
+ for child in self.child.values():
+ ret.extend(child.webconf_function_map())
+ return ret
+
def to_json(self):
ret = super().to_json()
ret.update(
@@ -572,6 +581,19 @@ class AnalyticFunction(ModelFunction):
"""
return self._function(self.model_args, param_list)
+ def webconf_function_map(self):
+ js_buf = self.model_function
+ for i in range(len(self.model_args)):
+ js_buf = js_buf.replace(f"regression_arg({i})", str(self.model_args[i]))
+ for parameter_name in self._parameter_names:
+ js_buf = js_buf.replace(
+ f"parameter({parameter_name})", f"""param["{parameter_name}"]"""
+ )
+ for arg_num in range(self._num_args):
+ js_buf = js_buf.replace(f"function_arg({arg_num})", f"args[{arg_num}]")
+ js_buf = "(param, args) => " + js_buf.replace("np.", "Math.")
+ return [(f'"{self.model_function}"', js_buf)]
+
def to_json(self):
ret = super().to_json()
ret.update(
diff --git a/lib/model.py b/lib/model.py
index 4585dfe..8cbb012 100644
--- a/lib/model.py
+++ b/lib/model.py
@@ -373,6 +373,13 @@ class AnalyticModel:
return ret
+ def webconf_function_map(self) -> list:
+ ret = list()
+ for name in self.names:
+ for attr_model in self.attr_by_name[name].values():
+ ret.extend(attr_model.webconf_function_map())
+ return ret
+
def predict(self, trace, with_fitted=True, wth_lut=False):
pass
# TODO trace= ( (name, duration), (name, duration), ...)
diff --git a/lib/parameters.py b/lib/parameters.py
index a8a8451..d5339c5 100644
--- a/lib/parameters.py
+++ b/lib/parameters.py
@@ -537,6 +537,9 @@ class ModelAttribute:
ret = {"mean": (self.mean, unit), "median": (self.median, unit)}
return ret
+ def webconf_function_map(self):
+ return self.model_function.webconf_function_map()
+
@staticmethod
def from_json(cls, name, attr, data):
param_names = data["paramNames"]