A room summary starts with the alignment flag. For each record in the public StagingBench data, the flag can say that automatic alignment passed, that it failed, or that the outcome was unrecorded. Python can represent those three states as True, False, and None. A Counter can use those values as keys, so each record increments its own outcome. An expression such as if aligned would put False and None on the same branch and lose the distinction between failure and missing information.
The embedded dataset contains all 51 records for four selected rooms. Each tuple holds the room identifier, anonymous tool identifier, and decoded flag value in that order. Room 01 is the open plan kitchen and living area, room 04 is the attic with odd windows, room 08 is the loft kitchen with ducts, and room 09 is the small white room with double doors. Room 08 contributes 12 records and each of the other selected rooms contributes 13.
Use defaultdict(Counter) to create a counter when a room first appears. The loop unpacks the tool identifier because it is part of each source record. The aggregation uses the room and the flag, adding one observation per tuple. A Counter returns zero when a key has never been counted, so the print loop can access all three states directly, including the unknown count for rooms whose flags are all present.
Keep the room identifiers as strings to retain their leading zeroes. Since the identifiers have the same width, sorting the dictionary items puts them in room order. The format strings align the labels and numbers so that even a room with several zeroes can be read across the same columns as the others.
If you adapt the example to read the full data as CSV with csv.DictReader, map the strings "True", "False", and "" explicitly to True, False, and None. CSV fields arrive as strings, and bool("False") evaluates to True because the string is nonempty. A record with a blank flag contributes to Unknown. An absent record contributes nothing to the counter, which is why room 08 totals 12.
The printed rows show two different cases with zero failures. Room 01 has nine unknowns and four passes, while room 08 has a recorded pass for every row present. Room 04 has nine failures and four passes. Room 09 has 13 failures, so all its drift scores are fallbacks and cannot be compared with aligned drift scores. The counts show which photographs account for repeated failures. The cause is unknown from the data.
from collections import Counter, defaultdict
records = [
("01", "T01", None),
("04", "T01", False),
("08", "T01", True),
("09", "T01", False),
("01", "T02", None),
("04", "T02", False),
("08", "T02", True),
("09", "T02", False),
("01", "T03", None),
("04", "T03", False),
("08", "T03", True),
("09", "T03", False),
("01", "T04", None),
("04", "T04", False),
("08", "T04", True),
("09", "T04", False),
("01", "T05", None),
("04", "T05", False),
("08", "T05", True),
("09", "T05", False),
("01", "T06", None),
("04", "T06", True),
("08", "T06", True),
("09", "T06", False),
("01", "T07", True),
("04", "T07", False),
("08", "T07", True),
("09", "T07", False),
("01", "T08", None),
("04", "T08", True),
("08", "T08", True),
("09", "T08", False),
("01", "T09", True),
("04", "T09", False),
("08", "T09", True),
("09", "T09", False),
("01", "T10", True),
("04", "T10", True),
("08", "T10", True),
("09", "T10", False),
("01", "T11", True),
("04", "T11", False),
("08", "T11", True),
("09", "T11", False),
("01", "T12", None),
("04", "T12", True),
("09", "T12", False),
("01", "T13", None),
("04", "T13", False),
("08", "T13", True),
("09", "T13", False),
]
counts_by_room = defaultdict(Counter)
for room, tool, aligned in records:
counts_by_room[room][aligned] += 1
print(f"{'Room':<4} {'Failed':>6} {'Passed':>6} {'Unknown':>7}")
for room, counts in sorted(counts_by_room.items()):
print(f"{room:<4} {counts[False]:>6} {counts[True]:>6} {counts[None]:>7}")
Output:
Room Failed Passed Unknown
01 0 4 9
04 9 4 0
08 0 12 0
09 13 0 0
Top comments (0)