40 lines
1.8 KiB
Python
40 lines
1.8 KiB
Python
"""The goal weights a plan is ranked by, read from the goals file, the decision log and the comprehension history, for the markdown plan and for the scoring of a plan in Jira."""
|
|
import dataclasses
|
|
import decimal
|
|
|
|
from failure import Failure
|
|
from project_config.settings import JiraScoring
|
|
from plan import ranking
|
|
from record_store.stores import RecordStore
|
|
|
|
# What the reader of a missing or empty goals file is told.
|
|
GOALS_HINT = "rank_todo.py weighs goals from the goals file the project's config names as goals-and-audience"
|
|
|
|
|
|
@dataclasses.dataclass(frozen=True)
|
|
class StatedScoring:
|
|
"""The scoring of a plan in Jira: the formula and bar the project's config states, with goal weights that ranking reads from the goals file, the decision log and the comprehension history."""
|
|
stated: JiraScoring
|
|
goals: RecordStore
|
|
decisions: RecordStore
|
|
history: RecordStore
|
|
floor: decimal.Decimal
|
|
|
|
def read(self) -> ranking.Scoring | Failure:
|
|
weighing = weighing_texts(self.goals, self.decisions, self.history)
|
|
return weighing if isinstance(weighing, Failure) else ranking.config_scoring(self.stated.formula, self.stated.bar, *weighing, self.floor)
|
|
|
|
|
|
def weighing_texts(goals: RecordStore, decisions: RecordStore, history: RecordStore) -> tuple[str, str, str] | Failure:
|
|
"""What ranking weighs the goals by: the goals file, the decision log and the comprehension history. The last two are empty when missing; a goals file that is missing or empty is a Failure."""
|
|
goals_text = goals.read()
|
|
if isinstance(goals_text, Failure):
|
|
return goals_text
|
|
if not goals_text:
|
|
return Failure(f"{goals.label}: missing or empty; {GOALS_HINT}")
|
|
decisions_text = decisions.read()
|
|
if isinstance(decisions_text, Failure):
|
|
return decisions_text
|
|
history_text = history.read()
|
|
return history_text if isinstance(history_text, Failure) else (goals_text, decisions_text, history_text)
|