-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclaimstats.py
executable file
·66 lines (56 loc) · 2.51 KB
/
claimstats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
import claims
import tabulate
reports = claims.Report()
stat_all = len(reports)
reports_fails = [i for i in reports if i['status'] in claims.Case.FAIL_STATUSES]
stat_failed = len(reports_fails)
reports_claimed = [i for i in reports_fails if i['testActions'][0].get('reason')]
stat_claimed = len(reports_claimed)
print("\nOverall stats")
print(tabulate.tabulate(
[[stat_all, stat_failed, stat_claimed]],
headers=['all reports', 'failures', 'claimed failures']))
rules = claims.Ruleset()
rules_reasons = [r['reason'] for r in rules]
reports_per_reason = {'UNKNOWN': stat_failed-stat_claimed}
reports_per_reason.update({r:0 for r in rules_reasons})
for report in reports_claimed:
reason = report['testActions'][0]['reason']
if reason not in reports_per_reason:
reports_per_reason[reason] = 0
reports_per_reason[reason] += 1
print("\nHow various reasons for claims are used")
reports_per_reason = sorted(reports_per_reason.items(), key=lambda x: x[1], reverse=True)
reports_per_reason = [(r, c, r in rules_reasons) for r, c in reports_per_reason]
print(tabulate.tabulate(
reports_per_reason,
headers=['claim reason', 'number of times', 'is it in current knowleadgebase?']))
reports_per_class = {}
for report in reports:
class_name = report['className']
if class_name not in reports_per_class:
reports_per_class[class_name] = {'all': 0, 'failed': 0}
reports_per_class[class_name]['all'] += 1
if report in reports_fails:
reports_per_class[class_name]['failed'] += 1
print("\nHow many failures are there per class")
print(tabulate.tabulate(
sorted([(c, r['all'], r['failed'], float(r['failed'])/r['all']) for c,r in reports_per_class.items()],
key=lambda x: x[3], reverse=True),
headers=['class name', 'number of reports', 'number of failures', 'failures ratio'],
floatfmt=".3f"))
reports_per_method = {}
for report in reports:
method = report['className'].split('.')[2]
if method not in reports_per_method:
reports_per_method[method] = {'all': 0, 'failed': 0}
reports_per_method[method]['all'] += 1
if report in reports_fails:
reports_per_method[method]['failed'] += 1
print("\nHow many failures are there per method (CLI vs. API vs. UI)")
print(tabulate.tabulate(
sorted([(c, r['all'], r['failed'], float(r['failed'])/r['all']) for c,r in reports_per_method.items()],
key=lambda x: x[3], reverse=True),
headers=['method', 'number of reports', 'number of failures', 'failures ratio'],
floatfmt=".3f"))