Collection Management
Manager
Card collection management module.
This module provides functionality for managing a local collection of Netrunner cards, including tracking owned cards, packs, and missing cards.
- Classes:
CollectionManager: Main class for managing card collections. CardRequirement: Represents a card requirement from a decklist. CollectionError: Custom exception for collection errors.
- Protocols:
APIClient: Protocol for API client dependency injection.
- class simulchip.collection.manager.CollectionData[source]
Bases:
TypedDict
Type definition for collection file structure.
This represents the structure of the collection TOML file.
- packs
List of pack codes that are fully owned.
- owned_packs
List of pack codes that are owned (new format).
- cards
Dictionary mapping card codes to quantities owned.
- missing
Dictionary mapping card codes to quantities marked as missing.
- class simulchip.collection.manager.PackSummary[source]
Bases:
TypedDict
Type definition for pack summary statistics.
- owned
Number of unique cards owned from this pack.
- total
Total number of unique cards in this pack.
- exception simulchip.collection.manager.CollectionError[source]
Bases:
Exception
Custom exception for collection-related errors.
- message
Error message describing what went wrong.
- file_path
Path to the collection file if applicable.
- class simulchip.collection.manager.CardRequirement[source]
Bases:
object
Represents a card requirement from a decklist.
This class tracks how many copies of a card are required by a decklist and how many are available in the collection.
- code
Card code (e.g., “01001”).
- required
Number of copies required by the decklist.
- owned
Number of copies owned in the collection.
- missing
Number of additional copies needed.
- Properties:
is_satisfied: True if owned >= required.
Examples
>>> req = CardRequirement("01001", required=3, owned=2, missing=1) >>> req.is_satisfied False
- class simulchip.collection.manager.APIClient[source]
Bases:
Protocol
Protocol for API client interface.
- __init__(*args, **kwargs)
- class simulchip.collection.manager.CollectionManager[source]
Bases:
object
Manages local card collection data with validation and functional patterns.
- __post_init__()[source]
Initialize and load collection after dataclass initialization.
- Return type:
- load_collection()[source]
Load collection from file with validation.
- Raises:
CollectionError – If file format is unsupported or data is invalid
- Return type:
- save_collection()[source]
Save collection to file with atomic write.
- Raises:
CollectionError – If save fails
- Return type:
- modify_card_count(card_code, delta, target)[source]
Modify card count with validation (functional helper).
- analyze_decklist(decklist)[source]
Analyze decklist requirements against collection.
- get_pack_summary(api_client)[source]
Get collection summary by pack with functional approach.
- Parameters:
api_client (
APIClient
) – NetrunnerDB API client- Return type:
- Returns:
Dictionary mapping pack codes to statistics
- add_pack(pack_code)[source]
Add all cards from a pack to collection.
- Raises:
ValueError – If pack_code is invalid
- Return type:
- Parameters:
pack_code (str)
- remove_pack(pack_code)[source]
Remove all cards from a pack from collection.
- Raises:
ValueError – If pack is not owned
- Return type:
- Parameters:
pack_code (str)
- get_card_difference(card_code)[source]
Get card difference from expected (positive = extra, negative = missing).
- get_all_cards_with_differences()[source]
Get all cards with their expected counts and differences.
- Returns:
int, ‘difference’: int, ‘actual’: int}
- Return type:
Dict mapping card codes to {‘expected’
- get_statistics()[source]
Calculate collection statistics.
- Returns:
owned_packs: Number of owned packs
unique_cards: Number of unique cards owned
total_cards: Total number of cards (counting duplicates)
missing_cards: Total number of missing cards
- Return type:
Dictionary with statistics
- __init__(collection_file=None, api=None, owned_packs=<factory>, card_diffs=<factory>, collection=<factory>, missing_cards=<factory>)
Operations
Collection operations and utilities.
This module provides utility functions for collection management that are used by the CLI but should be in the library.
- simulchip.collection.operations.get_reset_items(collection_path)[source]
Get list of items that would be reset.
- simulchip.collection.operations.get_or_create_manager(collection_file, api, all_cards=False)[source]
Get or create a collection manager with appropriate settings.
- Parameters:
collection_file (
Optional
[Path
]) – Path to collection file (can be None)api (
NetrunnerDBAPI
) – NetrunnerDB API instanceall_cards (
bool
) – If True, use empty collection (ignore existing collection)
- Return type:
- Returns:
CollectionManager instance
- simulchip.collection.operations.sort_cards_by_title(cards_dict)[source]
Sort cards by title for consistent display.
- simulchip.collection.operations.get_packs_by_release_date(api, newest_first=True)[source]
Get packs sorted by release date.
- Parameters:
api (
NetrunnerDBAPI
) – NetrunnerDB API instancenewest_first (
bool
) – If True, sort newest first
- Return type:
- Returns:
List of pack data sorted by release date