summaryrefslogtreecommitdiff
path: root/lib/functions.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/functions.py')
-rw-r--r--lib/functions.py22
1 files changed, 22 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(