Rule each dimension in the paired ruling, and count a better ruling as worse when a dimension it rules fallen is under the floor
This commit is contained in:
+37
-12
@@ -1,7 +1,7 @@
|
||||
import decimal
|
||||
import re
|
||||
|
||||
from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS
|
||||
from larv_review.seats import DIMENSIONS, FIRST_SEATS, Seat, SPLIT_SEATS, vote_line
|
||||
from larv_review.history import entries, Entry, HistoryChange, PLACE
|
||||
from failure import Failure
|
||||
from rank_todo import Item, ITEMS_HEADER, parse_row, table_rows
|
||||
@@ -13,18 +13,26 @@ ROUND = re.compile(r"^Answer (.+?) round ([0-9]+):")
|
||||
VOTES = ("better", "same", "worse")
|
||||
|
||||
|
||||
def votes(seats: list[Seat]) -> dict[str, str] | Failure:
|
||||
"""Each seat's vote as it counts: a better or worse vote naming no `path:line` place counts as same."""
|
||||
def votes(seats: list[Seat]) -> dict[str, list[str]] | Failure:
|
||||
"""Each seat's five votes as written, in DIMENSIONS' order."""
|
||||
names = [seat.name for seat in seats]
|
||||
if names[:2] != list(FIRST_SEATS) or names[2:] not in ([], list(SPLIT_SEATS)):
|
||||
return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}")
|
||||
if unknown := [seat for seat in seats if seat.said not in VOTES]:
|
||||
return Failure(f"{unknown[0].name}'s vote {unknown[0].said!r} is not better, same or worse")
|
||||
counted = {seat.name: seat.said if names_a_place(seat) else "same" for seat in seats}
|
||||
first, second, *more = counted.values()
|
||||
return Failure(f"a paired ruling's seats are {' and '.join(FIRST_SEATS)}, then, when their overall votes differ, {' and '.join(SPLIT_SEATS)}, in that order; the file has {', '.join(names) or 'none'}")
|
||||
said = {}
|
||||
for seat in seats:
|
||||
line = vote_line(seat.name, seat.said)
|
||||
if isinstance(line, Failure):
|
||||
return line
|
||||
said[seat.name] = line
|
||||
first, second, *more = (each[-1] for each in counted(seats, said).values())
|
||||
if more and first == second:
|
||||
return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first}, which settles the ruling; drop the other seats' lines")
|
||||
return counted
|
||||
return Failure(f"{' and '.join(FIRST_SEATS)} both count as {first} overall, which settles the ruling; drop the other seats' lines")
|
||||
return said
|
||||
|
||||
|
||||
def counted(seats: list[Seat], said: dict[str, list[str]]) -> dict[str, list[str]]:
|
||||
"""Each seat's votes as they count: a seat naming no `path:line` place counts as same on each."""
|
||||
return {seat.name: said[seat.name] if names_a_place(seat) else ["same"] * len(DIMENSIONS) for seat in seats}
|
||||
|
||||
|
||||
def names_a_place(seat: Seat) -> bool:
|
||||
@@ -41,6 +49,21 @@ def ruling(counted: list[str]) -> str | None:
|
||||
return "same"
|
||||
|
||||
|
||||
def fallen(counted: dict[str, list[str]]) -> list[str]:
|
||||
"""Each dimension, Overall aside, that the seats rule worse by a lead of two."""
|
||||
return [name for name, column in zip(DIMENSIONS[:-1], zip(*counted.values())) if ruling(list(column)) == "worse"]
|
||||
|
||||
|
||||
def pending_fall(history: str) -> list[str]:
|
||||
"""The dimensions that fell in the history's newest entry, when it is a better paired ruling, so no scoring run has followed it. Of entries with one time, the later in the file is newer."""
|
||||
newest = max(enumerate(entries(history)), key=lambda indexed: (indexed[1].time, indexed[0]), default=None)
|
||||
return newest[1].fell if newest and newest[1].ruling == "better" else []
|
||||
|
||||
|
||||
def fell_under_floor(fell: list[str], found: list[decimal.Decimal]) -> list[str]:
|
||||
return [f"{name} {value}" for name, value in zip(DIMENSIONS, found) if name in fell and value < FLOOR]
|
||||
|
||||
|
||||
def means(lines: list[list[str]]) -> list[decimal.Decimal]:
|
||||
"""The mean of each score across the lines, in DIMENSIONS' order, rounded half up to two decimals."""
|
||||
return [mean([decimal.Decimal(score) for score in column]) for column in zip(*lines)]
|
||||
@@ -102,13 +125,15 @@ def plan_items(todo: str) -> list[Item] | Failure:
|
||||
return items
|
||||
|
||||
|
||||
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool) -> list[str] | Failure:
|
||||
"""Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, and landed whether the default branch holds a commit after its newest release tag. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds."""
|
||||
def scoring_run_due(before: list[Item], after: list[Item], ships: list[int], landed: bool, fell: list[str]) -> list[str] | Failure:
|
||||
"""Why the chunk takes a scoring run, empty when it does not. before is the default branch's plan, after the chunk's, ships the IDs it ships, landed whether the default branch holds a commit after its newest release tag, and fell what pending_fall finds in the chunk's history. Work has landed towards an emptied release when the chunk ships one of its items, or when it is the next release, the earliest before names, and landed holds."""
|
||||
plan = {item.id: item for item in before + after}
|
||||
if unknown := sorted(set(ships) - set(plan)):
|
||||
return Failure(f"neither plan holds item {', '.join(map(str, unknown))}")
|
||||
shipped = [plan[id_] for id_ in ships]
|
||||
reasons = [f"ships item {item.id}, which names the comprehension floor" for item in shipped if "comprehension floor" in item.tagline.lower()]
|
||||
if fell:
|
||||
reasons.append(f"has a better paired ruling in which {' and '.join(fell)} fell")
|
||||
next_release = min((item.release for item in before), default=None)
|
||||
for release in emptied(before, after, shipped):
|
||||
if any(item.release == release for item in shipped) or (release == next_release and landed):
|
||||
|
||||
Reference in New Issue
Block a user