Skip to content

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_least facts that agree with rule.
  • A sum goal (total is set) needs the sum of total over the facts that agree to be at least at_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 None. The default None means count the facts.

every bool

Whether every fact must agree. The default is False.

by date | None

The day by which the goal must be met. The default None means no day. A check after this day is late.

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

name instance-attribute

name: str

of instance-attribute

of: type[T]

rule class-attribute instance-attribute

rule: Callable[..., bool] = lambda fact: True

at_least class-attribute instance-attribute

at_least: float = 1

total class-attribute instance-attribute

total: Callable[[T], float | None] | None = None

every class-attribute instance-attribute

every: bool = False

by class-attribute instance-attribute

by: date | None = None

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 by day of the goal.

failing Facts[T]

The facts that do not agree with the rule.

goal instance-attribute

goal: str

on instance-attribute

on: date

met instance-attribute

met: bool

found instance-attribute

found: int | float

needed instance-attribute

needed: int | float

late instance-attribute

late: bool

failing instance-attribute

failing: Facts[T]

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']

DAY class-attribute instance-attribute

DAY = 'day'

One calendar day.

WEEK class-attribute instance-attribute

WEEK = 'week'

7 days.

MONTH class-attribute instance-attribute

MONTH = 'month'

One calendar month. A day that the later month does not have moves to the last day of that month.