-
Notifications
You must be signed in to change notification settings - Fork 0
/
horario.py
executable file
·109 lines (105 loc) · 4.57 KB
/
horario.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
class Horario(object):
'''
Objeto para guardar el horario de una actividad
TODO: Quizas seria mas legible si fuese este formato:
{'horarios': {{'initHour':'10'}: [{'endHour':'11'}, {'quota':'3'}, {'participants':set(['351519348', '35151938', '3515204597'])]}}, 'name': 'Bldy'}
Quota is 1 as default
'''
def __init__(self,activity,initHour,endHour,quota='1',participant=None):
appointment = {}
turnos = {}
if participant is not None:
if type(participant) is str: # If it is only one number, create a list
participant = [participant]
if len(participant) > int(quota):
return "Message: Quota is smaller than participants' number"
else:
participantSet = set(participant)
else:
participantSet = set([])
appointment[initHour] = [endHour,quota,participantSet] #TAG_1
turnos[activity] = appointment
self.name = activity
self.horarios = turnos[activity]
def addParticipant(self,initHour,participant):
'''
Method to add a participant to an appointment
Params: initHour, participant
participant: It is the participant's telephone number
'''
_, qota, participants = self.horarios[initHour] # Look to TAG_1
try:
message = 'Message: adding {} ... '.format(participant)
message += "Inscriptos: {}".format(participants)
totalP = str(len(participants))
if type(participant) is str:
participant = [participant]
newP = len(participant)
print(qota,totalP)
if totalP == qota:
message += '\nFailed: Turno completo, no se puede inscribir'
print(message)
elif (newP + int(totalP)) > int(qota):
message += "\nFailed: No puede reservar {} lugare/s".format(str(newP))
message += ", la disponibilidad es de {}".format((str(int(qota)-int(totalP))))
print(message)
else:
print("entra al else de addParticipant, la quota es: {}".format(qota))
self.horarios[initHour][2].update(participant)
message += "Success:{} has been added".format(participant)
# message += """ at {}\n""".format(initHour)
# message += "AdminMessage: {} participants"
# message += "in {4} at {5}"
# message.format(participant,self.name,initHour)
except KeyError as e:
message = "Message: There is no appointment for {} at {}".format(self.name, initHour)
print(message)
finally:
print(message)
return message
def addAppointment(self,initHour,endHour,quota='1', participant=None):
'''
Params: initHour, endHour,quota
'''
if participant == None:
participantSet = set([])
elif type(participant) is str: # Only one element given
participantSet = set([participant])
else:
participantSet = set(participant)
self.horarios[initHour] = [endHour,quota,participantSet]
def removeParticipant(self,initHour,participant):
'''
Method to remove a participant from a given appointment
Params: initHour, participant
participant: It is the participant's telephone number,
it can be a set, a list, or a string
'''
message = ''
try:
if type(participant) is str: # It is only one number
print("tb es str")
participant = set([participant])
elif type(participant) is list:
participant = set(participant)
newPart = self.horarios[initHour][2] - participant # new participants' set
self.horarios[initHour][2] = newPart # update set
if participant == set([]):
message = "Message: {} has been removed at {}".format(participant, initHour)
except KeyError as e:
message = "Message: {} has no appointment to {} at {}".format(participant,self.name, initHour)
except Exception as e: # Is this catch all error needed?
message = "Message: Exception for catch all error"
raise e
finally:
return message
def deleteAppointment(self,initHour):
"""
Method to delete the appointment for initHour
"""
try:
message = self.horarios.pop(initHour)
except Exception as e:
raise e
finally:
return message