Schedules on the calendar¶
RePyability's models work in model time: a number of hours, days or cycles
from 0, or from a state. repyability.schedule connects that to the
calendar. This page covers the first part: which dates a rule gives
(Recurrence) and when tasks fall due on them (Task,
work_by_period); then how equipment runs (DutyPlan) and the
map between dates and operating hours it gives (UsageForecast), which
puts tasks counted in running hours on dates; and, through that map,
failures, events and shuts on the calendar (failures_by_period,
events_by_period, shutdown_spec, Opportunity.from_recurrence),
and what a task is worth against not doing it (task_value): a
replacement, or a test that finds a hidden failure.
The module computes and stores nothing. You pass it dates, rules and what
you know (when a task was last done); it never reads the clock. Dates are
whole dates, as datetime.date or ISO text such as "2026-11-14", and
every period includes both of its ends: dates("2026-10-11",
"2026-12-31") means through 31 December.
Which dates: Recurrence¶
One type, made with a named constructor for each kind of rule:
| Constructor | Means | Example |
|---|---|---|
Recurrence.every(n, unit, anchor) |
every n days, weeks, months or years from a date | every 2 weeks from 15 Jul 2026 |
Recurrence.weekly(weekdays, every=1, anchor=None) |
named weekdays, every n weeks | every Saturday; "Mon-Fri" |
Recurrence.monthly(day= or weekday=, nth=, every=1, anchor=None) |
a day of the month, or its nth weekday | the 30th; the first Saturday; the last Friday of every 3rd month |
Recurrence.yearly(month=, day= or weekday=, nth=, every=1) |
a date or weekday pattern in a named month | 1 July; the first Tuesday of November |
Recurrence.on(dates) |
given dates | turnarounds on 3 Mar 2027 and 9 Sep 2028 |
from repyability.schedule import Recurrence, Season, Task, work_by_period
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="November", 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']
describe() says the rule in plain words, so you can check it is the rule
you meant before you save it.
Short months, the fifth weekday, and anchors¶
A day the month doesn't have falls on the month's last day by default, or
is skipped with short_months="skip". Months counted from an anchor keep
the anchor's day: they are not carried to the 28th after February.
monthly = Recurrence.every(1, "months", "2027-01-31")
[str(d) for d in monthly.dates("2027-01-01", "2027-04-30")]
# ['2027-01-31', '2027-02-28', '2027-03-31', '2027-04-30']
nth runs from 1 to 5, and from -1 (the last) to -5. A fifth Saturday is
in only some months; the others are skipped, and notes() says which:
fifth = Recurrence.monthly(weekday="Saturday", nth=5)
len(fifth.dates("2027-01-01", "2027-12-31")) # -> 4
len(fifth.notes("2027-01-01", "2027-12-31").missing_months) # -> 8
With every above 1, weeks, months or years are counted from the
anchor's, so it needs an anchor. Weeks start on Monday. No date comes
before an anchor.
Seasons, excluded dates and moves¶
Every rule takes the same options:
season=: aSeasonof months (Season(months=[4, 5, 6, 7, 8, 9, 10])) or of days of the year (Season(start="09-01", end="04-30"), across the new year). Dates outside it don't count.excluding=: dates, or(first, last)ranges, that don't count: holidays, a shut. RePyability ships no holiday calendar; you pass the dates.moved=: what an excluded date does:"skip"(the default),"before"(the nearest day before that is not excluded) or"after".
month_end = Recurrence.monthly(
weekday="Friday", nth=-1, excluding=["2026-12-25"], moved="before"
)
[str(d) for d in month_end.dates("2026-11-01", "2026-12-31")]
# ['2026-11-27', '2026-12-24']
month_end.notes("2026-11-01", "2026-12-31").text
# ('25 Dec 2026 is excluded: moved to 24 Dec 2026.',)
Asking about one date¶
on_or_after(day) and after(day) give the next date (or None),
includes(day) whether the rule falls on it, and number(day) how many
dates there are from the anchor through it: a visit's number, for work
done every third visit.
visits = Recurrence.monthly(weekday="Saturday", nth=1, anchor="2026-11-01")
str(visits.after("2026-11-07")) # '2026-12-05'
visits.number("2027-01-02") # -> 3
Saving¶
to_dict() gives plain JSON with a "kind" and a "version";
from_dict() reads it back, and also reads a work package's cadence
(every, unit, anchor, pattern) and a task's interval (interval,
unit, start) as earlier tools stored them. to_rrule() writes the
rule as iCalendar text, which python-dateutil (and calendar programs) read
back.
Recurrence.from_dict(overhaul.to_dict()) == overhaul # True
print(overhaul.to_rrule(start="2026-01-01"))
# DTSTART:20260101T000000
# RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=+1TU
When tasks fall due: Task¶
A Task falls due by its rule (every=), and optionally by a second limit
(also=), whichever comes first.
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 # -> 12
due.cost # -> 3000
due() returns a TaskDue: the due dates, which limit set each
(limits), when each is assumed done (done), how many days late
(late) and whether that is within the task's tolerance (on_time),
the count, cost and hours, and plain-language notes.
When it is done, and what counts again from then¶
A forecast has to assume when each time is done: on its due date, or with
visits= at the first visit on or after it. Then:
- an interval (
Recurrence.every) counts again from when the task was done (last_done=for the last time before the period); - a pattern (weekly, monthly, yearly, given dates) keeps its own dates.
resets=True or False overrides that for every limit, and
TaskDue.resets says which applied.
service = Task(
"service",
every=Recurrence.every(3, "months", "2026-01-15"),
last_done="2026-09-20",
visits=Recurrence.weekly("Tue"),
tolerance=3,
)
due = service.due("2026-11-01", "2027-12-31")
[str(d) for d in due.done]
# ['2026-12-22', '2027-03-23', '2027-06-29', '2027-10-05']
due.late # (2, 1, 6, 6)
due.on_time # (True, True, False, False)
A task already due before the period starts (after last_done) is
overdue: it comes first, with its missed date, done at the period's
start (due.overdue is True).
Two limits¶
oil = Task(
"oil change",
every=Recurrence.every(30, "days", "2027-01-01"),
also=Recurrence.monthly(day=1),
last_done="2027-01-10",
)
due = oil.due("2027-01-10", "2027-04-30")
[str(d) for d in due.dates]
# ['2027-02-01', '2027-03-01', '2027-03-31', '2027-04-01']
due.limits # ('also', 'also', 'every', 'also')
Limits by use (every so many operating hours, Usage) take the same
every= and also=, with a duty plan's forecast: see
Duty plans.
Work by period¶
work_by_period(tasks, period, start, end) counts the tasks done in each
day, week (Monday to Sunday), month, quarter or year, with their hours and
cost. The first and last periods are cut to the dates asked. Tasks with no
hours or no cost are listed in no_hours and no_cost, so a total isn't
read as all the work.
tasks = [
Task("inspect", every=Recurrence.weekly("Mon"), duration=1.5, cost=120.0),
Task("service", every=Recurrence.every(3, "months", "2026-12-20"),
duration=4.0, cost=480.0),
]
work = work_by_period(tasks, "month", "2026-11-16", "2027-02-28")
work.count # (3, 5, 4, 4)
work.hours # (4.5, 10.0, 6.0, 6.0)
work.cost # (360.0, 960.0, 480.0, 480.0)
Present values: discount=¶
Give a yearly discount rate and the forecasts return present values
beside the plain totals. discount=0.07 is 7% a year, the effective
yearly rate (the convention of the dated replacement policies): an
amount y years after the first date is worth 1 / 1.07 ** y of
itself, with a year of 365.25 days. Money is discounted to the
forecast's first date, which is your "today". With no discount,
nothing changes.
A $250 task every 30 days from 20 November 2026, over its first year:
grease = Task("grease bearings",
every=Recurrence.every(30, "days", "2026-11-20"), cost=250.0)
year = grease.due("2026-11-20", "2027-11-19", discount=0.07)
year.count # -> 13
year.cost # -> 3250
round(year.npv, 2) # -> 3144.10
Each task is discounted from the date it is done (after its visit, if
it waits for one). eac is the equivalent annual cost: the steady cost
a year over the period that is worth the same. work_by_period(...,
discount=0.07) gives each period's npv, with total_npv and eac.
long_run_value is what the task is worth repeating for ever:
value = grease.long_run_value("2026-11-20", 0.07)
round(value.npv) # -> 45112
value.method # 'closed form'
A plain interval of days or weeks is a geometric sum, 250 / (1 - 1.07
** (-30 / 365.25)). Any other task (the first Tuesday of the month, a
task that waits for visits, two limits) is summed date by date until
what is left cannot matter: precision is the most the dates left out
could add, and summed_to the last date summed. It refuses, saying what
to run, where there is no such value: at discount=0, for given dates
(they end), and for a limit by use (its usage forecast ends).
Duty plans: operating hours on dates¶
A life fitted in operating hours, or a task every 2,000 running hours,
needs to know how the equipment runs before it can say anything about
dates. A DutyPlan says how it runs; its forecast is the map between
moments and meter readings, both ways.
A repeating week¶
A pump runs Monday to Friday, 06:00 to 22:00, and its hour meter read 12,340 h at the start of Monday 16 November 2026:
from repyability.schedule import DutyPlan, Shifts, Task, Usage
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
Its service is every 2,000 operating hours and was last done at 12,000 h, so it is next due at 14,000 h. The meter reaches that at 18:00 on Thursday 8 April 2027, in the middle of a run; the pump stops at 22:00 that day, which is when the service can be done:
crossing = usage.when(hours=14_000)
str(crossing.moment) # '2027-04-08 18:00:00'
str(crossing.next_stop_after) # '2027-04-08 22:00:00'
At a flat 80 hours a week the date would have been Saturday 10 April, a day the pump does not run: the shape of the week matters, not only its total.
A Task with a limit by use takes the same forecast:
service = Task("Service", every=Usage(2000, "hours"), last_done_reading=12_000)
due = service.due("2026-11-16", "2027-11-30", usage=usage)
[str(m) for m in due.moments] # ['2027-04-08 18:00:00', '2027-09-30 18:00:00']
The hours in each calendar month, and the reading at each month's end:
months = usage.by_period("month")
months.usage["hours"][:3] # (176.0, 368.0, 336.0)
months.at_end["hours"][-1] # -> 16692
Operating time, the model's clock¶
A life fitted in operating hours is reached from dates through
model_time (operating time since the forecast's start, in the model's
unit) and back through moment:
usage.model_time("2026-11-23") # -> 80
usage.moment(80.0) == usage.moment(usage.model_time("2026-11-20 22:00")) # True
duty() is the share of the time running (what a RepairableRBD
block's "duty" takes) and rate("starts", per="hours") one meter per
unit of another:
round(usage.duty(), 4) # -> 0.4772
usage.rate("starts", per="hours") # -> 0.0625
The parts of a plan¶
| Part | Means | Example |
|---|---|---|
Runs([(on, off), ...]) |
concrete runs | on 14 Nov 12:31, off 15 Nov 03:27 |
Shifts(days, start, stop) |
a repeating week; a stop before the start is the next day | Shifts("Mon-Fri", "06:00", "22:00") |
Roster(pattern, anchor, start, stop) |
days on and off in turn | Roster((4, 4), "2026-11-02", "07:00", "19:00") |
Rate(amount, per, meter="hours") |
a general rate, each calendar period's amount spread over it | Rate(3, per="day"), Rate(15, per="month"), Rate((2, 4), per="day") |
Continuous() |
all the time | a 24/7 process pump |
Options on the plan (and, but for the zone and outages, on each part):
from_/until, season="Apr-Oct", outages=[(start, end), ...],
utilisation=0.9 (each planned hour and start counts 0.9, an expected
value), time_zone="Australia/Sydney", and other meters:
per_hour={"tonnes": 40}, per_run={"cycles": 1}, or a Rate of their
own (Rate(1200, per="week", meter="km")). Every run adds one to
"starts".
A concrete run¶
A standby generator is booked to run from 12:31 on Saturday 14 November to 03:27 on Sunday, 14 hours 56 minutes. Its meter read 486.2 h; its 500-hour check falls due 13.8 hours into the run, at 02:19:
from repyability.schedule import Runs
generator = DutyPlan(Runs([("2026-11-14 12:31", "2026-11-15 03:27")]))
run = generator.forecast("2026-11-14", "2026-11-16", readings={"hours": 486.2})
str(run.when(hours=500).moment) # '2026-11-15 02:19:00'
run.at("2026-11-16")["hours"] # -> 501.13
A general rate, and a range¶
A conveyor runs about 3 hours a day; its meter read 1,180 h on 1 December 2026 and its idlers are inspected every 250 h (last at 1,000 h). The next falls due at 1,250 h, 23⅓ days on:
from repyability.schedule import Rate
conveyor = DutyPlan(Rate(3, per="day"))
belt = conveyor.forecast("2026-12-01", "2027-12-01", readings={"hours": 1_180})
str(belt.when(hours=1_250).moment) # '2026-12-24 08:00:00'
If the rate is only known as "2 to 4 hours a day", the date is a range: the middle at 3 h a day, the earliest at 4 and the latest at 2:
ranged = DutyPlan(Rate((2, 4), per="day"))
c = ranged.forecast("2026-12-01", "2027-12-01", readings={"hours": 1_180}).when(hours=1_250)
str(c.earliest), str(c.latest) # ('2026-12-18 12:00:00', '2027-01-05 00:00:00')
A rate is an assumption, and every answer from it says so (exact is
False); runs, shifts and rosters are exact.
From specific to general¶
A plan is usually exact for the next day or two and rough after. Give the rough part as the background and the exact runs as specific parts on top: the forecast uses the runs where they cover, and the background the moment they run out, and says which stretch came from which:
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")],
)
layered = plan.forecast("2026-11-14", "2027-11-14", readings={"hours": 4_820})
layered.describe() # 'exact runs to 16 Nov 03:30, then about 3 h a day'
A specific part covers from its from_ to its until; runs, by
default, from their first start to their last stop. As the days pass,
add the next runs; nothing else changes, and a new reading re-anchors the
forecast.
No duty is made at the handover. By default (fill="pro_rata") the
background applies only to the time the specific parts leave, at its
rate spread by time: the runs above give Monday 16 November 3.5 hours
to 03:30, and the background the 20.5 hours left of the day 3 × 20.5/24
= 2.5625 hours, never a full 3 hours more:
layered.by_period("day").usage["hours"][2] # -> 6.0625
A shift or roster background simply starts again at its next clock time,
counting only the part of a run no specific part covers. For a rate that
is a budget ("15 hours a month"), fill="top_up" gives the period in
which the specific parts end what they left of its amount (never less
than nothing), spread over the rest of it; the periods after get the
whole amount. Either way the days add up to the change in the reading.
Two parts of one layer that would count the same time twice are
refused, with a message naming both; a background part with no end ends
where the next one starts (Shifts(..., from_="2027-03-01")).
Time zones¶
With time_zone=, plans are in the site's wall-clock time and count
real hours: in Sydney, a 22:00 to 06:00 shift is 7 hours the night the
clocks go forward and 9 the night they go back. With no zone, clock
times are taken as they are.
night = DutyPlan(Shifts("Sat", "22:00", "06:00"), time_zone="Australia/Sydney")
night.forecast("2026-10-03", "2026-10-05").at("2026-10-05")["hours"] # -> 7
night.forecast("2027-04-03", "2027-04-05").at("2027-04-05")["hours"] # -> 9
A time that does not exist (02:30 the night the clocks go forward) moves
to the end of the gap (03:00); one that happens twice means the first.
The forecast's notes say when either happened. On Windows, install the
tzdata package for the zones (RePyability requires it there).
With no plan¶
UsageForecast.calendar(start, end) is the identity map: calendar time
is operating time, as for a life fitted in calendar days.
Saving¶
Every part and plan has to_dict() and from_dict() (plain JSON, a
"kind" on each part, moments as ISO text, the zone by name, and a
"version"), and every answer is plain data with to_dict().
Failures and costs on the calendar¶
RePyability's models answer in model time. These functions ask them from dates and label the answers with dates. They add no new probability: each turns dates into model time, calls a method that already exists, and puts the dates back. Every range is the 5th to 95th percentile: 90% of outcomes, two-sided.
A part, by month¶
The pump above has a wear ring with a fitted life in operating hours (Weibull, scale 9,000 h, shape 2.5). The ring is 5,200 h old. It is replaced when it fails, and a failure costs $4,800. The forecast runs to 1 December 2027:
import surpyval as surv
from repyability import NonRepairable
from repyability.schedule import failures_by_period
ring = NonRepairable(surv.Weibull.from_params([9000.0, 2.5]), unplanned_cost=4800.0)
months = failures_by_period(ring, usage, "month", age=5200.0)
round(months.total["probability"], 3) # -> 0.596
round(months.total["expected_failures"], 3) # -> 0.622
round(months.total["expected_cost"]) # -> 2988
months.total["cost_low"], months.total["cost_high"] # (0.0, 4800.0)
In words: there is a 60% chance the ring fails at least once by 1 December 2027. Expect 0.62 failures, which comes to about $2,990. The likely range is no failure to one failure, so $0 to $4,800 (90% of outcomes). Month by month the numbers are small, about 0.05 failures (roughly $250) in a full month:
[round(float(c)) for c in months.expected_cost[:3]] # [105, 227, 217]
With discount=, each period also has its expected cost as a present
value. An expected cost accrues as the part runs, and each part of it is
discounted from when it is expected to fall: an integral over the
forecast, worked out until its error estimate is small. npv_precision
is that estimate plus how far the expected cost itself can be from the
true one (the expected failures are worked out on a grid).
worth = failures_by_period(ring, usage, "month", age=5200.0, discount=0.07)
round(worth.npv) # -> 2883
worth.npv_precision < 0.001 * worth.npv # True
npv_tolerance (0.001 by default) sets how small npv_precision must
be, as a share of npv. expected_cost and the ranges
stay undiscounted: the present values are expected_npv and npv.
One part rarely fails in a given month, so the monthly figures become
useful once you add them up over many positions. The expected values
add up; the ranges do not, so total gives the whole forecast's own
range.
How it is worked out: each period's end becomes operating time since the
forecast starts (usage.model_time). The part is then asked about those
windows: NonRepairable.cost_by_window gives the expected failures, cost
and range for each period, and NonRepairable.failures gives the chance
of at least one failure. A policy goes in as those methods take it:
every=6000.0, resets=True for age replacement, or a calendar= built
from dated shuts (below). The part's age is its age when the forecast
starts. The model's unit comes from its label (unit="h" on the
surpyval model), or from unit=. With neither, it is taken as hours and
the notes say so.
Is a replacement task worth it?¶
A task's cost is only worth paying for what it prevents. task_value
values a task against not doing it: the part's cost with the task, without
it, and the difference, by period. Say every 6-monthly service fits a new
wear ring for $600:
from repyability.schedule import Recurrence, Replaces, Task, task_value
new_ring = Task("new wear ring",
every=Recurrence.every(6, "months", "2026-12-01"), cost=600.0)
worth = task_value(new_ring, Replaces(ring), usage, age=5200.0, discount=0.07)
[str(d) for d in worth.dates] # ['2026-12-01', '2027-06-01']
round(worth.total["with_task"]) # -> 1517
round(worth.total["without_task"]) # -> 2883
round(worth.total["value"]) # -> 1366
round(worth.total["failures_avoided"], 3) # -> 0.549
Replaces(ring) says what the task does: it puts a new ring in every
time it is done, whatever the ring's age. A failure in between is
replaced too and does not move the service dates. Without the task, the
ring runs to failure from the same age over the same dates (with_words
and without_words say so). value is without_task - with_task, so a
positive value means the task pays. Here it does: the ring is old, and
the first service replaces it in two weeks. Each failure's cost is
discounted as failures_by_period discounts it, and precision is how
far the value can be from the true one; the task's own cost is
discounted from the day it is done. With no discount the numbers are
plain expected costs ($1,550.82 against $2,987.56).
The task's cost is the planned ring's price. A task with no cost takes
the part's planned_cost. If both are given and differ, the call is
refused, naming the two numbers. A task by use (every=Usage(2000,
"hours")) is done when the meter reaches its reading.
Is a test of a hidden failure worth it?¶
A test of a protective device (a trip, a relief valve, a standby pump's
start) replaces nothing and prevents no failure. What it buys is time: a
device that has failed without anyone knowing is found and repaired at
the next test, instead of sitting failed until it is needed. Finds
says that is what the task does. Say a trip fails hidden at 0.1 a year
and is tested every 6 months at $400; a repair costs $3,000; the event
it protects against comes once in 2 years and costs $250,000 if the trip
is failed then:
from repyability.schedule import Finds, UsageForecast
trip = NonRepairable(surv.Exponential.from_params([0.1])) # per year
trip_test = Task("trip test",
every=Recurrence.every(6, "months", "2027-01-01"), cost=400.0)
years = UsageForecast.calendar("2026-11-16", "2029-11-16")
does = Finds(trip, demand_rate=0.5, consequence_cost=250_000.0,
repair_cost=3_000.0)
tested = task_value(trip_test, does, years, unit="years", discount=0.07)
round(tested.total["found"], 3) # -> 0.228
round(tested.total["unavailability_with"], 4) # -> 0.0213
round(tested.total["unavailability_without"], 4) # -> 0.0894
round(tested.total["failures_avoided"], 3) # -> 0.102
round(tested.total["value"], -2) # -> 19800.0
The trip's life is in calendar years, so the forecast is
UsageForecast.calendar and unit="years"; a device whose life is in
running hours takes a duty plan's forecast, and demands then come only
while it runs (demand_rate is per unit of the device's own time). With
the task, the cost is the tests, the repairs of what they find, and the
demands that meet the trip failed. Without it the trip is never tested.
The result's "failures" are those demands: here the tests avoid about
0.1 of them over three years, and are worth about $19,800 today.
found is the failures the tests find, and unavailability_with and
unavailability_without are the trip's mean unavailability in each
period (and over the whole forecast in total).
By default, a demand that meets the device failed also shows the
failure, which is repaired then. That is what happens without the task,
too: a failure stays until a demand finds it. With
demands_reveal=False, only a test finds a failure, as
failure_finding has it, so never tested, a failure
is for good. Tests and repairs take no time, a test never misses, and
the device is taken to be working when the forecast starts. The task's
cost is one test's. precision includes the error of the numerical
solution. In model time, with the tests at any list of times,
failure_finding_window gives the same numbers.
Is a service worth it?¶
A service (lubricate, adjust, clean, overhaul) neither replaces the unit
nor tests it, and what it does to the failure rate is not known from the
task. By default task_value takes it as having no effect: the
service is an accepted cost, and its value is minus its cost's present
value, worked out exactly. Say a gearbox, 4,000 h old and running around
the clock, is serviced every 3 months for $800:
from repyability.maintenance import Prices, Restoration, UnitPlan
from repyability.schedule import Services
gearbox = UnitPlan(surv.Weibull.from_params([8760.0, 3.0]), "instant",
prices=Prices(repair=12000.0))
service = Task("gearbox service",
every=Recurrence.every(3, "months", "2027-04-01"), cost=800.0)
year = UsageForecast.calendar("2027-01-01", "2028-01-01")
cost_only = task_value(service, Services(gearbox), year, age=4000.0,
discount=0.07)
round(cost_only.total["value"], 2) # -> -2320.95
A benefit is credited only when you state what a service does. If the
fit of the gearbox's history (surpyval's GeneralizedRenewal) says each
service leaves 60% of its virtual age, give that restoration:
fitted = task_value(service, Services(gearbox, Restoration(q=0.6)), year,
age=4000.0, discount=0.07, mc_samples=1000, seed=4)
fitted.method # -> 'simulated'
round(fitted.total["value"], -1) # -> 3660.0
round(fitted.total["value_lower"], -1) # -> 3240.0
round(fitted.total["value_upper"], -1) # -> 4080.0
The effect is the plan's own task effect, a Restoration (Kijima I or
II: 0 as new under Kijima II, 1 no effect, which is then valued exactly
as the default, above 1 a service that does harm; or a virtual age to
restore to, or a fitted process). A Condition(life, fresh=, stale=,
lasts=) instead takes a regression life fitted with a "serviced or
overdue" covariate, at fresh for lasts after each service. With an
effect, the plan's one-node diagram is simulated with the service on its
dates and without it, from one seed, so both see the same failures until
a service changes them; each run is priced with the plan's prices, by
period. value_lower and value_upper are the value's 90% interval
(confidence=), by period and in total. The plan must hold no
preventive task of its own. A virtual age on a duty plan that changes
over time is not followed yet: give the unit's duty as one share.
A system, by month¶
A RepairableRBD runs on calendar time: its blocks' "duty" puts
running hours onto that clock. So events_by_period turns each period's
end into the real time since the forecast starts. With a failure rate
of one per 2,000 hours, January 2027 (744 h) expects 0.372 failures:
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"}},
)
year = UsageForecast.calendar("2027-01-01", "2028-01-01")
by_month = events_by_period(rbd, year, unit="hours")
round(float(by_month.events.system_failures[0]), 3) # -> 0.372
events holds expected_events_by_window's answer, which is exact.
cost=True adds cost_by_window: each period's mean cost is exact, and
its range is simulated. With cost=True, discount=0.07 each period also
has expected_npv, its expected cost as a present value, with npv and
eac; cost (its mean and range) stays the cost as it falls, not
discounted, as failures_by_period's expected_cost does. This is exact: the diagram's clock is calendar time, so the
yearly rate is one continuous rate on it, which
RepairableRBD.expected_cost(discount_rate=) takes.
Shuts on dates¶
The annual overhaul falls on the first Tuesday of November. The gap
between one and the next is 364 or 371 days, so it is not a fixed
period, and it goes in as given times. To use the dates as cheap
replacement opportunities for a part, lay them on the part's model
time. Pass usage= for a life in operating hours, or leave it out for a
life in calendar time:
from repyability import Opportunity
from repyability.schedule import Recurrence
overhaul = Recurrence.yearly(month=11, weekday="Tuesday", nth=1)
shut = Opportunity.from_recurrence(
"overhaul", 500.0, overhaul, "2026-11-16", "2027-11-30", usage=usage
)
shut.dates # (4016.0,)
To put the overhaul on a diagram as a shutdown, use shutdown_spec. Its
times are on the diagram's clock, which is the real time since the
start date's midnight:
from repyability.schedule import shutdown_spec
spec = shutdown_spec(overhaul, "2026-11-14", "2029-12-31", duration=48.0, at="06:00")
spec["times"] # [8478.0, 17382.0, 26118.0]
RepairableRBD(..., shutdowns={"overhaul": spec}) takes it. Shuts at
given times are valued over a horizon, exactly where the blocks worked
on in them are renewed (expected_npv, expected_cost), and simulated
(cost(), availability()); they end, so the long-run methods refuse
such a diagram with a message that says so.
Two clocks¶
Some lives are fitted on two clocks, such as running hours and starts
(surpyval 0.28's EquivalenceModel). The plan supplies the rate between
the two clocks: usage.rate("starts", per="hours") is 0.0625 for the
weekday pump (one start for each 16-hour run). usage.life_at_usage(model)
passes that rate to model.at_usage and returns a life in hours. With an
earlier surpyval, it refuses and names the version it needs.
Two limits, and the one doing nothing¶
When a task has two limits and one of them never sets a date in the
period, TaskDue.notes says how far behind it was. For a generator
running 15 hours a month with an oil change every 250 hours or 12
months, the note reads: "The limit "every 250 hours" set none of the
dates: when the task was first due (2027-11-14, by the other limit), it
would not have been reached until 2028-04-04, about 4.7 months later."