-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced
utils.py
, including get_all_rounds
function
- Loading branch information
1 parent
faca65c
commit bbec95c
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .structures import * | ||
from .structures import * | ||
from .utils import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""Various utilities to aid in the manipulation and analysis of the objects in `debaterpy.structures`.""" | ||
from .structures import * | ||
from typing import Generator, Callable | ||
|
||
|
||
def get_all_rounds(record: Record, function: Callable[[Tournament, Round], bool] = lambda x, y: True)\ | ||
-> Generator[Round, None, None]: | ||
"""Gets all the rounds `record` for which `function` returns `True`. | ||
This allows easier access to all the data such as for analysis of speaks or winrates. The `function` argument | ||
behaves similarly to Python's built-in `filter`, it only allows entries for which `function(x, y)` is `True`. For | ||
example, the following code will get all rounds in BP (which might be useful for splitting up analyses by format): | ||
>>> get_all_rounds(record, lambda x, y: x.format == "BP") | ||
<generator object get_all_rounds at 0x102861e40> | ||
Args: | ||
record: An instance of `structures.Record` from which the rounds will be extracted. | ||
function: A callable returning a boolean which needs to be true for a record to be included. Receives instances | ||
of `structures.Tournament` and `structures.Round`as arguments. Will default to including all rounds.""" | ||
for tournament in record.tournaments: | ||
for round in tournament.rounds: | ||
if function(tournament, round): | ||
yield round |