Goals¶
Goal
dataclass
¶
Goal(
name: str,
of: type[T],
rule: Callable[..., bool] = lambda fact: True,
at_least: float = 1,
total: Callable[[T], float | None] | None = None,
every: bool = False,
by: date | None = None,
)
A rule over the facts of 1 type and a number to reach. World.check tests it.
view.steps(...).map(lambda v: v.check(goal)) tests it on several days.
There are 3 kinds of goal:
- A count goal (the default) needs at least
at_leastfacts that agree withrule. - A sum goal (
totalis set) needs the sum oftotalover the facts that agree to be at leastat_least. - An every goal (
every=True) needs every fact to agree. The result lists the facts that do not.
rule takes the fact or the fact and the view. A rule with 2 parameters can read
other types from the view.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
A short name for the goal. It shows in the result. |
of |
type[T]
|
The type of fact that the goal tests. |
rule |
Callable[..., bool]
|
A function that takes a fact (or a fact and a view) and gives a true or false value. The default accepts every fact. |
at_least |
float
|
The number to reach. The default is 1. |
total |
Callable[[T], float | None] | None
|
A function that takes a fact and gives a number or |
every |
bool
|
Whether every fact must agree. The default is |
by |
date | None
|
The day by which the goal must be met. The default |
Example
open_at_home = Goal(
"at least 3 open tasks at home",
Task,
lambda t: t.list == "home" and t.status == Status.OPEN,
at_least=3,
)
today.check(open_at_home).met # -> True
GoalResult
dataclass
¶
GoalResult(
goal: str,
on: date,
met: bool,
found: int | float,
needed: int | float,
late: bool,
failing: Facts[T],
)
The result of one check of a goal on one date. World.check makes it.
Attributes:
| Name | Type | Description |
|---|---|---|
goal |
str
|
The name of the goal. |
on |
date
|
The date of the view that was checked. |
met |
bool
|
Whether the goal is met. |
found |
int | float
|
The count or the sum that the facts give. For an every goal it is the number of facts that agree. |
needed |
int | float
|
The number to reach. For an every goal it is the number of facts of the type. |
late |
bool
|
Whether the view's date is after the |
failing |
Facts[T]
|
The facts that do not agree with the rule. |
Step ¶
Bases: Enum
The distance between 2 views in a series. World.steps takes a Step.
Example
from scriptt.world import Step
views = today.steps(Step.DAY, 3)
[view.on_date.isoformat() for view in views]
# -> ['2026-11-04', '2026-11-05', '2026-11-06']