-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade.py
89 lines (78 loc) · 1.98 KB
/
grade.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from enum import IntEnum
class Grade(IntEnum):
'''
Class which represents the grades assigned to a scanline or a barcode, it has several static methods to compute the grade
for each parameter of interest
'''
A = 4
B = 3
C = 2
D = 1
F = 0
@staticmethod
def get_min_reflectance_grade(score, rmax):
value = (255 * score) / 100
if value <= 0.5 * rmax:
return Grade.A
else:
return Grade.F
@staticmethod
def get_min_edge_contrast_grade(score):
if score >= 15:
return Grade.A
else:
return Grade.F
@staticmethod
def get_symbol_contrast_grade(score):
if score >= 70:
return Grade.A
elif score >= 55:
return Grade.B
elif score >= 40:
return Grade.C
elif score >= 20:
return Grade.D
else:
return Grade.F
@staticmethod
def get_modulation_grade(score):
if score >= 0.7:
return Grade.A
elif score >= 0.6:
return Grade.B
elif score >= 0.5:
return Grade.C
elif score >= 0.4:
return Grade.D
else:
return Grade.F
@staticmethod
def get_defects_grade(score):
if score <= 0.15:
return Grade.A
elif score <= 0.2:
return Grade.B
elif score <= 0.25:
return Grade.C
elif score <= 0.3:
return Grade.D
else:
return Grade.F
@staticmethod
def get_decodability_grade(score):
return Grade.A
@staticmethod
def get_decode_grade(score):
return Grade.A
@staticmethod
def get_barcode_grade(score):
if score < 0.5:
return Grade.F
elif score < 1.5:
return Grade.D
elif score < 2.5:
return Grade.C
elif score < 3.5:
return Grade.B
else:
return Grade.A