-
Notifications
You must be signed in to change notification settings - Fork 10
/
extract_online_model.py
115 lines (100 loc) · 3.74 KB
/
extract_online_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""
Entrypoint Extract Online Model
---------------------
Entrypoint for the online model extractor wrapper.
"""
from online_model import extractor_wrapper
from utils import logging_tools, iotools
from utils.entrypoint import entrypoint, EntryPointParameters, ArgumentError
LOG = logging_tools.get_logger(__name__)
FUNCTION_OVERVIEW = 'overview'
FUNCTION_DEFINITION = 'definition'
def get_params():
return EntryPointParameters({
"function": dict(
flags=["-f", "--functionality"],
type=str,
required=True,
choices=["overview", "definition"],
help="Which functionality to run."
),
"knob_names": dict(
flags=["-k", "--knobs", "--knobnames"],
type=str,
nargs="+",
default=[],
help="Names of the knobs to show."
),
"time": dict(
flags=["-t", "--time"],
type=str,
),
"cwd": dict(
flags=["-c", "--cwd"],
type=str,
default="./",
help="Path of the current working directory.",
),
"server": dict(
flags=["-s", "--server"],
type=str,
help="Server to use."
),
"show_plot": dict(
flags=["--showplots"],
action="store_true",
help="Whether to show plots or not."
"(Only for {:s} functionality.)".format(FUNCTION_OVERVIEW)
)
})
@entrypoint(get_params(), strict=True)
def main(opt):
""" Entrypoint for the online model extractor python wrapper.
Creates either the overview or knob definitions, depending on the functionality chosen.
Keyword Args:
Required
function (str): Which functionality to run.
**Flags**: ['-f', '--functionality']
**Choices**: ['overview', 'definition']
Optional
cwd (str): Path of the current working directory.
**Flags**: ['-c', '--cwd']
**Default**: ``./``
knob_names (str): Names of the knobs to show.
**Flags**: ['-k', '--knobs', '--knobnames']
**Default**: __See Source__
server (str): Server to use.
**Flags**: ['-s', '--server']
show_plot: Whether to show plots or not.(Only for overview functionality.)
**Flags**: ['--showplots']
**Action**: ``store_true``
time (str): -Help not available-
**Flags**: ['-t', '--time']
"""
iotools.create_dirs(opt.cwd)
if opt.function == FUNCTION_OVERVIEW:
extractor_wrapper.extract_overview(opt.knob_names, opt.time, opt.cwd,
server=opt.server, show_plot=opt.show_plot)
elif opt.function == FUNCTION_DEFINITION:
if not opt.knob_names:
raise ArgumentError(
"Argument 'knob_names' required for function '{:s}'.".format(FUNCTION_DEFINITION)
)
if opt.time is None:
raise ArgumentError(
"Argument 'time' required for function '{:s}'.".format(FUNCTION_DEFINITION)
)
if opt.show_plot:
LOG.warn(
"Argument 'show_plot' has no effect in function '{:s}'".format(FUNCTION_DEFINITION)
)
extractor_wrapper.extract_knob_value_and_definition(opt.knob_names, opt.time, opt.cwd,
server=opt.server)
def _create_help():
""" Print help for parameters. """
import sys
from utils.entrypoint import create_parameter_help
create_parameter_help(sys.modules[__name__])
if __name__ == '__main__':
# _create_help()
main()