-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
55 lines (40 loc) · 1.42 KB
/
models.py
File metadata and controls
55 lines (40 loc) · 1.42 KB
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
class Photo:
def __init__(self, id: int, tags: set, horizontal: bool):
self.id = id
self.tags = tags
self.horizontal = horizontal
def __str__(self):
return "%d(%s,%s)" % (self.id, "H" if self.horizontal else "V", str(self.tags))
def __repr__(self):
return str(self)
class Slide:
def __init__(self, photo1, photo2 = None):
self.photo1 = photo1
self.photo2 = photo2
if photo2 is None:
self.tags = self.photo1.tags.copy()
else:
self.tags = photo1.tags | photo2.tags
def interest_factor(self, other_slide):
common_tags = self.tags & other_slide.tags
common_score = len(common_tags)
first_score = len(self.tags) - common_score
second_score = len(other_slide.tags) - common_score
return min(common_score, first_score, second_score)
def to_output_file(self):
if self.photo2 is None:
return str(self.photo1.id)
else:
return str(self.photo1.id) + " " + str(self.photo2.id)
class SlideShow:
def __init__(self):
self.slides = []
def append(self, slide):
self.slides.append(slide)
def score(self):
points = 0
for ind in range(len(self.slides) - 1):
first = self.slides[ind]
second = self.slides[ind + 1]
points += first.interest_factor(second)
return points