home · contact · privacy
Add by-pieces listings to Box.
authorPlom Heller <plom@plomlompom.com>
Wed, 29 Apr 2026 20:29:46 +0000 (22:29 +0200)
committerPlom Heller <plom@plomlompom.com>
Wed, 29 Apr 2026 20:29:46 +0000 (22:29 +0200)
bricksplom.py

index ccb17efa36fdca26c33fd1172114c7e2a4e43ea0..fc1c2c737d0e7e0a8113e6688882ea655ed1a316 100755 (executable)
@@ -44,14 +44,14 @@ class Textfiled(ABC):
             body: str,
             len_expected: int
             ) -> tuple[str, ...]:
-        'Body parsd into left-stripped tokens of len_expected count.'
+        'Body parsed into left-stripped tokens of len_expected count.'
         collected: list[str] = []
         while len(collected) < len_expected:
             body = body.lstrip()
             if len(collected) == len_expected - 1:
                 tok = body
             else:
-                assert CHAR_SPACE in body
+                assert CHAR_SPACE in body, body
                 tok, body = body.split(CHAR_SPACE, maxsplit=1)
             collected += [tok]
         return tuple(collected)
@@ -328,6 +328,27 @@ class Box(Textfiled):
             ) -> str:
         return f'{self.id_:>2} {",".join(self.designs)}'
 
+    def print_pieces(
+            self,
+            pieces: dict[str, 'Piece'],
+            designs: dict[str, 'Design'],
+            colors: dict[str, 'Color'],
+            collections: dict[str, 'Collections']
+            ) -> None:
+        'Print explanatory listings of pieces expected by .designs.'
+        for design_id in self.designs:
+            design = designs[design_id]
+            print(f'=== {design_id:>6}: {design.description} ===')
+            for piece in [p for p in pieces.values()
+                          if p.design_id in {design.id_} | design.alternates]:
+                count_pieces = 0
+                color = colors[piece.color_id]
+                for listings in [c.piece_listings_flat()
+                                 for c in collections.values()]:
+                    for count in [t[0] for t in listings if t[1] == piece.id_]:
+                        count_pieces += count
+                print(f'{count_pieces:>2}× {piece.id_:>7} / {color}')
+
 
 def check_consistencies_between_tables(
         colors: dict[str, Color],
@@ -358,7 +379,7 @@ def check_consistencies_between_tables(
 
     # check all pieces' designs recorded in designs
     for design_id in [piece.design_id for piece in pieces.values()]:
-        assert Design.possibly_by_alt(design_id, designs) is not None
+        assert Design.possibly_by_alt(design_id, designs), design_id
 
     # check all recorded designs have matching pieces (at least via alts)
     for design_id, alts in [(k, v.alternates) for k, v in designs.items()]: