fix(pfs): disappeared confirmed by any later complete year for the status
Some checks failed
CI / lint (push) Successful in 1m3s
CI / notebooks-smoke (push) Successful in 2m28s
Deploy / changes (push) Successful in 18s
CI / test (push) Failing after 4m57s
Infra CI / notebooks (push) Successful in 1m17s
Infra CI / zotero (push) Successful in 40s
Infra CI / docs (push) Successful in 1m49s
Infra CI / api (push) Successful in 1m30s
Deploy / report (push) Has been cancelled
Deploy / notebooks (push) Has been cancelled
Deploy / zotero (push) Has been cancelled
Deploy / docs (push) Has been cancelled
Deploy / api (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Infra CI / mc (push) Has been cancelled
Infra CI / bcda (push) Has been cancelled
Infra CI / llm (push) Has been cancelled
Some checks failed
CI / lint (push) Successful in 1m3s
CI / notebooks-smoke (push) Successful in 2m28s
Deploy / changes (push) Successful in 18s
CI / test (push) Failing after 4m57s
Infra CI / notebooks (push) Successful in 1m17s
Infra CI / zotero (push) Successful in 40s
Infra CI / docs (push) Successful in 1m49s
Infra CI / api (push) Successful in 1m30s
Deploy / report (push) Has been cancelled
Deploy / notebooks (push) Has been cancelled
Deploy / zotero (push) Has been cancelled
Deploy / docs (push) Has been cancelled
Deploy / api (push) Has been cancelled
Deploy / bcda (push) Has been cancelled
Deploy / llm (push) Has been cancelled
Deploy / mc (push) Has been cancelled
Infra CI / mc (push) Has been cancelled
Infra CI / bcda (push) Has been cancelled
Infra CI / llm (push) Has been cancelled
This commit is contained in:
@@ -71,13 +71,20 @@ def status_counts(con: Any) -> dict[tuple[int, str], int]:
|
||||
}
|
||||
|
||||
|
||||
#: A status counts as present in a year when that year holds at least this
|
||||
#: share of the prior year's codes with it. A partial file (an Addendum B,
|
||||
#: not the full RVU file) drops whole statuses; a code vanishing from it is
|
||||
#: not evidence the code left the schedule.
|
||||
#: A status is "complete" in year Z when Z holds at least this share of
|
||||
#: year Z-1's codes with it. A partial file (an Addendum B, not the full
|
||||
#: RVU file) drops whole statuses; a code vanishing from it alone is not
|
||||
#: evidence the code left the schedule.
|
||||
_COMPLETE_SHARE = 0.9
|
||||
|
||||
|
||||
def _status_complete(counts: dict[tuple[int, str], int], year: int, st: str) -> bool:
|
||||
"""``count(year, st) >= 0.9 * count(year - 1, st)``. When the prior
|
||||
year had no such codes (retired status, or one never used) the test is
|
||||
``0 >= 0``, so the status counts as complete."""
|
||||
return counts.get((year, st), 0) >= _COMPLETE_SHARE * counts.get((year - 1, st), 0)
|
||||
|
||||
|
||||
def rvu_events(
|
||||
con: Any,
|
||||
code: str,
|
||||
@@ -97,7 +104,11 @@ def rvu_events(
|
||||
if counts is None:
|
||||
counts = status_counts(con)
|
||||
st = rows[-1][1]
|
||||
if counts.get((last + 1, st), 0) >= _COMPLETE_SHARE * counts.get((last, st), 0):
|
||||
# The code is absent from every year after `last`, so ANY later
|
||||
# complete file for its status (Z in last+1..hi) confirms the
|
||||
# absence: a retired status or a one-year dip still fires, a partial
|
||||
# newest year with no later file does not.
|
||||
if any(_status_complete(counts, z, st) for z in range(last + 1, hi + 1)):
|
||||
out.append(_ev(code, last + 1, "disappeared"))
|
||||
for (py, ps, pd, pt), (y, s, d, t) in zip(rows, rows[1:]):
|
||||
if s != ps:
|
||||
|
||||
@@ -444,6 +444,53 @@ class TestPartialYearDisappearance:
|
||||
]
|
||||
|
||||
|
||||
class TestRetiredAndDipStatuses:
|
||||
@staticmethod
|
||||
def _con(rows):
|
||||
c = duckdb.connect(":memory:")
|
||||
ensure_tables(c)
|
||||
c.execute(f"CREATE TABLE pfs.rvu ({RVU_COLS})")
|
||||
c.executemany("INSERT INTO pfs.rvu VALUES (?,?,?,?,?,?)", rows)
|
||||
return c
|
||||
|
||||
def test_retired_status_fires_in_the_year_after_last_seen(self):
|
||||
rows = [
|
||||
(f"A{i:04d}", None, "d", "A", 1.0, y)
|
||||
for y in (1, 2, 3, 4)
|
||||
for i in range(10)
|
||||
]
|
||||
rows += [
|
||||
(f"Q{i:04d}", None, "d", "Q", 1.0, y) for y in (1, 2) for i in range(5)
|
||||
]
|
||||
c = self._con(rows)
|
||||
assert [(e.year, e.kind) for e in rvu_events(c, "Q0001")] == [
|
||||
(3, "disappeared")
|
||||
]
|
||||
|
||||
def test_one_year_dip_that_recovers_still_fires_in_the_dip_year(self):
|
||||
rows = [
|
||||
(f"A{i:04d}", None, "d", "A", 1.0, y) for y in (1, 2, 3) for i in range(10)
|
||||
]
|
||||
rows += [(f"M{i:04d}", None, "d", "M", 1.0, 1) for i in range(10)]
|
||||
rows += [("M0000", None, "d", "M", 1.0, 2)]
|
||||
rows += [(f"N{i:04d}", None, "d", "M", 1.0, 3) for i in range(10)]
|
||||
c = self._con(rows)
|
||||
# M0001 last seen in year 1, never again; year 2 dipped, year 3 recovered
|
||||
assert [(e.year, e.kind) for e in rvu_events(c, "M0001")] == [
|
||||
(2, "disappeared")
|
||||
]
|
||||
|
||||
def test_partial_newest_year_with_no_later_file_is_suppressed(self):
|
||||
rows = [
|
||||
(f"A{i:04d}", None, "d", "A", 1.0, y) for y in (1, 2, 3) for i in range(10)
|
||||
]
|
||||
rows += [
|
||||
(f"M{i:04d}", None, "d", "M", 1.0, y) for y in (1, 2) for i in range(10)
|
||||
]
|
||||
c = self._con(rows)
|
||||
assert rvu_events(c, "M0001") == []
|
||||
|
||||
|
||||
class TestExpandRangeBoundary:
|
||||
def test_span_fifty_expands_fifty_one_does_not(self):
|
||||
assert len(_expand_ranges("99100-99150").split()) == 51
|
||||
|
||||
Reference in New Issue
Block a user