-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad_validator.py
50 lines (40 loc) · 1.52 KB
/
ad_validator.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
from typing import Tuple, Dict
from ad import Ad
from counter import Counter
from metro import Metro
class AdValidator:
def __init__(self, ad: Ad, counter: Counter, descriptions: Dict[str, bool]):
self.descriptions = descriptions
self.counter = counter
self.ad = ad
@staticmethod
def validate_coordinate(point: Tuple[float, float], counter: Counter) -> bool:
station = Metro.get_closest(point)
if station.distance_to(point) < 1000:
return True
counter.too_far()
return False
def validate(self) -> bool:
if self.ad.get_description() in self.descriptions:
self.counter.duplicate()
print(self.ad.id + ' is a duplicate...........')
return False
else:
self.descriptions[self.ad.get_description()] = True
if Metro.get_closest(self.ad.get_coord()).distance() > 1000:
self.counter.too_far()
print(self.ad.id + ' is too far...........')
return False
if self.ad.bedrooms_count() < 2:
self.counter.wrong_size()
print(self.ad.id + ' is too small...........')
return False
if self.ad.is_basement():
self.counter.basement()
print(self.ad.id + ' is basement...........')
return False
if self.ad.is_nothing_included():
self.counter.nothing_included()
print(self.ad.id + ' is nothing included...........')
return False
return True