Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alexandre Bulté
Validata Core
Commits
9f83a7f8
Commit
9f83a7f8
authored
Mar 29, 2019
by
Pierre Dittgen
Browse files
Refactor badge generation code
parent
175113cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
validata_core/__init__.py
View file @
9f83a7f8
...
@@ -242,6 +242,18 @@ class Validator:
...
@@ -242,6 +242,18 @@ class Validator:
def
compute_badge
(
report
,
config
)
->
dict
:
def
compute_badge
(
report
,
config
)
->
dict
:
"""Compute badge from report statistics and badge configuration."""
"""Compute badge from report statistics and badge configuration."""
def
build_badge
(
structure_status
,
body_status
=
None
,
error_ratio
=
None
):
"""Badge info creation"""
if
structure_status
==
'KO'
:
return
{
"structure"
:
'KO'
}
return
{
"structure"
:
structure_status
,
"body"
:
body_status
,
"error-ratio"
:
error_ratio
}
# Gets stats from report
# Gets stats from report
stats
=
report
[
'tables'
][
0
][
'error-stats'
]
stats
=
report
[
'tables'
][
0
][
'error-stats'
]
...
@@ -252,11 +264,7 @@ def compute_badge(report, config) -> dict:
...
@@ -252,11 +264,7 @@ def compute_badge(report, config) -> dict:
# No errors
# No errors
if
stats
[
'count'
]
==
0
:
if
stats
[
'count'
]
==
0
:
return
{
return
build_badge
(
'OK'
,
'OK'
,
0.0
)
"structure"
:
'OK'
,
"body"
:
'OK'
,
"error-ratio"
:
0.0
,
}
# Structure part
# Structure part
structure_status
=
None
structure_status
=
None
...
@@ -268,18 +276,12 @@ def compute_badge(report, config) -> dict:
...
@@ -268,18 +276,12 @@ def compute_badge(report, config) -> dict:
structure_status
=
'WARN'
structure_status
=
'WARN'
else
:
else
:
# structure_status = 'KO'
# structure_status = 'KO'
return
{
return
build_badge
(
'KO'
)
"structure"
:
'KO'
}
# body part
# body part
value_errors
=
stats
[
'value-errors'
]
value_errors
=
stats
[
'value-errors'
]
if
value_errors
[
'count'
]
==
0
:
if
value_errors
[
'count'
]
==
0
:
return
{
return
build_badge
(
structure_status
,
'OK'
,
0.0
)
"structure"
:
structure_status
,
"body"
:
'OK'
,
"error-ratio"
:
0.0
}
# Computes error ratio
# Computes error ratio
weight_dict
=
config
[
'body'
][
'errors-weight'
]
weight_dict
=
config
[
'body'
][
'errors-weight'
]
...
@@ -287,8 +289,4 @@ def compute_badge(report, config) -> dict:
...
@@ -287,8 +289,4 @@ def compute_badge(report, config) -> dict:
/
cell_total_number
/
cell_total_number
body_status
=
'WARN'
if
ratio
<
config
[
'body'
][
'acceptability-threshold'
]
else
'KO'
body_status
=
'WARN'
if
ratio
<
config
[
'body'
][
'acceptability-threshold'
]
else
'KO'
return
{
return
build_badge
(
structure_status
,
body_status
,
ratio
)
"structure"
:
structure_status
,
"body"
:
body_status
,
"error-ratio"
:
ratio
}
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