Reference

class datasets18xx.Dataset18xx(db, game, conf)

Class to maintain a dataset for a given 18xx game. The class is used to access the raw transcript and processed result files.

Parameters:
  • db (Path) – Path to the database.

  • game (Games) – The game to load the dataset.

  • conf (DatasetConfig) – The dataset config.

game

The game to load the dataset.

conf

The dataset config.

root

The root folder of the dataset.

context(valid_only=False)

Get the transcript context.

Parameters:

valid_only (bool) – To only include valid transcripts.

Return type:

DataFrame

Returns:

The dataframe containing individual transcript contexts.

static from_db(root)

Build dataset from dataset root.

Parameters:

root (Path) – The root of the dataset.

Return type:

Dataset18xx

Returns:

The corresponding dataset.

inspect()

Create and write a snapshot of the dataset.

Return type:

dict

Returns:

The snapshot including sizes, distributions, debug data.

load(game_id)

Load a transcript context.

Parameters:

game_id (int) – The game id to load context from.

Return type:

TranscriptContext

Returns:

The transcript context to analyse result or metadata.

Raises:

ValueError – If game id does not exist of transcript is invalid.

make(force=False)

Invokes the transcript parser on the raw transcripts.

Parameters:

force (bool) – Enforce parsing of valid transcripts without errors such as failed verification, missing game finish. Otherwise, only transcripts with noted failures will be parsed.

Return type:

DataFrame

Returns:

The parsed dataset context.

prune()

Delete processed data from the dataset.

subset(conf)

Create a subset of the current dataset.

The subset can be created based on the full dataset, not on a subset. Can filter number of players and/or game endings.

Parameters:

conf (DatasetConfig) – The dataset config, i.e. number of players, game endings to keep.

Return type:

Dataset18xx

Returns:

The new dataset instance.

class datasets18xx.DatasetConfig(num_players=None, game_ending=None)

Data class implements available filters for the full dataset.

num_players

Set of number of players in a game to include as int.

game_ending

Set of game endings to include, see GameEnding.

static from_cli(np=None, ge=None)

Create dataset configuration from CLI inputs.

Parameters:
  • np (tuple[int]) – Number of players definition, default is None.

  • ge (tuple[GameEnding]) – Game endings for configuration, default is None.

Return type:

DatasetConfig

Returns:

The dataset config based on number of players and game ending.

static from_db(dir_name)

Build config from dataset directory name.

Parameters:

dir_name (str) – Name of the dataset directory.

Return type:

DatasetConfig

Returns:

Corresponding dataset config.

game_ending: set = None
num_players: set = None
query()

Construct a query for a dataframe based on config.

Return type:

str

Returns:

The query to search for num_players and game_ending in context.

suffix()

Create the suffix for the dataset name based on the config.

Return type:

str

Returns:

The suffix, i.e. number of players and game endings. E.g, 4p_BankBroke or 3p4p_BankBroke_PlayerGoesBankrupt.

class datasets18xx.DefaultDatasetConfig(num_players=None, game_ending=None)

Dataclass implements the default config for the full dataset.

game_ending: set = None
num_players: set = None
class datasets18xx.GameEnding(value)

Enum class implements the available game endings.

BankBroke = 2
GameEndedManually = 4
NotFinished = 1
PlayerGoesBankrupt = 3
static argparse(game_end)

Maps the game ending to its enum member.

Parameters:

game_end (str) – The enum member name as string.

Returns:

The enum member matching to the string.

Raises:

ValueError – If ending is not found in the enum.

datasets18xx.database()

Read database exported as environment variable DATABASE.

Return type:

Path

Returns:

The exported database, or default is env variable is not set.

datasets18xx.default_database()

The default location of the database.

Return type:

Path

Returns:

The default location of the database.

datasets18xx.make_config(num_players=None, game_ending=None)

Create dataset configuration.

Parameters:
  • num_players (tuple[int]) – Number of players definition.

  • game_ending (tuple[GameEnding]) – Game endings for configuration.

Return type:

DatasetConfig

Returns:

The dataset config based on number of players and game ending.

datasets18xx.make_dataset(game=Games.G1830, conf=<class 'datasets18xx.core.config.DefaultDatasetConfig'>)

Create a dataset object.

Parameters:
  • game (Games) – The game to load the dataset.

  • conf (DatasetConfig) – The dataset config.

Return type:

Dataset18xx

Returns:

Dataset instance for game with given database and config.