Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
Collectl2plotly
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Matthias Lieber
Collectl2plotly
Commits
dd32b479
Commit
dd32b479
authored
Mar 27, 2020
by
Julius Metz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add comments and validation_example_html
parent
f8502ef8
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
7 deletions
+34
-7
Collectl2plotly/Collectl2plotly/Collectl2plotly.py
Collectl2plotly/Collectl2plotly/Collectl2plotly.py
+31
-6
collectl_value_validation/html/plotly.js
collectl_value_validation/html/plotly.js
+1
-0
collectl_value_validation/html/testhtml.html
collectl_value_validation/html/testhtml.html
+1
-0
readme.md
readme.md
+1
-1
No files found.
Collectl2plotly/Collectl2plotly/Collectl2plotly.py
View file @
dd32b479
...
@@ -34,18 +34,25 @@ DEFAULT_FILTER = 'average'
...
@@ -34,18 +34,25 @@ DEFAULT_FILTER = 'average'
### validation Config
### validation Config
# Merger that exist and posible kwargs/parameter
# Merger that exist and possible kwargs/parameter
# key = merger_func name
# value = dict with kwarguments of merger_func
# kwargument dict:
# key = argument name
# value = 1. 'type' with a type obj or a tuple of type objs
# or
# 2. 'choices' list of possible choices for the kwargument
MERGER
=
{
MERGER
=
{
'x2oneaddition_int'
:
{
'x2oneaddition_int'
:
{
'roundingpoint'
:
{
'type'
:
int
},
'roundingpoint'
:
{
'type'
:
int
},
'operator'
:
{
'
type'
:
str
,
'
choices'
:
[
'+'
,
'-'
,
'*'
,
'/'
,
'%'
]},
'operator'
:
{
'choices'
:
[
'+'
,
'-'
,
'*'
,
'/'
,
'%'
]},
'operator_value'
:
{
'type'
:
(
int
,
float
)},
'operator_value'
:
{
'type'
:
(
int
,
float
)},
},
},
'x2oneaddition_float'
:
{
'x2oneaddition_float'
:
{
'roundingpoint'
:
{
'type'
:
int
},
'roundingpoint'
:
{
'type'
:
int
},
'operator'
:
{
'type'
:
str
,
'choices'
:
[
'+'
,
'-'
,
'*'
,
'/'
,
'%'
]},
'operator'
:
{
'type'
:
str
,
'choices'
:
[
'+'
,
'-'
,
'*'
,
'/'
,
'%'
]},
'operator_value'
:
{
'type'
:
(
int
,
float
)},
'operator_value'
:
{
'type'
:
(
int
,
float
)},
}
}
,
}
}
# validation infos of config
# validation infos of config
...
@@ -180,8 +187,11 @@ def is_merger(to_check):
...
@@ -180,8 +187,11 @@ def is_merger(to_check):
except
ValueError
:
except
ValueError
:
return
False
,
"'{0}' has no right merger structur expected: (name[str], kwargs[dict])"
.
format
(
to_check
)
return
False
,
"'{0}' has no right merger structur expected: (name[str], kwargs[dict])"
.
format
(
to_check
)
#check name and mergerkwargs has right types
if
isinstance
(
name
,
str
)
and
isinstance
(
mergerkwargs
,
dict
):
if
isinstance
(
name
,
str
)
and
isinstance
(
mergerkwargs
,
dict
):
# check is the given merger known
if
name
in
MERGER
:
if
name
in
MERGER
:
# check every kwarg of the given merger is it known and is right value for it given.
for
kwarg_name
,
value
in
mergerkwargs
.
items
():
for
kwarg_name
,
value
in
mergerkwargs
.
items
():
if
kwarg_name
in
MERGER
[
name
]:
if
kwarg_name
in
MERGER
[
name
]:
if
'choices'
in
MERGER
[
name
][
kwarg_name
]:
if
'choices'
in
MERGER
[
name
][
kwarg_name
]:
...
@@ -209,20 +219,25 @@ def check_valid(to_check, validationinfos):
...
@@ -209,20 +219,25 @@ def check_valid(to_check, validationinfos):
Arguments:
Arguments:
to_check {unkown} -- object to check is valid
to_check {unkown} -- object to check is valid
validationinfos {
dict or type or tuple with types} -- infos what is
needed that to_check is valid
validationinfos {
validationdict(see comment of VALIDATIONS_INFOS) or type or tuple with types} -- infos what is
needed that to_check is valid
Returns:
Returns:
(bool, str) -- return true if it is valid, false and error if not
(bool, str) -- return true if it is valid, false and error if not
"""
"""
# check is validationinfos a validationdict or only a type/tuple of types
if
isinstance
(
validationinfos
,
dict
):
if
isinstance
(
validationinfos
,
dict
):
if
validationinfos
[
'type'
]
==
'__merger__'
:
if
validationinfos
[
'type'
]
==
'__merger__'
:
return
is_merger
(
to_check
)
return
is_merger
(
to_check
)
else
:
else
:
# check is given elem expected type
if
isinstance
(
to_check
,
validationinfos
[
'type'
]):
if
isinstance
(
to_check
,
validationinfos
[
'type'
]):
# if elem dict check special cases of it
if
type
(
to_check
)
==
dict
:
if
type
(
to_check
)
==
dict
:
# check is elem is empty and is this ok
if
not
validationinfos
.
get
(
'emptyable'
,
False
)
and
not
len
(
to_check
):
if
not
validationinfos
.
get
(
'emptyable'
,
False
)
and
not
len
(
to_check
):
return
False
,
'{0} can not be empty!'
.
format
(
to_check
)
return
False
,
'{0} can not be empty!'
.
format
(
to_check
)
# check special keys and there values if 'fixed_keys' is given
for
fixed_name
,
infos
in
validationinfos
.
get
(
'fixed_keys'
,
{}).
items
():
for
fixed_name
,
infos
in
validationinfos
.
get
(
'fixed_keys'
,
{}).
items
():
if
fixed_name
in
to_check
:
if
fixed_name
in
to_check
:
if
'validator'
in
infos
:
if
'validator'
in
infos
:
...
@@ -233,6 +248,7 @@ def check_valid(to_check, validationinfos):
...
@@ -233,6 +248,7 @@ def check_valid(to_check, validationinfos):
elif
infos
.
get
(
'required'
,
True
):
elif
infos
.
get
(
'required'
,
True
):
return
False
,
'{0} missing key: "{1}"'
.
format
(
to_check
,
fixed_name
)
return
False
,
'{0} missing key: "{1}"'
.
format
(
to_check
,
fixed_name
)
# check all keys and there values if 'changing_keys' is given
if
'changing_keys'
in
validationinfos
:
if
'changing_keys'
in
validationinfos
:
for
key
,
subvalue
in
to_check
.
items
():
for
key
,
subvalue
in
to_check
.
items
():
if
not
isinstance
(
key
,
validationinfos
[
'changing_keys'
][
'key_type'
]):
if
not
isinstance
(
key
,
validationinfos
[
'changing_keys'
][
'key_type'
]):
...
@@ -243,11 +259,13 @@ def check_valid(to_check, validationinfos):
...
@@ -243,11 +259,13 @@ def check_valid(to_check, validationinfos):
valid
,
error_msg
=
check_valid
(
subvalue
,
validationinfos
[
'changing_keys'
][
'validator'
])
valid
,
error_msg
=
check_valid
(
subvalue
,
validationinfos
[
'changing_keys'
][
'validator'
])
if
not
valid
:
if
not
valid
:
return
valid
,
'[{0}] => {1}'
.
format
(
key
,
error_msg
)
return
valid
,
'[{0}] => {1}'
.
format
(
key
,
error_msg
)
# if elem list or tuple check special cases of it
if
isinstance
(
to_check
,
(
list
,
tuple
)):
elif
isinstance
(
to_check
,
(
list
,
tuple
)):
# check is elem is empty and is this ok
if
not
validationinfos
.
get
(
'emptyable'
,
False
)
and
not
len
(
to_check
):
if
not
validationinfos
.
get
(
'emptyable'
,
False
)
and
not
len
(
to_check
):
return
False
,
'{0} can not be empty!'
.
format
(
to_check
)
return
False
,
'{0} can not be empty!'
.
format
(
to_check
)
# validate all values of tuple/list if 'subvalue_validator' is given
if
'subvalue_validator'
in
validationinfos
:
if
'subvalue_validator'
in
validationinfos
:
for
i
,
subvalue
in
enumerate
(
to_check
):
for
i
,
subvalue
in
enumerate
(
to_check
):
valid
,
error_msg
=
check_valid
(
subvalue
,
validationinfos
[
'subvalue_validator'
])
valid
,
error_msg
=
check_valid
(
subvalue
,
validationinfos
[
'subvalue_validator'
])
...
@@ -260,9 +278,11 @@ def check_valid(to_check, validationinfos):
...
@@ -260,9 +278,11 @@ def check_valid(to_check, validationinfos):
)
)
else
:
else
:
# check it is the special case that is the type is '__merger__'
if
validationinfos
==
'__merger__'
:
if
validationinfos
==
'__merger__'
:
return
is_merger
(
to_check
)
return
is_merger
(
to_check
)
else
:
else
:
# check is given elem expected type
if
not
isinstance
(
to_check
,
validationinfos
):
if
not
isinstance
(
to_check
,
validationinfos
):
return
False
,
'{0} is {1} expected: {2}'
.
format
(
return
False
,
'{0} is {1} expected: {2}'
.
format
(
to_check
,
type
(
to_check
),
validationinfos
,
to_check
,
type
(
to_check
),
validationinfos
,
...
@@ -598,6 +618,7 @@ def build_html(plots_dict):
...
@@ -598,6 +618,7 @@ def build_html(plots_dict):
with
tag
(
'head'
):
with
tag
(
'head'
):
with
tag
(
'script'
,
src
=
'plotly.js'
):
with
tag
(
'script'
,
src
=
'plotly.js'
):
pass
pass
# build plotly javascipt in html
with
tag
(
'script'
):
with
tag
(
'script'
):
doc
.
asis
(
"document.onreadystatechange = () => {if (document.readyState === 'complete') {"
)
doc
.
asis
(
"document.onreadystatechange = () => {if (document.readyState === 'complete') {"
)
for
name
,
plots
in
plots_dict
.
items
():
for
name
,
plots
in
plots_dict
.
items
():
...
@@ -615,6 +636,7 @@ def build_html(plots_dict):
...
@@ -615,6 +636,7 @@ def build_html(plots_dict):
with
tag
(
'li'
):
with
tag
(
'li'
):
with
tag
(
'a'
,
href
=
'#'
+
name
):
with
tag
(
'a'
,
href
=
'#'
+
name
):
text
(
name
)
text
(
name
)
# add div for all plots in html
for
name
,
plots
in
plots_dict
.
items
():
for
name
,
plots
in
plots_dict
.
items
():
with
tag
(
'div'
,
id
=
name
):
with
tag
(
'div'
,
id
=
name
):
for
i
in
range
(
len
(
plots
)):
for
i
in
range
(
len
(
plots
)):
...
@@ -663,10 +685,12 @@ def data_from_file(arguments):
...
@@ -663,10 +685,12 @@ def data_from_file(arguments):
"""
"""
path
,
collectl
,
shorten_cmds
,
coarsest
,
filtercmds
,
filtervalue
,
filtertype
,
config
=
arguments
path
,
collectl
,
shorten_cmds
,
coarsest
,
filtercmds
,
filtervalue
,
filtertype
,
config
=
arguments
host
=
''
host
=
''
# get hostname
with
gzip
.
open
(
path
,
'r'
)
as
f
:
with
gzip
.
open
(
path
,
'r'
)
as
f
:
for
line
in
f
:
for
line
in
f
:
if
line
.
startswith
(
b'# Host:'
):
if
line
.
startswith
(
b'# Host:'
):
host
=
re
.
search
(
r'# Host: *([^ ]+)'
,
line
.
decode
()).
group
(
1
)
host
=
re
.
search
(
r'# Host: *([^ ]+)'
,
line
.
decode
()).
group
(
1
)
data
,
filter_data
=
parse_file
(
path
,
collectl
,
shorten_cmds
,
coarsest
,
config
)
data
,
filter_data
=
parse_file
(
path
,
collectl
,
shorten_cmds
,
coarsest
,
config
)
filter_infos
=
None
filter_infos
=
None
...
@@ -722,6 +746,7 @@ def main(source, collectl, plotlypath, destination, configpath,
...
@@ -722,6 +746,7 @@ def main(source, collectl, plotlypath, destination, configpath,
print
(
'in destination "collectlplots" already exist'
)
print
(
'in destination "collectlplots" already exist'
)
exit
(
1
)
exit
(
1
)
# load custome conf if given
config_module
=
default_plot_conf
config_module
=
default_plot_conf
if
configpath
:
if
configpath
:
if
configpath
.
endswith
(
'.py'
):
if
configpath
.
endswith
(
'.py'
):
...
...
collectl_value_validation/html/plotly.js
0 → 120000
View file @
dd32b479
..
/
..
/
Collectl2plotly
/
Collectl2plotly
/
plotly
-
latest
.
min
.
js
\ No newline at end of file
collectl_value_validation/html/testhtml.html
0 → 100644
View file @
dd32b479
This diff is collapsed.
Click to expand it.
readme.md
View file @
dd32b479
...
@@ -290,7 +290,7 @@ A merger is a function that merge a values from collectl to existing base value.
...
@@ -290,7 +290,7 @@ A merger is a function that merge a values from collectl to existing base value.
### Add new Merger
### Add new Merger
In default it gives only two filter but in value_merger.py it is possible to add more.
In default it gives only two filter but in value_merger.py it is possible to add more.
If one merger is added in value_merger.py he must be added in the global var MERGER in Collectl2plotly.py.
If one merger is added in value_merger.py he must be added in the global var
iable
MERGER in Collectl2plotly.py.
#### Arguments of a merger function
#### Arguments of a merger function
1.
base value is the initial value for merging on it. Normaly has the same type like the return value
1.
base value is the initial value for merging on it. Normaly has the same type like the return value
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment