Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SOaAS
psot.repository
Commits
29590252
Commit
29590252
authored
Nov 28, 2017
by
hmueller
Browse files
Add TargetP to json converter.
parent
3c3f0eb1
Changes
1
Show whitespace changes
Inline
Side-by-side
scripts/convert_targetp.py
0 → 100755
View file @
29590252
#!/usr/bin/python3
import
sys
import
json
import
argparse
parser
=
argparse
.
ArgumentParser
(
description
=
'Convert targetp results to json documents'
)
parser
.
add_argument
(
'--result'
,
'-r'
,
required
=
True
,
help
=
'The targetp result file'
)
parser
.
add_argument
(
'--output'
,
'-o'
,
required
=
True
,
help
=
'The converted results json file'
)
args
=
parser
.
parse_args
()
filename
=
args
.
result
documents
=
{}
with
open
(
filename
)
as
f
:
tool
=
None
field_index
=
{
"Name"
:
None
,
"cTP"
:
None
,
"mTP"
:
None
,
"SP"
:
None
,
"Loc"
:
None
}
is_datasection
=
False
for
line
in
f
:
if
line
.
startswith
(
"---------"
):
is_datasection
=
not
is_datasection
elif
is_datasection
:
split
=
line
.
split
()
if
not
split
[
0
]
in
documents
:
documents
[
split
[
0
]]
=
{
"id"
:
split
[
0
],
"computations"
:
[{
'tool'
:
tool
,
'results'
:[{}]}]}
results
=
documents
[
split
[
0
]][
'computations'
][
0
][
"results"
][
0
]
for
field
in
field_index
:
if
field_index
[
field
]
is
not
None
:
if
field
in
[
"cTP"
,
"mTP"
,
"SP"
]:
results
[
field
.
lower
()]
=
float
(
split
[
field_index
[
field
]])
else
:
results
[
field
.
lower
()]
=
split
[
field_index
[
field
]]
else
:
if
line
.
startswith
(
'Name '
):
split
=
line
.
split
()
for
field
in
field_index
:
try
:
field_index
[
field
]
=
split
.
index
(
field
)
except
ValueError
:
print
(
'TargetP Converter: No column "'
+
field
+
'" found in table!'
)
elif
line
.
startswith
(
'### targetp '
):
split
=
line
.
split
()
tool
=
{
'name'
:
'TargetP'
,
'version'
:
split
[
2
].
replace
(
"v"
,
""
),
'plantmode'
:
True
}
elif
' NON-PLANT '
in
line
:
tool
[
'plantmode'
]
=
False
output_filename
=
args
.
output
with
open
(
output_filename
,
'w'
)
as
o
:
json
.
dump
(
documents
,
o
)
Write
Preview
Supports
Markdown
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