Answer architecture round 2: keep reading_cost's main to finding, updating and reporting
This commit is contained in:
+21
-14
@@ -17,9 +17,8 @@ order the chunks finished.
|
|||||||
figures of chunks that finished after it.
|
figures of chunks that finished after it.
|
||||||
|
|
||||||
It then compares the mean tokens of the history's last 5 figures with the 5 before them, in the
|
It then compares the mean tokens of the history's last 5 figures with the 5 before them, in the
|
||||||
order their chunks finished, and prints
|
order their chunks finished, and prints "Rising:" or "Not rising:" with both means. Rising, it
|
||||||
"Rising:" or "Not rising:" with both means. Rising, it lists the files the last 5 chunks read most.
|
lists the files the last 5 chunks read most. With fewer than 10 figures, it says so.
|
||||||
With fewer than 10 figures, it says so.
|
|
||||||
|
|
||||||
Exit 1, saying why, when git cannot start or finds no checkout, the archive or the history cannot
|
Exit 1, saying why, when git cannot start or finds no checkout, the archive or the history cannot
|
||||||
be read or written, or a figure in the history cannot be read back.
|
be read or written, or a figure in the history cannot be read back.
|
||||||
@@ -70,31 +69,39 @@ class Checkout:
|
|||||||
def main(argv: list[str]) -> int:
|
def main(argv: list[str]) -> int:
|
||||||
reset = argv[:1] == ["--reset"]
|
reset = argv[:1] == ["--reset"]
|
||||||
given = argv[1:] if reset else argv
|
given = argv[1:] if reset else argv
|
||||||
helped = given[:1] in (["-h"], ["--help"])
|
if given[:1] in (["-h"], ["--help"]) or len(given) > 1:
|
||||||
if helped or len(given) > 1:
|
helped = len(given) == 1
|
||||||
print(__doc__.strip(), file=sys.stdout if helped else sys.stderr)
|
print(__doc__.strip(), file=sys.stdout if helped else sys.stderr)
|
||||||
return 0 if helped else 1
|
return 0 if helped else 1
|
||||||
home = pathlib.Path.home()
|
|
||||||
checkout = located()
|
checkout = located()
|
||||||
if isinstance(checkout, Failure):
|
if isinstance(checkout, Failure):
|
||||||
return failed(checkout)
|
return failed(checkout)
|
||||||
history = pathlib.Path(given[0]) if given else pathlib.Path(checkout.top, "docs", "comprehension-history.md")
|
history = pathlib.Path(given[0]) if given else pathlib.Path(checkout.top, "docs", "comprehension-history.md")
|
||||||
|
updated = update(history, checkout, reset)
|
||||||
|
if isinstance(updated, Failure):
|
||||||
|
return failed(updated)
|
||||||
|
appended, readings = updated
|
||||||
|
print(f"Appended {appended} reading-cost figures{' and a reset' if reset else ''} to {history}.")
|
||||||
|
print(trend(readings))
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
def update(history: pathlib.Path, checkout: Checkout, reset: bool) -> tuple[int, list[Reading]] | Failure:
|
||||||
|
"""How many figures it appended, and the readings the trend counts."""
|
||||||
text = read_history(history)
|
text = read_history(history)
|
||||||
if isinstance(text, Failure):
|
if isinstance(text, Failure):
|
||||||
return failed(text)
|
return text
|
||||||
figures = new_figures(text, checkout, home)
|
figures = new_figures(text, checkout, pathlib.Path.home())
|
||||||
if isinstance(figures, Failure):
|
if isinstance(figures, Failure):
|
||||||
return failed(figures)
|
return figures
|
||||||
marks = [*figures, f"## {RESET}{utc(time.time())}\n"] if reset else figures
|
marks = [*figures, f"## {RESET}{utc(time.time())}\n"] if reset else figures
|
||||||
text = merged(text, marks) if marks else text
|
text = merged(text, marks) if marks else text
|
||||||
readings = readings_of(text)
|
readings = readings_of(text)
|
||||||
if isinstance(readings, Failure):
|
if isinstance(readings, Failure):
|
||||||
return failed(readings)
|
return readings
|
||||||
if marks and (unwritten := write_history(history, text)):
|
if marks and (unwritten := write_history(history, text)):
|
||||||
return failed(unwritten)
|
return unwritten
|
||||||
print(f"Appended {len(figures)} reading-cost figures{' and a reset' if reset else ''} to {history}.")
|
return len(figures), readings
|
||||||
print(trend(readings))
|
|
||||||
return 0
|
|
||||||
|
|
||||||
|
|
||||||
def new_figures(history: str, checkout: Checkout, home: pathlib.Path) -> list[str] | Failure:
|
def new_figures(history: str, checkout: Checkout, home: pathlib.Path) -> list[str] | Failure:
|
||||||
|
|||||||
Reference in New Issue
Block a user