Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
tsn-measures
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
tsn-measures
Commits
68ae81be
Commit
68ae81be
authored
Jun 01, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add options to the measure analysis script
parent
2c34b5e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
11 deletions
+33
-11
measure-analysis/measure-analysis.py
measure-analysis/measure-analysis.py
+33
-11
No files found.
measure-analysis/measure-analysis.py
View file @
68ae81be
...
...
@@ -17,14 +17,21 @@ class MeasureSetHandler:
self
.
measure_sets
=
json
.
load
(
measure_sets_file
)
def
__str__
(
self
):
s
=
"List of measures:
\
n
\
n
"
for
measure_set
in
self
.
measure_sets
:
print
(
"List of measures:
\
n
\
n
"
)
print
(
" "
+
measure_set
)
s
+=
" {} : {}"
.
format
(
measure_set
,
self
.
measure_sets
[
measure_set
]
)
return
s
def
save
(
self
):
with
open
(
MeasureSetHandler
.
measure_sets_path
,
'w'
)
as
measure_sets_file
:
json
.
dump
(
self
.
measure_sets
,
measure_sets_file
)
def
get_measure_set
(
self
,
measure_name
):
measure_set
=
MeasureSet
()
measure_path
=
"{}/{}"
.
format
(
self
.
measures_dir
,
measure_name
)
measure_set
.
import_from_json
(
measure_path
,
False
)
return
measure_set
def
add_measure_set
(
self
,
measure_set
):
mtype
=
measure_set
.
measure_type
...
...
@@ -41,6 +48,8 @@ class MeasureSetHandler:
self
.
save
()
print
(
"Saved measure as {}{}"
.
format
(
mtype
,
next_id
))
def
remove_measure_set
(
self
,
mtype
,
mid
):
if
mtype
in
self
.
measure_sets
and
len
(
self
.
measure_sets
[
mtype
][
'ids'
])
>
0
:
...
...
@@ -103,11 +112,12 @@ class MeasureSet:
measure_type
=
data
[
'measure_type'
]
interval
=
data
[
'interval'
]
col_names
=
data
[
'col_names'
]
values
=
data
[
'values'
]
units
=
data
[
'units'
]
if
flat
:
values
=
data
[
'values'
]
nb_cols
=
len
(
col_names
)
cols
=
[[]
for
c
in
range
(
nb_cols
)]
...
...
@@ -129,11 +139,12 @@ class MeasureSet:
self
.
avg
,
self
.
var
]
headers
=
[
"
Name"
,
"
Min"
,
"Max"
,
"Avg"
,
"Var"
]
values
=
[[
(
format
(
m
[
j
][
i
],
'.4f'
)
+
self
.
units
[
i
])
for
j
in
range
(
len
(
m
))]
for
i
in
range
(
len
(
m
[
0
]
))]
headers
=
[
"Min"
,
"Max"
,
"Avg"
,
"Var"
]
values
=
[[
(
format
(
m
[
i
][
j
],
'.4f'
)
+
self
.
units
[
j
])
for
j
in
range
(
len
(
m
[
0
]))]
for
i
in
range
(
len
(
m
))]
table
=
[
headers
]
table
+=
[([(
"*"
+
self
.
col_names
[
i
]
+
"*"
)]
+
values
[
i
])
for
i
in
range
(
len
(
values
))]
table
+=
[[
"**"
+
" - "
.
join
(
self
.
col_names
)
+
"**"
]
*
len
(
headers
)]
table
+=
[[
" - "
.
join
(
values
[
i
])
for
i
in
range
(
len
(
values
))]]
col_lens
=
[
max
([
len
(
table
[
i
][
j
])
for
i
in
range
(
len
(
table
))])
for
j
in
range
(
len
(
table
[
0
]))]
table
=
[[
table
[
i
][
j
].
ljust
(
col_lens
[
j
])
for
j
in
range
(
len
(
table
[
0
]))]
for
i
in
range
(
len
(
table
))]
...
...
@@ -149,20 +160,31 @@ def parse():
parser
=
argparse
.
ArgumentParser
(
description
=
'Measure analysis'
)
parser
.
add_argument
(
'-i'
,
nargs
=
1
,
required
=
False
,
help
=
'import file'
)
parser
.
add_argument
(
'--remove_all'
,
action
=
'store_true'
,
help
=
'remove all measure sets'
)
parser
.
add_argument
(
'-t'
,
action
=
'store_true'
,
help
=
'generate table'
)
parser
.
add_argument
(
'-t'
,
nargs
=
'?'
,
const
=
'input_file'
,
required
=
False
,
help
=
'generate table'
)
parser
.
add_argument
(
'-s'
,
action
=
'store_true'
,
help
=
'show measures'
)
args
=
parser
.
parse_args
()
ms_handler
=
MeasureSetHandler
()
if
args
.
i
is
not
None
:
measure_set
=
MeasureSet
()
measure_set
.
import_from_json
(
args
.
i
[
0
],
True
)
ms_handler
.
add_measure_set
(
measure_set
)
if
args
.
t
is
not
None
:
print
(
measure_set
.
generate_table
())
elif
args
.
t
is
not
None
and
args
.
t
!=
"input_file"
:
measure_set
=
ms_handler
.
get_measure_set
(
args
.
t
)
print
(
measure_set
.
generate_table
())
if
args
.
remove_all
:
confirm
=
input
(
"Are you sure all measure sets should be removed ? [Yes] / [No]: "
)
if
confirm
==
"Yes"
:
ms_handler
.
remove_all
()
if
args
.
i
is
not
None
:
measure_set
=
MeasureSet
()
measure_set
.
import_from_json
(
args
.
i
[
0
],
True
)
ms_handler
.
add_measure_set
(
measure_set
)
if
args
.
s
:
print
(
ms_handler
)
parse
()
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