Skip to content

Commit d7ae781

Browse files
Update Hivemind.py
1 parent 6bac3d9 commit d7ae781

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

hive/app/domain/Hivemind.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,35 @@ def __read_shared_file_bytes(self, shared_file_path):
8888
Hivemind.MY_SHARED_FILES[shared_file_name] = shared_file_parts
8989

9090
def __filter_and_map_living_workers(self):
91+
"""
92+
Filters all worker items(key:val) from the worker_status dict known to this hivemind who have Status.Online
93+
:returns list<domain.Worker>: a list containing only the keys (workers, w/o their status) returned by the filter
94+
"""
9195
filtered_items = [*filter(lambda item: item[1] == Status.ONLINE, self.worker_status.items())]
9296
return [*map(lambda a_worker: a_worker[0], filtered_items)]
9397

94-
def __kill_phase(self, living_workers):
98+
def __kill_phase(self, workers):
99+
"""
100+
:param workers: collection of workers that are known to be online
101+
:type list<domain.Worker>
102+
"""
95103
cc = self.casualty_chance
96104
if self.multiple_casualties_allowed:
97-
targets = [*filter(lambda dw: np.random.choice([True, False], p=[cc, 1 - cc]), living_workers)]
105+
targets = [*filter(lambda dw: np.random.choice([True, False], p=[cc, 1 - cc]), workers)]
98106
for target in targets:
99107
self.__kill_worker(target, clean_kill=False)
100108
else:
101109
if np.random.choice([True, False], p=[cc, 1 - cc]):
102-
target = np.random.choice(living_workers)
110+
target = np.random.choice(workers)
103111
self.__kill_worker(target, clean_kill=False)
104112

105113
def __kill_worker(self, target, clean_kill=True):
114+
"""
115+
:param target: worker who is going to be removed from the simulation network
116+
:type domain.Worker
117+
:param clean_kill: When True worker will ask for his files to be redistributed before leaving the network
118+
:type bool
119+
"""
106120
if clean_kill:
107121
target.leave_hive(orderly=True)
108122
else:

0 commit comments

Comments
 (0)