-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexternal_model.py
65 lines (47 loc) · 1.54 KB
/
external_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import json
class ExecutionInfo(object):
script = None
param_values = {}
def set_script(self, value):
self.script = value
def get_script(self):
return self.script
def set_param_values(self, value):
self.param_values = value
def get_param_values(self):
return self.param_values
def config_to_json(config):
parameters = []
for parameter in config.get_parameters():
if parameter.is_constant():
continue
parameters.append({
"name": parameter.get_name(),
"description": parameter.get_description(),
"withoutValue": parameter.is_no_value(),
"required": parameter.is_required(),
"default": parameter.get_default(),
"type": parameter.get_type(),
"min": parameter.get_min(),
"max": parameter.get_max(),
"values": parameter.get_values()
})
return json.dumps({
"name": config.get_name(),
"description": config.get_description(),
"parameters": parameters
})
def to_execution_info(request_data):
json_object = json.loads(request_data)
script = json_object.get("script")
info = ExecutionInfo()
info.set_script(script)
param_values = {}
parameters = json_object.get("parameters")
if parameters:
for parameter in parameters:
name = parameter.get("name")
value = parameter.get("value")
param_values[name] = value
info.set_param_values(param_values)
return info