/
session.py
90 lines (64 loc) · 1.7 KB
/
session.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
'''
Session object is used to store either
AM or PM session.
'''
class Session(object):
def __init__(self, time_allocated):
self.time_allocated = time_allocated
self.remaining = time_allocated
self.talks = []
'''
Append 'talk' to current list of talks and
update our remaining minutes. Return False
if the duration of the talk is too long to
fit in this session
'''
def append(self, talk):
if self.remaining >= talk.duration:
self.talks.append(talk)
self.remaining = self.remaining - talk.duration
return True
else:
return False
'''
Session is full. Not accepting anymore talks
'''
def is_full(self):
return self.remaining == 0
'''
Returns a count of the talks in this session
'''
def talk_count(self):
return len(self.talks)
'''
To be implemented by subclass based on their
own constraints
'''
def is_valid(self):
raise NotImplementedError
'''
Number of minutes used by the talks already
added to this session
'''
def total_talk_duration(self):
return self.time_allocated - self.remaining
'''
For this session to be valid, the requirement is that
it has to be fully filled with no gaps. So 'self.remaining'
has to be 0 in order for an AM session to be valid.
'''
class AMSession(Session):
def is_valid(self):
return self.remaining == 0
'''
For the case of the PM session, we have the choice of
allowing it to end as follows:
4PM <= end time <= 5PM
which means, 180 <= self.remaining <= 240
'''
class PMSession(Session):
def __init__(self, time_allocated, minimum_duration):
self.minimum_duration = minimum_duration
super(PMSession, self).__init__(time_allocated)
def is_valid(self):
return self.total_talk_duration() > self.minimum_duration