Schedules¶
Calendar rules, duty plans, the map between dates and meter readings,
tasks on dates and failures, events and work by calendar period (see the
Schedules on the calendar guide). They are in
repyability.schedule: from repyability.schedule import DutyPlan.
Recurrence
dataclass
¶
Recurrence(*args, **kwargs)
Which dates something falls on: every so many days, weeks, months or years; named weekdays; a day or weekday of the month; a date or weekday pattern in a named month each year; or given dates.
Made with its named constructors (Recurrence.every, weekly,
monthly, yearly and on), each taking the same options:
season=: aSeason(or its dict); dates outside it don't count.excluding=: dates, or(first, last)ranges both ends included, that don't count (holidays, a shut).moved=: what an excluded date does:"skip"(the default),"before"(the nearest day before that is not excluded) or"after"(the nearest day after).short_months=: for a day of the month past the 28th (or a yearly 29 February), what a month without it does:"last"(the default) falls on its last day,"skip"has no date that month.
Every period asked about includes both of its ends.
Examples:
>>> from repyability.schedule import Recurrence
>>> first_saturday = Recurrence.monthly(weekday="Saturday", nth=1)
>>> [str(d) for d in first_saturday.dates("2026-11-14", "2027-03-31")]
['2026-12-05', '2027-01-02', '2027-02-06', '2027-03-06']
>>> first_saturday.describe()
'the first Saturday of every month'
>>> overhaul = Recurrence.yearly(month=11, weekday="Tuesday", nth=1)
>>> [str(d) for d in overhaul.dates("2026-11-14", "2029-12-31")]
['2027-11-02', '2028-11-07', '2029-11-06']
every
classmethod
¶
every(n, unit, anchor, *, season=None, excluding=None, moved=None, short_months=None)
Every n days, weeks, months or years from a date.
Months and years keep the anchor's day of the month (31 January,
28 February, 31 March: a shorter month's last day, or no date
that month with short_months="skip"), each counted from the
anchor, not from the date before.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
How many units apart, at least 1. |
required |
unit
|
('days', 'weeks', 'months', 'years')
|
The unit (the singular is taken too). |
"days"
|
anchor
|
date or str
|
A date the rule falls on, its first: no date comes before it. |
required |
season
|
The options every rule takes (see the class). |
None
|
|
excluding
|
The options every rule takes (see the class). |
None
|
|
moved
|
The options every rule takes (see the class). |
None
|
|
short_months
|
The options every rule takes (see the class). |
None
|
Returns:
| Type | Description |
|---|---|
Recurrence
|
|
Examples:
>>> from repyability.schedule import Recurrence
>>> weekly = Recurrence.every(1, "week", "2026-07-15")
>>> len(weekly.dates("2026-10-11", "2026-12-31"))
12
>>> monthly = Recurrence.every(1, "months", "2027-01-31")
>>> [str(d) for d in monthly.dates("2027-01-01", "2027-03-31")]
['2027-01-31', '2027-02-28', '2027-03-31']
weekly
classmethod
¶
weekly(weekdays, *, every=1, anchor=None, season=None, excluding=None, moved=None)
On named days of the week, every week or every every
weeks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weekdays
|
str or sequence of str
|
The days: |
required |
every
|
int
|
Every how many weeks, by default 1. Above 1, weeks are counted
from the anchor's week (weeks start on Monday), so it needs an
|
1
|
anchor
|
date or str
|
The date the rule starts: no date comes before it. |
None
|
season
|
The options every rule takes (see the class). |
None
|
|
excluding
|
The options every rule takes (see the class). |
None
|
|
moved
|
The options every rule takes (see the class). |
None
|
Returns:
| Type | Description |
|---|---|
Recurrence
|
|
Examples:
>>> from repyability.schedule import Recurrence
>>> Recurrence.weekly("Mon, Wed, Fri").describe()
'every Monday, Wednesday and Friday'
monthly
classmethod
¶
monthly(*, day=None, weekday=None, nth=None, every=1, anchor=None, season=None, excluding=None, moved=None, short_months=None)
A day of the month (the 30th), or the nth weekday of it
(the first Saturday, the last Friday), every month or every
every months.
A fifth weekday (nth=5 or -5) is in only some months: the
others have no date, and notes lists them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
int
|
The day of the month, 1 to 31. A month too short for it falls
on its last day, or is skipped ( |
None
|
weekday
|
str
|
The day of the week, with |
None
|
nth
|
int
|
Which of the month's weekdays: 1 to 5, or -1 (the last) to -5. |
None
|
every
|
int
|
Every how many months, by default 1. Above 1, months are
counted from the anchor's month, so it needs an |
1
|
anchor
|
date or str
|
The date the rule starts: no date comes before it. |
None
|
season
|
The options every rule takes (see the class). |
None
|
|
excluding
|
The options every rule takes (see the class). |
None
|
|
moved
|
The options every rule takes (see the class). |
None
|
|
short_months
|
The options every rule takes (see the class). |
None
|
Returns:
| Type | Description |
|---|---|
Recurrence
|
|
Examples:
>>> from repyability.schedule import Recurrence
>>> thirtieth = Recurrence.monthly(day=30)
>>> [str(d) for d in thirtieth.dates("2027-01-01", "2027-03-31")]
['2027-01-30', '2027-02-28', '2027-03-30']
>>> Recurrence.monthly(weekday="Fri", nth=-1, every=3,
... anchor="2027-01-01").describe()
'the last Friday of every 3rd month, from 1 Jan 2027'
yearly
classmethod
¶
yearly(*, month, day=None, weekday=None, nth=None, every=1, anchor=None, season=None, excluding=None, moved=None, short_months=None)
A date (1 July) or a weekday pattern (the first Tuesday) in a
named month, every year or every every years.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
month
|
int or str
|
The month, 1 to 12 or a name ( |
required |
day
|
int
|
The day of that month. 29 February falls on the 28th in other
years, or is skipped ( |
None
|
weekday
|
str
|
The day of the week, with |
None
|
nth
|
int
|
Which of the month's weekdays: 1 to 5, or -1 (the last) to -5. |
None
|
every
|
int
|
Every how many years, by default 1. Above 1, years are counted
from the anchor's year, so it needs an |
1
|
anchor
|
date or str
|
The date the rule starts: no date comes before it. |
None
|
season
|
The options every rule takes (see the class). |
None
|
|
excluding
|
The options every rule takes (see the class). |
None
|
|
moved
|
The options every rule takes (see the class). |
None
|
|
short_months
|
The options every rule takes (see the class). |
None
|
Returns:
| Type | Description |
|---|---|
Recurrence
|
|
Examples:
>>> from repyability.schedule import Recurrence
>>> Recurrence.yearly(month=11, weekday="Tuesday", nth=1).describe()
'the first Tuesday of November, every year'
>>> Recurrence.yearly(month="Jul", day=1).describe()
'1 July, every year'
on
classmethod
¶
on(dates, *, season=None, excluding=None, moved=None)
Given dates (turnarounds booked years ahead, say).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dates
|
sequence of datetime.date or str
|
The dates, at least one, in any order. |
required |
season
|
The options every rule takes (see the class). |
None
|
|
excluding
|
The options every rule takes (see the class). |
None
|
|
moved
|
The options every rule takes (see the class). |
None
|
Returns:
| Type | Description |
|---|---|
Recurrence
|
|
Examples:
>>> from repyability.schedule import Recurrence
>>> Recurrence.on(["2028-09-09", "2027-03-03"]).describe()
'on 3 Mar 2027 and 9 Sep 2028'
reanchored ¶
reanchored(anchor)
The same rule from another anchor (for an interval counted from when a task was last done).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anchor
|
date or str
|
The new anchor. |
required |
Returns:
| Type | Description |
|---|---|
Recurrence
|
|
dates ¶
dates(start, end)
The rule's dates from start to end, both included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
date or str
|
The first and last dates of the period. |
required |
end
|
date or str
|
The first and last dates of the period. |
required |
Returns:
| Type | Description |
|---|---|
tuple of datetime.date
|
In order. |
on_or_after ¶
on_or_after(day)
The rule's first date on or after day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date or str
|
The date. |
required |
Returns:
| Type | Description |
|---|---|
date or None
|
None when the rule has no date from then on. |
after ¶
after(day)
The rule's first date strictly after day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date or str
|
The date. |
required |
Returns:
| Type | Description |
|---|---|
date or None
|
None when the rule has no date after it. |
includes ¶
includes(day)
Whether the rule falls on day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date or str
|
The date. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
number ¶
number(day)
How many of the rule's dates there are up to day
(included), from its anchor: a visit's number, the first being 1
(0 before it), for work done "every third visit".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date or str
|
The date. |
required |
Returns:
| Type | Description |
|---|---|
int
|
|
notes ¶
notes(start, end)
What the rule left out or moved from start to end
(both included): months with no such day, dates out of season,
excluded dates, and moved ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
date or str
|
The first and last dates of the period. |
required |
end
|
date or str
|
The first and last dates of the period. |
required |
Returns:
| Type | Description |
|---|---|
RecurrenceNotes
|
|
describe ¶
describe()
The rule in plain words: "the first Tuesday of November,
every year".
Returns:
| Type | Description |
|---|---|
str
|
|
to_dict ¶
to_dict()
The rule as plain data, for JSON: a "kind" and a
"version", the rule's own fields (dates as ISO text, weekdays
and months by name), and the options that differ from their
defaults.
Returns:
| Type | Description |
|---|---|
dict
|
|
from_dict
classmethod
¶
from_dict(data)
A rule from its to_dict(), or from the shapes stored by
earlier tools: a work package's cadence (every, unit,
anchor and an optional pattern of weekday with nth,
or day) and a task's interval (interval, unit,
start).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
The saved rule. |
required |
Returns:
| Type | Description |
|---|---|
Recurrence
|
|
to_rrule ¶
to_rrule(start=None)
The rule as iCalendar (RFC 5545) text: a DTSTART line, the
RRULE (or RDATE) and any EXDATE lines, which
python-dateutil's rrulestr reads back to the same dates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
date or str
|
The |
None
|
Returns:
| Type | Description |
|---|---|
str
|
|
Notes
iCalendar cannot say a season of days of the year, nor move an excluded date: those rules are refused.
Season
dataclass
¶
Season(*, months=None, start=None, end=None)
The part of each year something applies in: some months (April to October), or from one day of the year to another (1 September to 30 April, across the new year), both ends included.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
months
|
sequence of int or str
|
The months, by number (1 to 12) or name ( |
None
|
start
|
str
|
The first and last days of the season, as |
None
|
end
|
str
|
The first and last days of the season, as |
None
|
Examples:
>>> from repyability.schedule import Season
>>> summer = Season(months=[10, 11, 12, 1, 2, 3])
>>> summer.includes("2027-01-15"), summer.includes("2027-06-01")
(True, False)
>>> summer.describe()
'October to March'
>>> Season(start="12-01", end="02-28").includes("2027-02-28")
True
includes ¶
includes(day)
Whether a date is in the season (both ends included).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
day
|
date or str
|
The date. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
to_dict ¶
to_dict()
The season as plain data: {"months": [...]} or
{"start": "MM-DD", "end": "MM-DD"}.
Returns:
| Type | Description |
|---|---|
dict
|
|
RecurrenceNotes
dataclass
¶
RecurrenceNotes(start, end, missing_months, out_of_season, excluded, moved, text)
Bases: _ScheduleResult
What a Recurrence left out or moved in a period: returned by
its notes(start, end).
Attributes:
| Name | Type | Description |
|---|---|---|
start, end |
date
|
The period's first and last dates, both included. |
missing_months |
tuple of str
|
The months ( |
out_of_season |
tuple of datetime.date
|
The rule's dates left out because they are outside its season. |
excluded |
tuple of datetime.date
|
The rule's dates left out because they are excluded
( |
moved |
tuple of (datetime.date, datetime.date)
|
The excluded dates that were moved, each with the date it moved to. |
text |
tuple of str
|
The same, in plain words, one line each. |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
to_dict ¶
to_dict()
The result as plain data, ready for json.dumps: each field
by name, dates as ISO text ("2026-12-05"), tuples as lists.
Returns:
| Type | Description |
|---|---|
dict
|
The fields, as plain data. |
Task
dataclass
¶
Task(name, *, every, also=None, last_done=None, tolerance=0, visits=None, cost=None, duration=None, resets=None, last_done_reading=None)
A task that falls due by the calendar: every so many days, weeks, months or years, or on a pattern of dates; with an optional second limit, whichever comes first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
What the task is called. |
required |
every
|
Recurrence
|
When it falls due. An interval ( |
required |
also
|
Recurrence
|
A second limit: the task falls due by whichever comes first; once
it is done, a resetting limit counts again from then (see
|
None
|
last_done
|
date or str
|
When it was last done. Without it, the first due date is the rule's first on or after the period's start. With it, a due date before the period's start means the task is overdue. |
None
|
tolerance
|
int
|
How many days after its due date the task may be done and still be on time, by default 0. |
0
|
visits
|
Recurrence
|
When the work is done (a weekly crew visit): each due date waits for the first visit on or after it. |
None
|
cost
|
float
|
What it costs each time, at least 0; None (the default) when not given, so a cost never given is not taken as free. |
None
|
duration
|
float
|
The hours of work each time, at least 0; None when not given. |
None
|
resets
|
bool
|
Whether a limit counts again from when the task is done. By
default an interval does and a pattern does not (and a limit by
use, |
None
|
last_done_reading
|
float
|
The meter reading when the task was last done, for a limit by use
( |
None
|
Examples:
A weekly task first done on Wednesday 15 July 2026, $250 a time:
>>> from repyability.schedule import Recurrence, Task
>>> conveyor = Task(
... "inspect conveyor",
... every=Recurrence.every(1, "weeks", "2026-07-15"),
... cost=250.0,
... )
>>> due = conveyor.due("2026-10-11", "2026-12-31")
>>> due.count, due.cost
(12, 3000.0)
>>> str(due.dates[0]), str(due.dates[-1])
('2026-10-14', '2026-12-30')
due ¶
due(start, end, usage=None, *, discount=None, escalation=None)
When the task falls due from start to end, both
included, assuming each time is done on its due date (or at its
visit).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
date or str
|
The first and last dates of the period. |
required |
end
|
date or str
|
The first and last dates of the period. |
required |
usage
|
UsageForecast
|
The map from dates to meter readings
( |
None
|
discount
|
float
|
A yearly discount rate (0.07 for 7% a year): the result then
has |
None
|
escalation
|
float
|
With |
None
|
Returns:
| Type | Description |
|---|---|
TaskDue
|
|
Examples:
$250 every 30 days from 20 November 2026, at 7% a year, over the first year:
>>> from repyability.schedule import Recurrence, Task
>>> task = Task(
... "grease bearings",
... every=Recurrence.every(30, "days", "2026-11-20"),
... cost=250.0,
... )
>>> year = task.due("2026-11-20", "2027-11-19", discount=0.07)
>>> year.count, year.cost, round(year.npv, 2)
(13, 3250.0, 3144.1)
long_run_value ¶
long_run_value(start, discount, *, precision=1e-09, escalation=None)
What the task is worth on start repeating for ever: the
present value of its cost every time it is done from start
on, at a yearly discount rate.
A plain interval of days or weeks (no second limit, visits,
season or excluded dates) is a geometric sum, in closed form:
cost / (1 - (1 + discount) ** (-days / 365.25)) from the
first time it is done. Any other task is summed date by date
until what is left cannot matter: a task is done once a day at
most, so the dates after any day are worth less than a task done
every day from then, and the sum stops where that is under
precision of the total.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
date or str
|
The date the costs are discounted to; the task's dates from it count (an overdue task is done on it). |
required |
discount
|
float
|
The yearly discount rate, more than 0 (0.07 for 7% a year). |
required |
escalation
|
float
|
The effective yearly rate the cost escalates at from its price
today (0.03 for 3% a year), below |
None
|
precision
|
float
|
For a task that is summed: the most the dates left out may add, as a share of the value; by default 1e-9. |
1e-09
|
Returns:
| Type | Description |
|---|---|
LongRunValue
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
The task has no cost; |
Examples:
$250 every 30 days from 20 November 2026, at 7% a year:
>>> from repyability.schedule import Recurrence, Task
>>> task = Task(
... "grease bearings",
... every=Recurrence.every(30, "days", "2026-11-20"),
... cost=250.0,
... )
>>> value = task.long_run_value("2026-11-20", 0.07)
>>> round(value.npv), value.method
(45112, 'closed form')
to_dict ¶
to_dict()
The task as plain data, for JSON: a "kind" and a
"version", its limits and visits as their own to_dict(),
dates as ISO text, and the options given.
Returns:
| Type | Description |
|---|---|
dict
|
|
TaskDue
dataclass
¶
TaskDue(task, start, end, dates, limits, done, late, on_time, overdue, count, cost, hours, resets, notes, moments=(), readings=(), stops_after=(), discount=None, npv=None, eac=None)
Bases: _ScheduleResult
When a Task falls due in a period: returned by its due.
Attributes:
| Name | Type | Description |
|---|---|---|
task |
str
|
The task's name. |
start, end |
date
|
The period's first and last dates, both included. |
dates |
tuple of datetime.date
|
The dates the task falls due, in order. The first is before
|
limits |
tuple of str
|
Which limit set each date: |
done |
tuple of datetime.date
|
When each is assumed done: its date, or the visit it waits for
( |
late |
tuple of int
|
The days each is done after its date (0 when done on it). |
on_time |
tuple of bool
|
Whether each is done within the task's |
overdue |
bool
|
Whether the task was overdue at |
count |
int
|
How many times it is done in the period. |
cost |
float or None
|
The cost each time times |
hours |
float or None
|
The duration each time times |
resets |
bool
|
Whether the interval counts again from when the task is done (else the limits keep their own dates). |
moments |
tuple of datetime.datetime
|
When each falls due, to the minute: a calendar limit's at midnight, a limit by use's when the meter reaches its reading. |
readings |
tuple of float or None
|
The meter reading each limit by use falls due at (None for a calendar limit's). |
stops_after |
tuple of datetime.datetime or None
|
For a limit by use due mid-run, when the equipment next stops (the task is done then); None otherwise. |
notes |
tuple of str
|
Plain words on what the rules left out or moved in the period (months with no fifth Saturday, excluded dates), and on the assumptions made. |
discount |
float or None
|
The yearly discount rate given ( |
npv |
float or None
|
With a discount and a cost: what the period's costs are worth on
|
eac |
float or None
|
The equivalent annual cost: the steady cost a year over the
period worth |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
to_dict ¶
to_dict()
The result as plain data, ready for json.dumps: each field
by name, dates as ISO text ("2026-12-05"), tuples as lists.
Returns:
| Type | Description |
|---|---|
dict
|
The fields, as plain data. |
LongRunValue
dataclass
¶
LongRunValue(task, start, discount, npv, eac, method, precision, summed_to, count, notes)
Bases: _ScheduleResult
What a task repeating for ever is worth now: returned by
Task.long_run_value.
Attributes:
| Name | Type | Description |
|---|---|---|
task |
str
|
The task's name. |
start |
date
|
The date the costs are discounted to; the dates from it count. |
discount |
float
|
The yearly discount rate. |
npv |
float
|
The present value on |
eac |
float
|
The equivalent annual cost: the steady cost a year, for ever,
worth |
method |
str
|
|
precision |
float
|
The most the dates left out can add to |
summed_to |
date or None
|
The last date summed to (None for a closed form). |
count |
int or None
|
How many times the task is done to |
notes |
tuple of str
|
What was assumed. |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
to_dict ¶
to_dict()
The result as plain data, ready for json.dumps: each field
by name, dates as ISO text ("2026-12-05"), tuples as lists.
Returns:
| Type | Description |
|---|---|
dict
|
The fields, as plain data. |
work_by_period ¶
work_by_period(tasks, period, start, end, usage=None, *, discount=None, escalation=None)
The work tasks need in each calendar period from start to
end (both included): how many are done, their hours and cost,
each counted in the period it is done in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
sequence of Task
|
The tasks, with names that differ. |
required |
period
|
('day', 'week', 'month', 'quarter', 'year')
|
The periods (a week runs Monday to Sunday); the first and last
are cut to |
"day"
|
start
|
date or str
|
The first and last dates. |
required |
end
|
date or str
|
The first and last dates. |
required |
usage
|
UsageForecast
|
The map from dates to meter readings, for tasks with a limit by
use (see |
None
|
discount
|
float
|
A yearly discount rate (0.07 for 7% a year): the result then has
each period's |
None
|
escalation
|
float
|
With |
None
|
Returns:
| Type | Description |
|---|---|
WorkByPeriod
|
|
Examples:
>>> from repyability.schedule import Recurrence, Task, work_by_period
>>> inspect = Task("inspect", every=Recurrence.weekly("Mon"),
... duration=1.5, cost=120.0)
>>> work = work_by_period([inspect], "month", "2026-11-16", "2027-01-31")
>>> work.count, work.hours
((3, 4, 4), (4.5, 6.0, 6.0))
WorkByPeriod
dataclass
¶
WorkByPeriod(period, starts, ends, count, hours, cost, by_task, tasks, no_hours, no_cost, discount=None, npv=None, total_npv=None, eac=None, notes=())
Bases: _ScheduleResult
The work tasks need in each calendar period: returned by
work_by_period.
Attributes:
| Name | Type | Description |
|---|---|---|
period |
str
|
|
starts, ends |
tuple of datetime.date
|
Each period's first and last dates, both included; the first and last periods are cut to the dates asked for. |
count |
tuple of int
|
How many tasks are done in each period (by the date each is done). |
hours |
tuple of float
|
Their durations summed, of the tasks that have one. |
cost |
tuple of float
|
Their costs summed, of the tasks that have one. |
by_task |
dict
|
Each task's count in each period, by name. |
tasks |
tuple of tuple of (str, datetime.date)
|
The tasks done in each period, with the date each is done. |
no_hours, no_cost |
tuple of str
|
The tasks with no duration (or no cost), left out of |
discount |
float or None
|
The yearly discount rate given; None when none was. |
npv |
tuple of float or None
|
With a discount: what each period's |
total_npv |
float or None
|
The periods' |
eac |
float or None
|
The equivalent annual cost: the steady cost a year over the dates
asked for worth |
notes |
tuple of str
|
What the present values assumed (empty with no discount). |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
to_dict ¶
to_dict()
The result as plain data, ready for json.dumps: each field
by name, dates as ISO text ("2026-12-05"), tuples as lists.
Returns:
| Type | Description |
|---|---|
dict
|
The fields, as plain data. |
DutyPlan
dataclass
¶
DutyPlan(*parts, background=None, specific=None, time_zone=None, season=None, outages=None, utilisation=1.0, per_hour=None, per_run=None, fill='pro_rata')
How a piece of equipment runs: a background, and specific parts on top of it, giving its operating hours (and other meters) by any moment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*parts
|
(Runs, Shifts, Roster, Rate or Continuous)
|
The background, when it is given positionally: one part, or parts
that follow each other (each from its |
()
|
background
|
part or sequence of parts
|
The same, by name (give one or the other). |
None
|
specific
|
sequence of parts
|
Parts on top of the background, each covering its own span
( |
None
|
time_zone
|
str
|
The site's IANA zone ( |
None
|
season
|
str or sequence of int
|
The months it runs in ( |
None
|
outages
|
sequence of (start, end)
|
Moments with no running at all (shutdowns, out of service), in every layer. |
None
|
utilisation
|
float
|
The share of the planned running that happens, taken as an expected value: each planned hour (and start) counts this much. A part's own takes its place for that part. |
1
|
per_hour
|
dict
|
Other meters each operating hour or each run adds:
|
None
|
per_run
|
dict
|
Other meters each operating hour or each run adds:
|
None
|
fill
|
('pro_rata', 'top_up')
|
How a background |
"pro_rata"
|
Examples:
>>> from repyability.schedule import DutyPlan, Rate, Runs
>>> plan = DutyPlan(
... background=Rate(3, per="day"),
... specific=[Runs([("2026-11-14 12:31", "2026-11-15 03:27"),
... ("2026-11-15 12:30", "2026-11-16 03:30")],
... from_="2026-11-14")],
... )
>>> plan.forecast("2026-11-14", "2027-11-14").describe()
'exact runs to 16 Nov 03:30, then about 3 h a day'
forecast ¶
forecast(start, end, readings=None, read_at=None)
The map between moments and meter readings from start to
end, anchored on the readings at read_at.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
(datetime, date or str)
|
The span of the forecast (wall-clock times at the site, unless given with a zone). |
required |
end
|
(datetime, date or str)
|
The span of the forecast (wall-clock times at the site, unless given with a zone). |
required |
readings
|
dict
|
Meter readings at |
None
|
read_at
|
(datetime, date or str)
|
When the meters were read; |
None
|
Returns:
| Type | Description |
|---|---|
UsageForecast
|
|
to_dict ¶
to_dict()
The plan as plain data, ready for json.dumps: every part
with its "kind", moments as ISO text, the zone by name.
Runs
dataclass
¶
Runs(runs, *, from_=None, until=None, season=None, utilisation=None)
Bases: _Part
Concrete runs, each a start and a stop: "on at 12:31 on 14 Nov, off at 03:27 on 15 Nov".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
runs
|
sequence of (on, off)
|
Each run's start and stop: datetimes, or ISO text such as
|
required |
from_
|
datetime or str
|
The span the runs cover, when it is more than from the first start to the last stop (the default): as a specific part, the background is not used anywhere in it. |
None
|
until
|
datetime or str
|
The span the runs cover, when it is more than from the first start to the last stop (the default): as a specific part, the background is not used anywhere in it. |
None
|
season
|
optional
|
As for |
None
|
utilisation
|
optional
|
As for |
None
|
Examples:
>>> from repyability.schedule import Runs
>>> run = Runs([("2026-11-14 12:31", "2026-11-15 03:27")])
>>> run.hours
14.933333333333334
Shifts
dataclass
¶
Shifts(days, start=None, stop=None, *, from_=None, until=None, season=None, utilisation=None)
Bases: _Part
A repeating week of clock times: Monday to Friday, 06:00 to 22:00.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
days
|
str or sequence of (days, start, stop)
|
The days of the week a run starts on ( |
required |
start
|
time or str
|
The clock times a run starts and stops, such as |
None
|
stop
|
time or str
|
The clock times a run starts and stops, such as |
None
|
from_
|
optional
|
As for |
None
|
until
|
optional
|
As for |
None
|
season
|
optional
|
As for |
None
|
utilisation
|
optional
|
As for |
None
|
Examples:
>>> from repyability.schedule import Shifts
>>> Shifts("Mon-Fri", "06:00", "22:00").hours_a_week
80.0
>>> two = [("Mon-Fri", "06:00", "14:00"), ("Mon-Fri", "14:30", "22:30")]
>>> Shifts(two).describe()
'Mon-Fri 06:00-14:00 and Mon-Fri 14:30-22:30'
Roster
dataclass
¶
Roster(pattern, anchor, start, stop, *, from_=None, until=None, season=None, utilisation=None)
Bases: _Part
A cycle of days on and off: four days on, four off, 07:00 to 19:00.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
sequence of int
|
Days on and days off, in turn, starting with days on: |
required |
anchor
|
date or str
|
The first day of a cycle (its first day on). |
required |
start
|
time or str
|
The clock times each day's run starts and stops (a stop before the start is on the next day). |
required |
stop
|
time or str
|
The clock times each day's run starts and stops (a stop before the start is on the next day). |
required |
from_
|
optional
|
As for |
None
|
until
|
optional
|
As for |
None
|
season
|
optional
|
As for |
None
|
utilisation
|
optional
|
As for |
None
|
Examples:
>>> from repyability.schedule import Roster
>>> Roster((4, 4), "2026-11-02", "07:00", "19:00").describe()
'4 on, 4 off, 07:00-19:00'
Rate
dataclass
¶
Rate(amount, per, meter='hours', *, from_=None, until=None, season=None, utilisation=None)
Bases: _Part
A general rate, spread evenly over each calendar period: 3 h a day; 15 h a month; 1,200 km a week; or a range, 2 to 4 h a day.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
amount
|
float or (float, float)
|
How much of the meter each period: a number more than 0, or a low and a high (a range: the forecast then gives the middle, and the low and high answers beside it). |
required |
per
|
str
|
|
required |
meter
|
str
|
The meter it drives. For |
"hours"
|
from_
|
optional
|
As for |
None
|
until
|
optional
|
As for |
None
|
season
|
optional
|
As for |
None
|
utilisation
|
optional
|
As for |
None
|
Examples:
>>> from repyability.schedule import Rate
>>> Rate(3, per="day").describe()
'about 3 h a day'
>>> Rate((2, 4), per="day").describe()
'about 2 to 4 h a day'
Continuous
dataclass
¶
Continuous(*, from_=None, until=None, season=None, utilisation=None)
Bases: _Part
Running all the time: a 24/7 process pump. A continuous stretch has no starts (it is one run with no start of its own in the plan).
Examples:
>>> from repyability.schedule import Continuous
>>> Continuous().describe()
'all the time'
Readings ¶
Readings(moment, values, low, high, layer)
Bases: Mapping
The meters' readings at a moment: read as a mapping of meter to
reading (readings["hours"]), with the moment, the low and high
readings of a range of rates, and the stretch it falls in.
Attributes:
| Name | Type | Description |
|---|---|---|
moment |
datetime
|
|
low, high |
dict
|
Each meter's reading under the low and the high rates (equal to the reading where the plan is exact). |
layer |
str or None
|
The layer of the stretch the moment falls in. |
Usage
dataclass
¶
Usage(amount, meter='hours')
A limit by use: every so much of a meter, such as Usage(2000,
"hours") (every 2,000 operating hours) or Usage(500, "starts").
Examples:
>>> from repyability.schedule import Usage
>>> Usage(2000, "hours").describe()
'every 2,000 hours'
UsageForecast ¶
UsageForecast(plan, clock_, start, end, origin, span, read_s, maps, runs, stretches, readings, notes)
The map between moments and meter readings from a duty plan (see the
module's notes). Made by DutyPlan.forecast, or
UsageForecast.calendar with no plan.
Attributes:
| Name | Type | Description |
|---|---|---|
start, end, read_at |
datetime
|
The forecast's span and when its readings were taken, as the site's wall-clock times (with the zone, when the plan has one). |
time_zone |
str or None
|
|
meters |
tuple of str
|
|
readings |
dict
|
The readings it is anchored on. |
fill |
str
|
How a background rate filled periods specific parts covered in
part ( |
stretches |
tuple of Stretch
|
Which layer each stretch of the forecast came from. |
notes |
tuple of str
|
What the forecast assumed: meters not read, times that don't exist or happen twice, stretches with no plan. |
plan |
DutyPlan
|
|
calendar
classmethod
¶
calendar(start, end, readings=None, read_at=None, time_zone=None)
The identity map, for when there is no duty plan: calendar time
is operating time (as for a life fitted in calendar days), so
"hours" counts every real hour.
Examples:
>>> from repyability.schedule import UsageForecast
>>> usage = UsageForecast.calendar("2027-01-01", "2027-02-01")
>>> usage.at("2027-01-02")["hours"]
24.0
at ¶
at(moment)
Each meter's reading at moment (a run starting then counts
its start).
Examples:
>>> from repyability.schedule import DutyPlan, Shifts
>>> pump = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00"))
>>> usage = pump.forecast(
... "2026-11-16", "2027-12-01", readings={"hours": 12_340}
... )
>>> usage.at("2027-01-01")["hours"]
12884.0
when ¶
when(**reading)
When a meter reaches a reading, such as when(hours=14_000),
searching from the forecast's start.
A moment in a run comes with the stop before and after it, since a task due mid-run is done while the equipment is off.
Examples:
>>> from repyability.schedule import DutyPlan, Runs
>>> run = Runs([("2026-11-14 12:31", "2026-11-15 03:27")])
>>> usage = DutyPlan(run).forecast(
... "2026-11-14", "2026-11-16", readings={"hours": 486.2}
... )
>>> crossing = usage.when(hours=500)
>>> str(crossing.moment), str(crossing.next_stop_after)
('2026-11-15 02:19:00', '2026-11-15 03:27:00')
due ¶
due(every, last_done_reading, start=None, end=None)
When a limit by use falls due from start to end (the
forecast's by default): at the readings last_done_reading +
every, + 2 * every, ... (each due counted from the one before,
as when every task is done when it falls due).
Examples:
>>> from repyability.schedule import DutyPlan, Shifts, Usage
>>> pump = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00"))
>>> usage = pump.forecast(
... "2026-11-16", "2027-12-01", readings={"hours": 12_340}
... )
>>> [str(m) for m in usage.due(Usage(2000, "hours"), 12_000).moments]
['2027-04-08 18:00:00', '2027-09-30 18:00:00']
by_period ¶
by_period(period='month')
Each meter's amount in each calendar period at the site:
"day", "week" (Monday to Sunday), "month",
"quarter" or "year". The amounts of a span's periods add up
to the readings' change over it.
Examples:
>>> from repyability.schedule import DutyPlan, Shifts
>>> pump = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00"))
>>> usage = pump.forecast(
... "2026-11-16", "2027-12-01", readings={"hours": 12_340}
... )
>>> usage.by_period("month").usage["hours"][:3]
(176.0, 368.0, 336.0)
model_time ¶
model_time(moments, unit='hours')
Operating time since the forecast's start at each moment, in
unit (the unit a model's life was fitted in): how a model in
operating time is reached from dates. A moment or a sequence (an
array back).
Examples:
>>> from repyability.schedule import DutyPlan, Shifts
>>> pump = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00"))
>>> usage = pump.forecast("2026-11-16", "2027-12-01")
>>> usage.model_time("2026-11-23")
80.0
moment ¶
moment(model_time, unit='hours')
The first moment operating time since the start reaches
model_time (in unit); None past the forecast. The inverse
of model_time wherever the equipment is running.
duty ¶
duty(start=None, end=None)
The share of the time running from start to end (the
forecast's span by default): what a RepairableRBD block's
"duty" takes.
rate ¶
rate(meter, per='hours', start=None, end=None)
One meter per unit of another over a span, such as
rate("starts", per="hours"): starts per operating hour.
Examples:
>>> from repyability.schedule import DutyPlan, Shifts
>>> plan = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00"))
>>> usage = plan.forecast("2026-11-16", "2026-11-23")
>>> usage.rate("starts", per="hours")
0.0625
life_at_usage ¶
life_at_usage(model, meter='starts', per='hours', start=None, end=None)
A life on two clocks taken at this plan's rate: model's
at_usage at rate(meter, per=per) over the span (the
forecast's by default), such as starts per operating hour.
model is a life fitted on two clocks (surpyval 0.28's
EquivalenceModel, fitted to hours and starts); the life back
is on the first clock (per), ready to be a block's or a
NonRepairable's life.
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
Examples:
>>> from repyability.schedule import DutyPlan, Shifts
>>> class TwoClocks: # stands in for surpyval's EquivalenceModel
... def at_usage(self, rate):
... return f"the life at {rate} starts an hour"
>>> plan = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00"))
>>> usage = plan.forecast("2026-11-16", "2026-11-23")
>>> usage.life_at_usage(TwoClocks())
'the life at 0.0625 starts an hour'
schedule ¶
schedule(unit='hours')
The duty as steps over calendar time since the forecast's start,
in unit: the shape a duty that changes over time takes.
describe ¶
describe()
Where the hours come from, stretch by stretch, in plain words:
"exact runs to 16 Nov 03:30, then about 3 h a day".
to_dict ¶
to_dict()
The forecast as plain data: its span, readings, the readings at its start and end, its stretches, its notes and its plan.
UsageDue
dataclass
¶
UsageDue(meter, every, last_done_reading, readings, moments, earliest, latest, last_stops_before, next_stops_after, layers, exact, overdue, count)
Bases: _Plain
When a limit by use falls due: returned by UsageForecast.due.
Attributes:
| Name | Type | Description |
|---|---|---|
meter |
str
|
|
every |
float
|
The limit, in the meter's unit. |
last_done_reading |
float
|
The meter's reading when the task was last done. |
readings |
tuple of float
|
The readings at which it falls due from the window's start to its end. |
moments, earliest, latest, last_stops_before, next_stops_after, layers |
Each due reading's |
|
exact |
tuple of bool
|
|
overdue |
bool
|
Whether the first due reading had already been reached at the
window's start (it is then the first of |
count |
int
|
How many fall due in the window. |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
PeriodUsage
dataclass
¶
PeriodUsage(period, starts, ends, usage, low, high, at_end)
Bases: _Plain
Each meter's amount in each calendar period: returned by
UsageForecast.by_period. A period runs from its start up to (not
including) its end; the first starts at the forecast's start and the
last ends at its end.
Attributes:
| Name | Type | Description |
|---|---|---|
period |
str
|
|
starts, ends |
tuple of datetime
|
|
usage |
dict
|
Each meter's amount in each period (by the middle map). |
low, high |
dict
|
The same under the low and the high rates. |
at_end |
dict
|
Each meter's reading at each period's end. |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
Crossing
dataclass
¶
Crossing(meter, reading, moment, earliest, latest, last_stop_before, next_stop_after, layer, exact, already_reached)
Bases: _Plain
When a meter reaches a reading: returned by UsageForecast.when.
Attributes:
| Name | Type | Description |
|---|---|---|
meter |
str
|
|
reading |
float
|
|
moment |
datetime or None
|
When the meter reaches the reading, by the middle map; None when it is not reached in the forecast (or was reached before it). |
earliest, latest |
datetime or None
|
The same under the high and the low rates of a range (equal to
|
last_stop_before |
datetime or None
|
The last time the equipment stopped before it reaches the reading (the last chance to do a task early while it is off). |
next_stop_after |
datetime or None
|
The first time it stops at or after then (when a task due mid-run can be done). None where the stretch is a general rate, which has no stops, or where the stop is not known. |
layer |
str or None
|
The layer of the stretch it falls in. |
exact |
bool
|
Whether the moment is exact (in a stretch of runs, shifts, a roster or all the time, and the same under low and high rates). |
already_reached |
bool
|
Whether the meter had already reached the reading at the forecast's start. |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
Stretch
dataclass
¶
Stretch(start, end, layer, description, exact)
Bases: _Plain
A stretch of a forecast with one source for its operating hours.
Attributes:
| Name | Type | Description |
|---|---|---|
start, end |
datetime
|
When the stretch starts and ends. |
layer |
str or None
|
|
description |
str
|
The part in words ("exact runs", "about 3 h a day"). |
exact |
bool
|
Whether the hours are exact (runs, shifts, a roster, all the time, or nothing) rather than a general rate. |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
DutySchedule
dataclass
¶
DutySchedule(unit, times, shares)
Bases: _Plain
The duty as steps over calendar time since the forecast's start:
from times[k] (in unit) the equipment runs shares[k] of
the time (1 while running, 0 while off, the rate's share on a general
rate). Returned by UsageForecast.schedule.
Attributes:
| Name | Type | Description |
|---|---|---|
unit |
str
|
|
times |
tuple of float
|
|
shares |
tuple of float
|
|
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
CalendarContext
dataclass
¶
CalendarContext(usage, duty=dict(), unit='hours')
The calendar an analysis runs on (see the module's notes).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
usage
|
UsageForecast
|
The calendar's frame: its start ("now", the diagram's 0), end,
time zone and periods
( |
required |
duty
|
mapping
|
Node -> its duty plan: a |
dict()
|
unit
|
str
|
The unit of the diagram's models ( |
'hours'
|
Examples:
>>> from repyability.schedule import CalendarContext, DutyPlan, Shifts
>>> from repyability.schedule import UsageForecast
>>> frame = UsageForecast.calendar("2027-01-04", "2027-01-11")
>>> shifts = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00")).forecast(
... "2027-01-04", "2027-01-11"
... )
>>> plan = CalendarContext(frame, {"pump": shifts}).duty_plan("pump")
>>> plan.times[:3], plan.shares[:3]
((0.0, 6.0, 22.0), (0.0, 1.0, 0.0))
duty_plan ¶
duty_plan(node)
Node node's duty as a block's "duty" takes it: a share
of the time, or the steps of its forecast over the diagram's clock
(a DutySchedule in the calendar's unit); None for a node the
calendar gives no plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
hashable
|
The diagram's node, as named in |
required |
model_time ¶
model_time(moments)
The diagram's clock at each moment: real time since the calendar's start, in its unit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moments
|
str, datetime or sequence of them
|
The moments, as the calendar's |
required |
rule_times ¶
rule_times(rule, at=None)
A recurrence rule's dates within the calendar, each at the clock
time at (midnight by default), on the diagram's clock: those
after its start (a task due at the start itself is due now, and
is not taken as done): a "preventive" spec's "replace_at"
for a task on the rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
Recurrence
|
The recurrence rule whose dates are taken. |
required |
at
|
str or time
|
The clock time on each date ( |
None
|
Examples:
>>> from repyability.schedule import CalendarContext, Recurrence
>>> from repyability.schedule import UsageForecast
>>> frame = UsageForecast.calendar("2027-01-01", "2028-01-01")
>>> quarterly = Recurrence.monthly(
... weekday="Monday", nth=1, every=3, anchor="2027-01-01"
... )
>>> CalendarContext(frame, unit="days").rule_times(quarterly).tolist()
[3.0, 94.0, 185.0, 276.0]
diagram ¶
diagram(rbd)
rbd (a RepairableRBD) on this calendar: each node the
calendar gives a plan has it as its "duty". The diagram
itself when the calendar gives no plan.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rbd
|
RepairableRBD
|
The diagram, each node the calendar's |
required |
to_dict ¶
to_dict()
The calendar as plain data: its frame, each node's plan (a share, or its steps on the diagram's clock) and its unit.
failures_by_period ¶
failures_by_period(part, usage, period='month', *, age=0.0, unit=None, every=None, resets=None, since_renewal=None, calendar=None, discount=None, escalation=None, npv_tolerance=NPV_TOLERANCE)
A part's expected failures, their cost and its range in each calendar period, through the map between dates and operating time.
Each period's end is turned into operating time since the forecast's
start (usage.model_time), the part is asked about those windows
with its existing methods, and the answers come back labelled with the
periods' dates. Each period's expected failures, cost and range, under
any policy (every, calendar), are
NonRepairable.cost_by_window's
(numerical); run to failure, the chance of at least one failure by
each period's end is
NonRepairable.failures's
(exact). A part cost_by_window does not take (no
unplanned_cost, or a replacement that takes time) is run to
failure with failures' exact expected failures and no ranges, the
reason in the notes. Ranges are the 5th to 95th percentile: 90% of
outcomes, two-sided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
part
|
NonRepairable
|
The part, its life in operating time (hours by default). |
required |
usage
|
UsageForecast
|
The map between dates and operating hours
( |
required |
period
|
str
|
|
'month'
|
age
|
float
|
The part's age at the forecast's start, in |
0.0
|
unit
|
str
|
The unit the part's life is in ( |
None
|
every
|
optional
|
A replacement policy, as
|
None
|
resets
|
optional
|
A replacement policy, as
|
None
|
since_renewal
|
optional
|
A replacement policy, as
|
None
|
calendar
|
optional
|
A replacement policy, as
|
None
|
discount
|
float
|
A yearly discount rate (0.07 for 7% a year): the result then has
each period's |
None
|
escalation
|
float
|
With |
None
|
npv_tolerance
|
float
|
How close the present value is worked out: the integral's pieces
are halved until |
NPV_TOLERANCE
|
Returns:
| Type | Description |
|---|---|
FailuresByPeriod
|
|
Examples:
A pump's wear ring (Weibull, scale 9,000 operating hours, shape 2.5), 5,200 h old, on a pump running Monday to Friday 06:00 to 22:00, at $4,800 a failure:
>>> import surpyval as surv
>>> from repyability import NonRepairable
>>> from repyability.schedule import DutyPlan, Shifts, failures_by_period
>>> ring = NonRepairable(
... surv.Weibull.from_params([9000.0, 2.5]), unplanned_cost=4800.0
... )
>>> usage = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00")).forecast(
... "2026-11-16", "2027-12-01", readings={"hours": 12_340}
... )
>>> months = failures_by_period(ring, usage, "month", age=5200.0)
>>> round(float(months.expected_failures.sum()), 3)
0.622
>>> round(float(months.probability[-1]), 3)
0.596
>>> round(months.total["expected_cost"])
2988
FailuresByPeriod
dataclass
¶
FailuresByPeriod(period, starts, ends, unit, operating, model_ends, age, policy, method, expected_failures, probability, probability_in_period, expected_planned, expected_cost, cost_low, cost_high, failures_low, failures_high, total, range, notes, discount=None, expected_npv=None, npv=None, npv_precision=None, eac=None)
Bases: _Plain
A part's failures and their cost in each calendar period: returned
by failures_by_period.
Each period's numbers are its own (not a running total) and add up
over the periods to the whole forecast's (the ranges do not add:
total has the whole forecast's own).
Attributes:
| Name | Type | Description |
|---|---|---|
period |
str
|
|
starts, ends |
tuple of datetime
|
Each period's start and end at the site (the first starts at the forecast's start, the last ends at its end). |
unit |
str
|
The model's unit of time. |
operating |
ndarray
|
The operating time in each period, in |
model_ends |
ndarray
|
The operating time from the forecast's start to each period's end: the model-time windows the part was asked about. |
age |
float
|
The part's age at the forecast's start, in |
policy |
str
|
|
method |
str
|
|
expected_failures |
ndarray
|
The expected failures in each period. |
probability |
ndarray
|
The chance of at least one failure from the forecast's start to each period's end. |
probability_in_period |
ndarray or None
|
The chance of at least one failure in each period. |
expected_planned |
ndarray or None
|
The expected planned replacements in each period (None when run to failure). |
expected_cost |
ndarray or None
|
The expected cost in each period, as it falls (not discounted,
with a discount too: the present values are |
cost_low, cost_high |
ndarray or None
|
Each period's cost range: its 5th and 95th percentiles (90% of outcomes, two-sided). |
failures_low, failures_high |
ndarray or None
|
The same for the number of failures. |
total |
dict
|
The whole forecast's: |
range |
str
|
What the ranges are, in words. |
notes |
tuple of str
|
What the forecast assumed. |
discount |
float or None
|
The yearly discount rate given; None when none was. |
expected_npv |
ndarray or None
|
With a discount: what each period's expected cost is worth at the
forecast's start, the cost discounted from when it is expected to
fall inside the period ( |
npv |
float or None
|
The periods' |
npv_precision |
float or None
|
How far the true |
eac |
float or None
|
The equivalent annual cost: the steady cost a year over the
forecast worth |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
events_by_period ¶
events_by_period(rbd, usage, period='month', *, state=None, unit=None, cost=False, mc_samples=None, seed=None, discount=None, escalation=None)
A RepairableRBD's expected events, and on request its cost, in
each calendar period.
A diagram's clock is calendar time (its blocks' "duty" and
"basis" put running hours on it), so each period's end is the real
time from the forecast's start to it, in the diagram's unit; the
diagram is asked about those windows
(expected_events_by_window,
exact) and the answers come back labelled with the periods' dates.
With cost=True,
cost_by_window adds
each period's cost: its mean exact, its range (the 5th to 95th
percentile, 90% of outcomes, two-sided) simulated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rbd
|
RepairableRBD
|
|
required |
usage
|
UsageForecast or CalendarContext
|
Gives the periods, the site's time zone and "now" (its start);
|
required |
period
|
str
|
|
'month'
|
state
|
dict or str
|
Where the components are at the forecast's start, as for
|
None
|
unit
|
str
|
The diagram's unit of time; by default the one its models' labels name, else hours (with a note). |
None
|
cost
|
bool
|
Also the cost by period (simulated range), by default False. |
False
|
mc_samples
|
optional
|
With |
None
|
seed
|
optional
|
With |
None
|
discount
|
float
|
With |
None
|
escalation
|
float
|
With |
None
|
Returns:
| Type | Description |
|---|---|
EventsByPeriod
|
|
Examples:
A pump whose failures come at a constant rate (one per 2,000 hours on average), repaired at once, by month in 2027:
>>> import surpyval as surv
>>> from repyability import RepairableRBD
>>> from repyability.schedule import UsageForecast, events_by_period
>>> rbd = RepairableRBD(
... [("s", "pump"), ("pump", "t")],
... {"pump": {
... "reliability": surv.Exponential.from_params([1 / 2000.0]),
... "repairability": "instant",
... }},
... )
>>> usage = UsageForecast.calendar("2027-01-01", "2028-01-01")
>>> months = events_by_period(rbd, usage, unit="hours")
>>> [round(float(x), 3) for x in months.events.system_failures[:2]]
[0.372, 0.336]
EventsByPeriod
dataclass
¶
EventsByPeriod(period, starts, ends, unit, model_ends, events, cost, range, notes, discount=None, expected_npv=None, npv=None, eac=None)
Bases: _Plain
A system's expected events (and, on request, cost) in each calendar
period: returned by events_by_period.
Attributes:
| Name | Type | Description |
|---|---|---|
period |
str
|
|
starts, ends |
tuple of datetime
|
Each period's start and end at the site. |
unit |
str
|
The diagram's unit of time. |
model_ends |
ndarray
|
Each period's end on the diagram's clock: real (calendar) time
since the forecast's start, in |
events |
EventsByWindow
|
|
cost |
CostByWindow or None
|
|
range |
str or None
|
What the cost range is, in words (None with no cost). |
notes |
tuple of str
|
|
discount |
float or None
|
The yearly discount rate given; None when none was. |
expected_npv |
ndarray or None
|
With a discount: what each period's expected cost is worth at the
forecast's start, each cost discounted from when it falls
( |
npv |
float or None
|
The periods' |
eac |
float or None
|
The equivalent annual cost: the steady cost a year over the
forecast worth |
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).
shutdown_spec ¶
shutdown_spec(rule, start, end, *, duration, unit='hours', at=None, time_zone=None, cost=None, scope=None, idle_ageing=None)
A RepairableRBD shutdown from a rule on dates: its "times"
are the rule's dates from start to end at the clock time
at, on the diagram's clock (real time since start's midnight,
in unit). A rule such as "the first Tuesday of November" has no
fixed period (364 or 371 days apart), so it goes in as given times.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule
|
Recurrence
|
When the shuts are. |
required |
start
|
date or str
|
The diagram's time 0 is |
required |
end
|
date or str
|
The diagram's time 0 is |
required |
duration
|
float
|
How long each shut lasts, in |
required |
unit
|
str
|
The diagram's unit, by default hours. |
'hours'
|
at
|
str or time
|
The clock time each shut starts, by default midnight. |
None
|
time_zone
|
str
|
The site's IANA zone (real hours across daylight saving); by default clock times as they are. |
None
|
cost
|
optional
|
The shutdown's |
None
|
scope
|
optional
|
The shutdown's |
None
|
idle_ageing
|
optional
|
The shutdown's |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
The spec for |
Examples:
The overhaul on the first Tuesday of November, from 06:00 for 48 hours, on a diagram whose time 0 is 14 November 2026:
>>> from repyability.schedule import Recurrence, shutdown_spec
>>> overhaul = Recurrence.yearly(month=11, weekday="Tuesday", nth=1)
>>> spec = shutdown_spec(
... overhaul, "2026-11-14", "2029-12-31", duration=48.0, at="06:00"
... )
>>> spec["times"]
[8478.0, 17382.0, 26118.0]
task_value ¶
task_value(task, does, usage, *, age=0.0, unit=None, discount=None, escalation=None, period='month', npv_tolerance=NPV_TOLERANCE, mc_samples=None, seed=None, confidence=0.9)
What a scheduled task is worth against not doing it, by calendar
period and in all: the part's cost with the task, without it, and the
difference, as present values with a discount.
Replaces(part): the task puts a new part in at every date it is
done (Task.due over the forecast, with its visits, second limit
and resets), whatever the part's age, and a failure in between is
replaced too without moving the dates (block replacement on dates).
Without the task the part runs to failure from the same age over the
same dates. Between two of the task's dates the part is a renewal
process from new, so the expected failures are
NonRepairable.failures' over
each stretch (exact); a failure costs the part's unplanned_cost
and the task its cost. A failure's cost is discounted from when
it is expected to fall, as
failures_by_period
discounts it (to within precision), and the task's own cost from
when it is done.
Finds(device, demand_rate=, consequence_cost=, repair_cost=): the
task tests a protective device for a hidden failure at every date it
is done, at the task's cost a test, and a failure it finds is
repaired as new. Demands come at demand_rate per unit of the
device's time, and one that meets the device failed costs
consequence_cost (and, by default, shows the failure, which is
repaired then). Without the task the device is never tested. The
device's chance of being failed over time, with the tests at the
task's times on its clock, is
failure_finding_window's
(numerical, its error in precision); the demands' cost is
discounted as it accrues, and a test and the repair of what it finds
from when the task is done. The result's "failures" are then the
demands that meet the device failed, and it has the failures
found and the device's unavailability with and without the task.
Services(plan, effect=): the task services the unit without
replacing it. With no effect (the default) the service is an accepted
cost: its value is minus its cost's present value, exactly. With an
effect (a maintenance.Restoration, or a fitted
Condition) the plan's one-node
diagram is simulated with the service at its dated times and without
it, from one seed (common random numbers), each run priced with the
plan's prices by period; the value is the mean difference, with its
interval (value_lower, value_upper).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
The task, by the calendar or by use ( |
required |
does
|
(Replaces, Finds or Services)
|
What the task does. |
required |
usage
|
UsageForecast
|
The map between dates and the part's operating time
( |
required |
age
|
float
|
The part's age at the forecast's start, in |
0.0
|
unit
|
str
|
The unit the part's life is in; by default the one its model's label names, else hours (with a note). |
None
|
discount
|
float
|
A yearly discount rate (0.07 for 7% a year): money is then a present value at the forecast's start. By default None: plain expected costs. |
None
|
escalation
|
float
|
With |
None
|
period
|
str
|
|
'month'
|
npv_tolerance
|
float
|
How close each side's failure cost is discounted, as for
|
NPV_TOLERANCE
|
mc_samples
|
int
|
For a service with an effect: the runs of each side, by default 4,000. |
None
|
seed
|
int
|
For a service with an effect: seeds the runs; by default one is drawn, and kept in the result. |
None
|
confidence
|
float
|
For a service with an effect: the level of the value's two-sided interval, by default 0.9. |
0.9
|
Returns:
| Type | Description |
|---|---|
TaskValue
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
|
ValueError
|
The part has no |
NotImplementedError
|
With |
Examples:
A pump's wear ring (Weibull, scale 9,000 operating hours, shape 2.5), 5,200 h old, \(4,800 when it fails; a new one (\)600) at every 6-monthly service; the pump runs Monday to Friday, 06:00 to 22:00:
>>> import surpyval as surv
>>> from repyability import NonRepairable
>>> from repyability.schedule import (
... DutyPlan, Recurrence, Replaces, Shifts, Task, task_value
... )
>>> ring = NonRepairable(
... surv.Weibull.from_params([9000.0, 2.5]), unplanned_cost=4800.0
... )
>>> service = Task(
... "new wear ring",
... every=Recurrence.every(6, "months", "2026-12-01"),
... cost=600.0,
... )
>>> usage = DutyPlan(Shifts("Mon-Fri", "06:00", "22:00")).forecast(
... "2026-11-16", "2027-12-01"
... )
>>> worth = task_value(service, Replaces(ring), usage, age=5200.0)
>>> [str(d) for d in worth.dates]
['2026-12-01', '2027-06-01']
>>> total = worth.total
>>> round(total["with_task"], 2), round(total["without_task"], 2)
(1550.82, 2987.56)
>>> round(total["value"], 2), round(total["failures_avoided"], 3)
(1436.74, 0.549)
Replaces
dataclass
¶
Replaces(part)
What a task does: it replaces part with a new one every time it
is done, whatever the part's age (and the part is replaced when it
fails, too). Plain data for
task_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
part
|
NonRepairable
|
The part, with its life in the unit of the usage forecast's model
time and its |
required |
Finds
dataclass
¶
Finds(device, *, demand_rate, consequence_cost, repair_cost=0.0, demands_reveal=True)
What a task does: it tests device, a protective device (a
relief valve, a trip, a standby pump's start), for a failure nobody
would otherwise see, and a failure it finds is repaired as new.
Plain data for task_value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
NonRepairable
|
The device, with its life (a failure is hidden) in the unit of the usage forecast's model time. Its own costs are not used. |
required |
demand_rate
|
float
|
How often the protected event comes, per unit of the device's time, at least 0. |
required |
consequence_cost
|
float
|
What a demand that meets the device failed costs, at least 0. |
required |
repair_cost
|
float
|
What repairing a failure costs, found by a test or shown by a demand; by default 0. |
0.0
|
demands_reveal
|
bool
|
Whether a demand that meets the device failed shows the failure,
which is repaired as new then (the default), with the task and
without it. False: only a test finds a failure, as
|
True
|
Services
dataclass
¶
Services(plan=None, effect=None)
What a task does: it services the unit of plan (a
maintenance.UnitPlan) without replacing it, with the stated
effect on its life. Plain data for
task_value.
By default (effect=None) a service has no effect on the life:
it is an accepted cost, valued at minus its own cost's present value,
exactly, and the plan is not needed. Otherwise:
- a
maintenance.Restoration: each service restores the unit as the restoration says (Kijima I or II factorqfrom 0, 0 as new under Kijima II, 1 no effect, above 1 a service that does harm; a virtual age to restore to; a fitted process); - a
Condition: the life a regression model fitted with a serviced-or-overdue covariate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
UnitPlan
|
The unit's plan: its life, repairs and prices, with no preventive task of its own. Needed with an effect. |
None
|
effect
|
Restoration or Condition
|
What a service does to the life; by default nothing. |
None
|
Condition
dataclass
¶
Condition(life, *, fresh, stale, lasts)
What a service does, as a fitted condition: the unit's life is
a surpyval regression model fitted with a covariate that says whether
the unit is serviced, fresh for lasts (in the plan's unit of
time) after each service and stale otherwise (and throughout
without the service). Plain data for
Services.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
life
|
surpyval regression model
|
Proportional or additive hazards, or accelerated failure time,
fitted with the covariate (as a block's |
required |
fresh
|
sequence of float
|
The covariates in force while the unit is serviced. |
required |
stale
|
sequence of float
|
The covariates in force while it is overdue (and throughout
without the service), as many as |
required |
lasts
|
float
|
How long a service keeps the unit |
required |
TaskValue
dataclass
¶
TaskValue(task, does, with_words, without_words, period, starts, ends, unit, age, dates, model_times, discount, with_task, without_task, value, task_cost, cost_with, cost_without, failures_with, failures_without, failures_avoided, total, precision, eac, notes, found=None, unavailability_with=None, unavailability_without=None, method='exact', value_lower=None, value_upper=None, confidence=None, n_simulations=None, seed=None)
Bases: _Plain
What a scheduled task is worth against not doing it: returned by
task_value.
Money is a present value at the forecast's start when a discount
is given, and the plain expected cost otherwise. Each period's
numbers are its own and add up to total's.
Attributes:
| Name | Type | Description |
|---|---|---|
task |
str
|
The task's name. |
does |
str
|
What the task does, in words. |
with_words, without_words |
str
|
What "with the task" and "without it" were taken to mean. |
period |
str
|
|
starts, ends |
tuple of datetime
|
Each period's start and end at the site. |
unit |
str
|
The part's unit of time. |
age |
float
|
The part's age at the forecast's start, in |
dates |
tuple of datetime.date
|
The dates the task is done in the forecast. |
model_times |
ndarray
|
The part's clock (operating time since the forecast's start, in
|
discount |
float or None
|
The yearly discount rate given; None when none was. |
with_task, without_task |
ndarray
|
What the part costs in each period with the task (its failures and the task's own cost) and without it (its failures): present values with a discount. |
value |
ndarray
|
|
task_cost |
ndarray
|
The task's own cost in each period (in |
cost_with, cost_without |
ndarray
|
The same two costs undiscounted. |
failures_with, failures_without |
ndarray
|
The expected failures in each period with and without the task. |
failures_avoided |
ndarray
|
|
total |
dict
|
The whole forecast's: |
precision |
float
|
How far the true total |
eac |
dict or None
|
With a discount, the equivalent annual cost of |
notes |
tuple of str
|
What was assumed. |
found |
ndarray or None
|
With |
unavailability_with, unavailability_without |
ndarray or None
|
With |
method |
str
|
|
value_lower, value_upper |
ndarray or None
|
Simulated: each period's value's two-sided interval at
|
confidence, n_simulations, seed |
(float, int, int or None)
|
Simulated: the interval's level, the runs and their seed (to repeat them). None when exact. |
With ``Services`` and no effect, the unit's own costs are the same |
|
|
with and without the service and are left out of both sides |
|
|
``with_task`` is the service's cost, ``without_task`` 0, and the |
|
|
failures are NaN (not worked out), none avoided. With an effect, |
|
|
each side is the unit's own costs (its plan's prices) in the |
|
|
simulated runs, ``with_task`` adding the service's cost. |
|
|
With ``Finds``, "the part" is the device and a "failure" above is a |
|
|
demand that meets it failed |
``failures_with``, ``failures_without``
|
|
and ``failures_avoided`` count those, and ``with_task`` is the |
|
|
tests' cost, the repairs' and those demands'. |
|
model_unit
property
¶
model_unit
The unit of the models of the diagram that gave this result
("hours", "km", "cycles"), as their labels name it:
the unit its times, rates and lives are in. None when the models
name no unit, or name different ones (the diagram warned of
that when it was built).