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
517a70c3
Commit
517a70c3
authored
Jun 10, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to update all metadata from measures of a measure type
parent
937e4442
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
14 deletions
+52
-14
measure-analysis/measure-analysis.py
measure-analysis/measure-analysis.py
+52
-14
No files found.
measure-analysis/measure-analysis.py
View file @
517a70c3
...
...
@@ -112,16 +112,35 @@ class MeasureSetHandler:
else
:
print
(
"{}{} doesn't exist"
.
format
(
mtype
,
mid
))
def
modify_metadata
(
self
,
mtype
,
mid
):
def
update_metadata
(
self
,
mtype
,
mid
,
metadata
,
removed_metadata
):
if
mtype
in
self
.
measure_sets
and
mid
in
self
.
measure_sets
[
mtype
][
'ids'
]:
measure_set
=
self
.
get_measure_set
(
"{}{}"
.
format
(
mtype
,
mid
))
metadata
=
measure_set
.
input_metadata
()
measure_set
.
metadata
.
update
(
metadata
)
measure_set
.
update_metadata
(
metadata
,
removed_metadata
)
measure_file_name
=
"{}/{}{}.json"
.
format
(
MeasureSetHandler
.
measures_dir
,
mtype
,
mid
)
measure_set
.
export_to_json
(
measure_file_name
)
else
:
print
(
"{}{} doesn't exist"
.
format
(
mtype
,
mid
))
def
modify_metadata
(
self
,
mtype
,
mid
=-
1
):
update_all
=
(
mid
==
-
1
)
if
mtype
in
self
.
measure_sets
:
measure_ids
=
self
.
measure_sets
[
mtype
][
'ids'
]
else
:
print
(
"There are no measures of type {}"
.
format
(
mtype
))
return
if
update_all
:
mid
=
measure_ids
[
0
]
if
mtype
in
self
.
measure_sets
and
mid
in
measure_ids
:
measure_set
=
self
.
get_measure_set
(
"{}{}"
.
format
(
mtype
,
mid
))
metadata
,
removed_metadata
=
measure_set
.
input_metadata
()
self
.
update_metadata
(
mtype
,
mid
,
metadata
,
removed_metadata
)
if
update_all
:
for
measure_id
in
measure_ids
:
self
.
update_metadata
(
mtype
,
measure_id
,
metadata
,
removed_metadata
)
else
:
print
(
"{}{} doesn't exist"
.
format
(
mtype
,
mid
))
def
remove_all
(
self
):
for
mtype
in
self
.
measure_sets
:
while
True
:
...
...
@@ -351,37 +370,54 @@ class MeasureSet:
return
"Cols: "
+
str
(
self
.
props
)
+
"
\
n
"
def
merge_metadata
(
metadata
,
new_metadata
,
removed_metadata
):
metadata
.
update
(
new_metadata
)
for
metadata_name
in
removed_metadata
:
metadata
.
pop
(
metadata_name
,
None
)
return
metadata
def
update_metadata
(
self
,
metadata
,
removed_metadata
):
self
.
metadata
=
MeasureSet
.
merge_metadata
(
self
.
metadata
,
metadata
,
removed_metadata
)
def
input_metadata
(
self
):
metadata
=
{}
metadata
.
update
(
self
.
metadata
)
removed_metadata
=
[]
metadata_name
=
""
while
True
:
merged_metadata
=
MeasureSet
.
merge_metadata
(
self
.
metadata
,
metadata
,
removed_metadata
)
print
(
"Current metadata:
\
n
"
)
for
metadata_name
in
metadata
:
print
(
" {}: {}"
.
format
(
metadata_name
,
metadata
[
metadata_name
]))
for
metadata_name
in
me
rged_me
tadata
:
print
(
" {}: {}"
.
format
(
metadata_name
,
me
rged_me
tadata
[
metadata_name
]))
metadata_name
=
input
(
'Enter metadata name (type "done" to exit): '
)
if
metadata_name
==
"done"
:
break
metadata_value
=
input
(
'Enter metadata value (type "done" to exit, "cancel" to cancel current metadata): '
)
metadata_value
=
input
(
'Enter metadata value (type "done" to exit, "
delete" to delete current metadata, "
cancel" to cancel current metadata): '
)
if
metadata_value
==
"done"
:
break
if
metadata_value
==
"cancel"
:
continue
if
metadata_value
==
"delete"
:
removed_metadata
.
append
(
metadata_name
)
continue
metadata
[
metadata_name
]
=
metadata_value
return
metadata
return
(
metadata
,
removed_metadata
)
def
add_metadata
(
self
,
measure_type
,
units
,
middle
,
metadata
):
def
add_metadata
(
self
,
measure_type
,
units
,
middle
,
metadata
,
user_input
=
False
):
self
.
measure_type
=
measure_type
self
.
units
=
units
self
.
middle
=
int
(
middle
)
self
.
metadata
.
update
(
metadata
)
if
user_input
:
new_metadata
,
removed_metadata
=
self
.
input_metadata
()
self
.
update_metadata
(
new_metadata
,
removed_metadata
)
def
add_chronological
(
self
,
props_names
,
props
):
self
.
props
=
props
...
...
@@ -462,10 +498,6 @@ class MeasureSet:
def
import_from_json_data
(
self
,
data
,
flat
=
False
,
user_input
=
False
):
if
user_input
:
self
.
metadata
.
update
(
data
[
'metadata'
])
data
[
'metadata'
]
=
self
.
input_metadata
()
measure_type
=
data
[
'measure_type'
]
units
=
data
[
'units'
]
metadata
=
data
[
'metadata'
]
...
...
@@ -474,7 +506,7 @@ class MeasureSet:
else
:
middle
=
0
self
.
add_metadata
(
measure_type
,
units
,
middle
,
metadata
)
self
.
add_metadata
(
measure_type
,
units
,
middle
,
metadata
,
user_input
)
props_names
=
data
[
'props_names'
]
...
...
@@ -583,6 +615,7 @@ def parse_args():
parser
.
add_argument
(
'--remove'
,
nargs
=
1
,
required
=
False
,
help
=
'remove a measure'
)
parser
.
add_argument
(
'--remove-all'
,
action
=
'store_true'
,
help
=
'remove all measure sets'
)
parser
.
add_argument
(
'-m'
,
nargs
=
1
,
required
=
False
,
help
=
'modify the metadata of a measure'
)
parser
.
add_argument
(
'-M'
,
nargs
=
1
,
required
=
False
,
help
=
'modify the metadata of all measures of a type'
)
parser
.
add_argument
(
'-t'
,
nargs
=
'?'
,
const
=
'input_file'
,
required
=
False
,
help
=
'generate table'
)
parser
.
add_argument
(
'-R'
,
action
=
'store_true'
,
required
=
False
,
help
=
'generate full measure report'
)
parser
.
add_argument
(
'-G'
,
action
=
'store_true'
,
required
=
False
,
help
=
'generate all graphs'
)
...
...
@@ -602,6 +635,11 @@ def parse_args():
mtype
,
mid
=
name_to_mtype_mid
(
args
.
m
[
0
])
ms_handler
.
modify_metadata
(
mtype
,
mid
)
if
args
.
M
is
not
None
:
mtype
=
str
(
args
.
M
[
0
])
ms_handler
.
modify_metadata
(
mtype
)
if
args
.
i
is
not
None
:
if
args
.
c
:
...
...
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