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
09a26fee
Commit
09a26fee
authored
Mar 25, 2019
by
Pierre Dittgen
Browse files
Implements compute_badge function
parent
44551ce0
Changes
1
Show whitespace changes
Inline
Side-by-side
validata_core/__init__.py
View file @
09a26fee
...
...
@@ -237,3 +237,58 @@ class Validator:
report
[
'date'
]
=
datetime
.
now
(
timezone
.
utc
).
isoformat
()
return
report
def
compute_badge
(
report
,
config
)
->
dict
:
"""Compute badge from report statistics and badge configuration."""
# Gets stats from report
stats
=
report
[
'tables'
][
0
][
'error-stats'
]
# And total number of cells
column_count
=
len
(
report
[
'tables'
][
0
][
'headers'
])
row_count
=
report
[
'tables'
][
0
][
'row-count'
]
cell_total_number
=
column_count
*
row_count
# No errors
if
stats
[
'count'
]
==
0
:
return
{
"structure"
:
'OK'
,
"body"
:
'OK'
,
"ratio"
:
0.0
,
}
# Structure part
structure_status
=
None
if
stats
[
'structure-errors'
][
'count'
]
==
0
:
structure_status
=
'OK'
else
:
cbc
=
stats
[
'structure-errors'
][
'count-by-code'
]
if
len
(
cbc
)
==
1
and
'invalid-column-delimiter'
in
cbc
:
structure_status
=
'WARN'
else
:
# structure_status = 'KO'
return
{
"structure"
:
'KO'
}
# body part
value_errors
=
stats
[
'value-errors'
]
if
value_errors
[
'count'
]
==
0
:
return
{
"structure"
:
structure_status
,
"body"
:
'OK'
,
"ratio"
:
0.0
}
# Computes error ratio
weight_dict
=
config
[
'body'
][
'errors-weight'
]
ratio
=
sum
([
nb
*
weight_dict
.
get
(
err
,
1.0
)
for
err
,
nb
in
value_errors
[
'count-by-code'
].
items
()])
\
/
cell_total_number
body_status
=
'WARN'
if
ratio
<
config
[
'body'
][
'acceptability-threshold'
]
else
'KO'
return
{
"structure"
:
structure_status
,
"body"
:
body_status
,
"ratio"
:
ratio
}
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