-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShavtzak.py
More file actions
206 lines (168 loc) · 6.04 KB
/
Shavtzak.py
File metadata and controls
206 lines (168 loc) · 6.04 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
from random import shuffle
import time
from Position import Position # Assuming Position class is defined in a separate module
class Shavtzak:
def __init__(self, hour, minute):
"""
Initialize a Shavtzak instance.
Parameters:
- hour: Starting hour for the Shavtzak.
- minute: Starting minute for the Shavtzak.
"""
self.hour = hour
self.minute = minute
self.guardList = [] # List to store guards
self.positionList = [] # List to store positions
self.time = [] # List to store time intervals
def addGuard(self, name):
"""
Add a guard to the Shavtzak's guard list.
Parameters:
- name: Name of the guard to be added.
Returns:
- True if the guard was successfully added.
- False if the guard already exists.
"""
if name not in self.guardList:
self.guardList.append(name)
return True
else:
return False
def deleteGuard(self, name):
"""
Delete a guard from the Shavtzak's guard list.
Parameters:
- name: Name of the guard to be deleted.
Returns:
- True if the guard was successfully deleted.
- False if the guard does not exist.
"""
if name in self.guardList:
self.guardList.remove(name)
return True
else:
return False
def randomOrder(self):
"""
Shuffle the order of guards randomly.
"""
shuffle(self.guardList)
def addPosition(self, position):
"""
Add a position to the Shavtzak's position list.
Parameters:
- position: Instance of the Position class to be added.
Returns:
- True if the position was successfully added.
- False if the position with the same name already exists.
"""
if position.name not in [p.name for p in self.positionList] and position.guardingTime % 5 ==0:
self.positionList.append(position)
return True
else:
return False
def deletePosition(self, name):
"""
Delete a position from the Shavtzak's position list.
Parameters:
- name: Name of the position to be deleted.
Returns:
- True if the position was successfully deleted.
- False if the position does not exist.
"""
for position in self.positionList:
if position.name == name:
self.positionList.remove(position)
return True
return False
def createGuardsList(self):
"""
Create a schedule for guards based on positions and time intervals.
"""
self.randomOrder()
self.createClock()
indexGuard = 0
for position in self.positionList:
position.clearGuards()
for i in range(len(self.time)):
for j in range(len(self.positionList)):
if self.positionList[j].timeToSwitch():
str = self.time[i] + " "
for z in range(0, self.positionList[j].numOfGuards):
if z == self.positionList[j].numOfGuards -1:
str += self.guardList[indexGuard]
else:
str += self.guardList[indexGuard] + ", "
indexGuard += 1
if indexGuard == len(self.guardList):
indexGuard = 0
self.positionList[j].addGuard(str)
self.positionList[j].pass5Minutes()
def createClock(self):
"""
Create a clock with time intervals at 5-minute intervals.
"""
increaseHour = self.hour
increaseMinute = self.minute
count24 = 0
while count24 < 24:
# Check if the minute reaches 60 and reset it to 0
if increaseMinute == 60:
increaseMinute = 0
increaseHour += 1
count24 += 1
# Check if the hour reaches 24 and reset it to 0
if increaseHour == 24:
increaseHour = 0
# Append the current hour and minute as a string to the time list
self.time.append(f"{increaseHour:02d}:{increaseMinute:02d}")
increaseMinute += 5
def printGuardsList(self):
"""
Print the list of guards in the Shavtzak.
"""
print(self.guardList)
def printPositionsList(self):
"""
Print the list of positions in the Shavtzak.
"""
for i in self.positionList:
print(f'{i.name} ')
def printShavtzak(self):
"""
Print the guards assigned to each position in the Shavtzak.
"""
for position in self.positionList:
print(position.name)
print(position.guardList)
def main():
# Create instances of Shavtzak
shavtzak_instance = Shavtzak(18, 00)
# Add guards to Shavtzak
shavtzak_instance.addGuard("Guard1")
shavtzak_instance.addGuard("Guard2")
shavtzak_instance.addGuard("Guard3")
shavtzak_instance.addGuard("Guard4")
shavtzak_instance.addGuard("Guard5")
shavtzak_instance.addGuard("Guard6")
shavtzak_instance.addGuard("Guard7")
shavtzak_instance.addGuard("Guard8")
shavtzak_instance.addGuard("Guard9")
# Add positions to Shavtzak
position1 = Position("Position1", 1, 60)
position2 = Position("Position2", 2, 90)
position3 = Position("Position3", 2, 90)
shavtzak_instance.addPosition(position1)
shavtzak_instance.addPosition(position2)
shavtzak_instance.createGuardsList()
# shavtzak_instance.printPositionsList()
shavtzak_instance.printShavtzak()
# shavtzak_instance.printGuardsList()
print("--------")
shavtzak_instance.deletePosition("Position2")
shavtzak_instance.deleteGuard("Guard1")
shavtzak_instance.createGuardsList()
shavtzak_instance.printShavtzak()
# shavtzak_instance.printPositionsList()
if __name__ == "__main__":
main()