Skip to content

Commit 012e801

Browse files
committed
Write method to write interactions to dictionary.
1 parent 4de9c7a commit 012e801

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

axelrod/tournament.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,14 @@ def _run_serial(self, progress_bar=False):
154154
return True
155155

156156
def _write_interactions(self, results):
157-
"""Write the interactions to csv."""
157+
"""Write the interactions to file or to a dictionary"""
158+
if self.interactions_dict is not None:
159+
self._write_to_dict(results)
160+
elif self.writer is not None:
161+
self._write_to_file(results)
162+
163+
def _write_to_file(self, results):
164+
"""Write the interactions to csv file"""
158165
for index_pair, interactions in results.items():
159166
for interaction in interactions:
160167
row = list(index_pair)
@@ -167,6 +174,16 @@ def _write_interactions(self, results):
167174
self.writer.writerow(row)
168175
self.num_interactions += 1
169176

177+
def _write_to_dict(self, results):
178+
"""Write the interactions to memory"""
179+
for index_pair, interactions in results.items():
180+
for interaction in interactions:
181+
try:
182+
self.interactions_dict[index_pair].append(interaction)
183+
except KeyError:
184+
self.interactions_dict[index_pair] = [interaction]
185+
self.num_interactions += 1
186+
170187
def _run_parallel(self, processes=2, progress_bar=False):
171188
"""
172189
Run all matches in parallel

0 commit comments

Comments
 (0)