-
Notifications
You must be signed in to change notification settings - Fork 0
/
blacklistitem.py
153 lines (116 loc) · 4.27 KB
/
blacklistitem.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from helper import coords_min, relocate, calc_coord
from pattern import Pattern
# An entry in the blacklist. Can be matched against a lotto tipp to device
# if it should be discarded. Defined as a form of visual pattern.
class BlacklistItem:
# name: Name of the item to see why it was discarded
# coords: One up to six coords [[x, y], ...] of the pattern, values zero to six
# misses: Amount of coords that don't have to match
# transformations: List of transformations that should be applied to the
# pattern before testing. L, R - Rotate. F - Flip. M - Mirror: ["R", "F"]
def __init__(self, name, coords, misses = 0, transformations = []):
self.name = name
self.misses = misses
# Make sure it starts at 0x0
min_coord = coords_min(coords)
coords = relocate(coords, min_coord)
self.main_pattern = Pattern(name, coords, misses)
self.patterns = [self.main_pattern]
self.transformations = transformations
self._perform_transformations()
def _perform_transformations(self):
for r in self.transformations:
rotated_coords = r.perform(self.get_coords())
min_coord = coords_min(rotated_coords)
relocated = relocate(rotated_coords, min_coord)
self.patterns.append(Pattern(self.name +" "+ r.get_suffix(), relocated, self.misses))
self.patterns = list(dict.fromkeys(self.patterns)) # reduce duplicates
def get_name(self):
return self.name
def get_coords(self):
return self.main_pattern.get_coords()
def get_patterns(self):
return self.patterns
def get_main_pattern(self):
return self.patterns[0]
def get_misses(self):
return self.misses
def matches(self, tipp):
for p in self.patterns:
if p.matches(tipp):
return True
return False
def __str__(self):
return self.str_pretty(1)
def str_pretty(self, verbosity = 1):
s = ''
if verbosity > 0:
if verbosity == 1:
s += self.patterns[0].str_pretty(verbosity)
if verbosity > 1:
for p in self.patterns:
s += p.str_pretty(verbosity)
return s
# Blacklist item entry, matches litteraly/directly entered numbers as opposed to patterns.
# Used for example famous numbers.
class BlacklistItemDirect:
# numbers: [1,2,3,4,5,6]
def __init__(self, name, numbers, misses = 0):
self.name = name
self.misses = misses
self.numbers = numbers
def get_name(self):
return self.name
def get_coords(self):
return [calc_coord(int(number)) for number in self.numbers]
def get_misses(self):
return self.misses
def matches(self, tipp):
matches = 0
for p in self.numbers:
if p in tipp.numbers():
matches += 1
return matches >= (len(self.numbers) - self.misses)
def __str__(self):
return self.str_pretty(1)
def str_pretty(self, verbosity = 1):
s = ''
if verbosity > 0:
s += ' '.join(['%2d' % e for e in self.numbers])
return s
# Matches tipps that likely look like a date
class BlacklistItemDate:
def __init__(self):
self.name = 'date'
def get_name(self):
return self.name
def get_coords(self):
return []
def get_misses(self):
return 0
def matches(self, tipp):
numbers = tipp.numbers()
if not 19 in numbers and not 20 in numbers and not 21 in numbers:
return False
anylt13 = any(num <= 12 for num in numbers)
# no month specified
if not anylt13:
return False
# Recognize day-like numbers
le31 = sum(num <= 31 for num in numbers)
# If 19(xx) is present just require le31to be three, the year might be
# larger than 20
if 19 in numbers:
has_gt_20 = any(num >= 20 for num in numbers)
if le31 >= 3 and has_gt_20:
return True
elif le31 >= 4:
return True
return False
def __str__(self):
return self.str_pretty(1)
def str_pretty(self, verbosity = 1):
s = ''
if verbosity > 0:
s += 'date'
return s