From: Plom Heller Date: Tue, 21 Apr 2026 23:24:12 +0000 (+0200) Subject: Add helper for collection unpacking. X-Git-Url: https://plomlompom.com/repos/%22https:/validator.w3.org/static/booking?a=commitdiff_plain;h=72dd6633b159a1003859a1e79bf98e2713bc9fe9;p=bricksplom Add helper for collection unpacking. --- diff --git a/bricksplom.py b/bricksplom.py index ddaaf93..b42fb61 100755 --- a/bricksplom.py +++ b/bricksplom.py @@ -193,14 +193,6 @@ class Collection(Textfiled): for page in v[1])) for k, v in collected.items()} - def piece_ids(self) -> tuple[str, ...]: - 'Flattened, alphabetically sorted list of recorded piece IDs.' - collected: list[str] = [] - for page in self.piece_listings: - for column in page: - collected += [p_id for _, p_id, _ in column] - return tuple(sorted(collected)) - def __str__( self ) -> str: @@ -215,6 +207,34 @@ class Collection(Textfiled): pages += ['\n -\n'.join(columns)] return f'\n{self.id_} {self.description}\n' + ' =\n'.join(pages) + def piece_listings_flat(self) -> tuple[PieceListing, ...]: + 'Flattened variant of .piece_listings, no division into pages/cols.' + collected: list[PieceListing] = [] + for page in self.piece_listings: + for column in page: + collected += list(column) + return tuple(collected) + + def print_unpacking_instructions( + self, + pieces: dict[str, 'Piece'], + designs: dict[str, 'Design'], + boxes: dict[str, 'Box'] + ) -> None: + 'Print helper for collecting from boxes all pieces of self.' + lines = [] + for count, piece_id, _ in self.piece_listings_flat(): + piece = pieces[piece_id] + design = Design.possibly_by_alt(piece.design_id, designs) + assert design is not None + description = design.description + box = [b for b in boxes.values() if design.id_ in b.designs][0] + idx_in_box = box.designs.index(design.id_) + lines += [f'{box.id_:>2}:{idx_in_box:>2} ' + f'{count}× {piece.color_id:>3} {description}'] + for line in sorted(lines): + print(line) + class Box(Textfiled): 'Order of designs.' @@ -252,7 +272,7 @@ def check_consistencies_between_tables( # check all items listed in collections recorded in pieces for coll in collections.values(): - for piece_id in coll.piece_ids(): + for _, piece_id, _ in coll.piece_listings_flat(): assert piece_id in pieces, piece_id # check all designs listed in boxes recorded in designs