Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
respdiff
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
18
Issues
18
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
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
Knot projects
respdiff
Commits
3fbe1d9d
Commit
3fbe1d9d
authored
Apr 17, 2018
by
Tomas Krizek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
diffsum: refactor printing global statistics
parent
1e88e873
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
137 additions
and
4 deletions
+137
-4
respdiff/cli.py
respdiff/cli.py
+101
-2
respdiff/diffsum.py
respdiff/diffsum.py
+2
-2
tests/test_cli.py
tests/test_cli.py
+34
-0
No files found.
respdiff/cli.py
View file @
3fbe1d9d
from
argparse
import
ArgumentParser
,
Namespace
import
logging
import
math
import
os
import
sys
from
typing
import
Mapping
from
typing
import
Dict
,
Mapping
,
Optional
,
Tuple
,
Union
# noqa
from
tabulate
import
tabulate
import
cfg
from
dataformat
import
DataMismatch
,
FieldCounter
,
FieldLabel
from
dataformat
import
DataMismatch
,
DiffReport
,
FieldCounter
,
FieldLabel
Number
=
Union
[
int
,
float
]
LOGGING_LEVEL
=
logging
.
DEBUG
CONFIG_FILENAME
=
'respdiff.cfg'
REPORT_FILENAME
=
'report.json'
...
...
@@ -48,6 +51,61 @@ def get_datafile(args: Namespace, check_exists: bool = True, key: str = 'datafil
return
datafile
def
format_stats_line
(
description
:
str
,
number
:
int
,
pct
:
float
=
None
,
diff
:
int
=
None
,
diff_pct
:
float
=
None
,
additional
:
str
=
None
)
->
str
:
s
=
{}
# type: Dict[str, str]
s
[
'description'
]
=
'{:21s}'
.
format
(
description
)
s
[
'number'
]
=
'{:8d}'
.
format
(
number
)
s
[
'pct'
]
=
'{:6.2f} %'
.
format
(
pct
)
if
pct
is
not
None
else
' '
*
8
s
[
'additional'
]
=
'{:30s}'
.
format
(
additional
)
if
additional
is
not
None
else
' '
*
30
s
[
'diff'
]
=
'{:+6d}'
.
format
(
diff
)
if
diff
is
not
None
else
' '
*
6
s
[
'diff_pct'
]
=
'{:+7.2f}'
.
format
(
diff_pct
)
if
diff_pct
is
not
None
else
' '
*
7
return
'{description} {number} {pct} {additional} {diff} {diff_pct}'
.
format
(
**
s
)
def
get_stats_data
(
n
:
int
,
total
:
int
=
None
,
ref_n
:
int
=
None
,
)
->
Tuple
[
int
,
float
,
Optional
[
int
],
Optional
[
float
]]:
"""
Return absolute and relative data statistics
Optionally, the data is compared with a reference.
"""
def
percentage
(
dividend
:
Union
[
int
,
float
],
divisor
:
Union
[
int
,
float
]
)
->
Optional
[
float
]:
"""Return dividend/divisor value in %"""
if
divisor
is
None
:
return
None
if
divisor
==
0
:
if
dividend
>
0
:
return
float
(
'+inf'
)
if
dividend
<
0
:
return
float
(
'-inf'
)
return
float
(
'nan'
)
return
dividend
*
100.0
/
divisor
pct
=
percentage
(
n
,
total
)
diff
=
None
diff_pct
=
None
if
ref_n
is
not
None
:
diff
=
n
-
ref_n
diff_pct
=
percentage
(
diff
,
ref_n
)
return
n
,
pct
,
diff
,
diff_pct
def
print_fields_overview
(
field_counters
:
Mapping
[
FieldLabel
,
FieldCounter
]
)
->
None
:
...
...
@@ -83,3 +141,44 @@ def print_field_mismatch_stats(
tablefmt
=
'simple'
,
floatfmt
=
'.2f'
))
print
(
''
)
def
print_global_stats
(
report
:
DiffReport
,
reference
:
DiffReport
=
None
)
->
None
:
ref_duration
=
getattr
(
reference
,
'duration'
,
None
)
ref_total_answers
=
getattr
(
reference
,
'total_answers'
,
None
)
ref_total_queries
=
getattr
(
reference
,
'total_queries'
,
None
)
print
(
'== Global statistics'
)
print
(
format_stats_line
(
'duration'
,
*
get_stats_data
(
report
.
duration
,
ref_n
=
ref_duration
),
additional
=
'seconds'
))
print
(
format_stats_line
(
'queries'
,
*
get_stats_data
(
report
.
total_queries
,
ref_n
=
ref_total_queries
)))
print
(
format_stats_line
(
'answers'
,
*
get_stats_data
(
report
.
total_answers
,
report
.
total_queries
,
ref_total_answers
,
ref_total_queries
)))
print
(
''
)
def
print_differences_stats
(
report
:
DiffReport
,
reference
:
DiffReport
=
None
)
->
None
:
ref_upstream_unstable
=
getattr
(
reference
,
'upstream_unstable'
,
None
)
ref_total_answers
=
getattr
(
reference
,
'total_answers'
,
None
)
ref_not_reproducible
=
getattr
(
reference
,
'not_reproducible'
,
None
)
ref_summary
=
getattr
(
reference
,
'summary'
,
None
)
ref_target_disagrees
=
len
(
ref_summary
)
if
ref_summary
is
not
None
else
None
ref_usable_answers
=
getattr
(
reference
,
'usable_answers'
,
None
)
print
(
'== Differences statistics'
)
print
(
format_stats_line
(
'upstream unstable'
,
*
get_stats_data
(
report
.
summary
.
upstream_unstable
,
report
.
total_answers
,
ref_upstream_unstable
,
ref_total_answers
),
additional
=
'of answers (ignoring)'
))
print
(
format_stats_line
(
'not 100% reproducible'
,
*
get_stats_data
(
report
.
summary
.
not_reproducible
,
report
.
total_answers
,
ref_not_reproducible
,
ref_total_answers
),
additional
=
'of answers (ignoring)'
))
print
(
format_stats_line
(
'target disagrees'
,
*
get_stats_data
(
len
(
report
.
summary
),
report
.
summary
.
usable_answers
,
ref_target_disagrees
,
ref_usable_answers
),
additional
=
'of not ignored answers'
))
print
(
''
)
respdiff/diffsum.py
View file @
3fbe1d9d
...
...
@@ -123,8 +123,8 @@ def main():
report
=
DiffReport
.
from_json
(
datafile
)
report
.
summary
=
Summary
.
from_report
(
report
,
field_weights
)
print_global_stats
(
report
)
print_differences_stats
(
report
.
summary
,
report
.
total_answers
)
cli
.
print_global_stats
(
report
)
cli
.
print_differences_stats
(
report
)
if
report
.
summary
:
field_counters
=
report
.
summary
.
get_field_counters
()
...
...
tests/test_cli.py
0 → 100644
View file @
3fbe1d9d
import
math
import
pytest
from
pytest
import
approx
from
cli
import
get_stats_data
@
pytest
.
mark
.
parametrize
(
'n, total, ref_n, expected'
,
[
(
9
,
None
,
None
,
(
9
,
None
,
None
,
None
)),
(
9
,
10
,
None
,
(
9
,
90
,
None
,
None
)),
(
11
,
None
,
10
,
(
11
,
None
,
1
,
10
)),
(
9
,
None
,
10
,
(
9
,
None
,
-
1
,
-
10
)),
(
10
,
None
,
10
,
(
10
,
None
,
0
,
0
)),
(
10
,
None
,
0
,
(
10
,
None
,
+
10
,
float
(
'inf'
))),
(
0
,
None
,
0
,
(
0
,
None
,
0
,
float
(
'nan'
))),
(
9
,
10
,
10
,
(
9
,
90
,
-
1
,
-
10
)),
(
9
,
10
,
90
,
(
9
,
90
,
-
81
,
-
81
*
100.0
/
90
)),
(
90
,
100
,
9
,
(
90
,
90
,
81
,
81
*
100.0
/
9
)),
])
def
test_get_stats_data
(
n
,
total
,
ref_n
,
expected
):
got_n
,
got_pct
,
got_diff
,
got_diff_pct
=
get_stats_data
(
n
,
total
,
ref_n
)
assert
got_n
==
expected
[
0
]
assert
got_diff
==
expected
[
2
]
def
compare_float
(
got
,
exp
):
if
got
is
None
:
return
exp
is
None
if
math
.
isnan
(
got
):
return
math
.
isnan
(
exp
)
return
got
==
approx
(
exp
)
assert
compare_float
(
got_pct
,
expected
[
1
])
assert
compare_float
(
got_diff_pct
,
expected
[
3
])
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