Skip to content

Value a service on dates: no effect by default, or a stated effect - #504

Merged
derrynknife merged 1 commit into
devfrom
build/service-value
Nov 21, 2026
Merged

derrynknife merged 1 commit into
devfrom
build/service-value

Conversation

@derrynknife

Copy link
Copy Markdown
Owner

Summary

schedule.task_value now values a service (lubricate, adjust, clean, overhaul) with Services(plan, effect=). Use case UC-67 was written in the schedule README first.

  • Default: no effect on the life. The service is an accepted cost. Its value is minus its cost's present value, worked out exactly with no simulation, and the notes say the effect was taken as none. A benefit is never invented. A Kijima factor of exactly 1 says the same thing ("as old as it was"), so it is valued the same way.
  • A stated effect is the plan's own task effect:
    • a maintenance.Restoration: a Kijima I or II factor from 0 (as new at 0 under Kijima II, harmful above 1), a virtual age, or a fitted process;
    • a new schedule.Condition(life, fresh=, stale=, lasts=): a regression life fitted with a serviced-or-overdue covariate. The service dates become a covariate schedule on the diagram's clock.
  • How an effect is valued. The plan's one-node diagram (UnitPlan.diagram, on a CalendarContext that gives it its duty) is simulated with the service as a no-duration task at the dated times, and again without it, from one seed. The node draws the same random numbers in both runs, as in compare_npv. Each run is priced by _npv_runs.priced_chunk with the plan's prices, through the money module's Ledger, by calendar period. The service's own cost is the exact amount, the same as in the default case.
  • TaskValue gains method ("exact"/"simulated"), value_lower, value_upper, confidence, n_simulations and seed. task_value takes mc_samples=, seed= and confidence=, with a 90% two-sided interval by default.
  • Anything the engine does not follow is refused with the engine's own reason, for example a virtual age on a duty plan that changes over time. A plan that already holds a preventive task is refused, with a message saying to value the service on the plan without it.
  • No existing result changes, and the engines are untouched.

Type of change

  • New feature

Checklist

  • Tests added (test_schedule_services.py, 11 tests):
    • the default against the hand numbers to the cent;
    • a factor of 1 equal to the default bit for bit;
    • "as new" against the existing exact block replacement on the same dates, within 4 standard errors;
    • "as new" with minimal repairs from new against the overhaul closed form, within 4 standard errors;
    • seeded runs repeat;
    • the interval narrows with more runs;
    • the value falls as the factor rises (0, 0.6, 1.2);
    • an exponential life gains nothing at any factor;
    • a fitted condition's sign follows its covariate;
    • the covariate schedule merges overlapping services;
    • refusals.
  • black, isort, flake8 and mypy on the changed files
  • CHANGELOG.md updated
  • Monte-Carlo tests are seeded

Notes for reviewers

Tests run, one process each:

  • test_schedule_services: 11 passed, all on their first run with seeds fixed beforehand.
  • test_schedule_value, test_schedule_finds, test_help, test_messages, and test_docs_examples for the schedule pages, plus the doctests of _value.py and _service.py: 73 passed.
  • test_api_docstrings: the new names pass. Its failures for the UnitPlan task classes (missing parameter docs, and the API page) already fail on dev, and this change does not touch them.

Generated by Claude Code

task_value takes Services(plan, effect=). With no effect the service is
an accepted cost, valued exactly at minus its cost's present value. A
maintenance.Restoration or a fitted schedule.Condition credits a benefit:
the plan's one-node diagram is simulated with the service on its dates
and without it on common random numbers, each run priced with the plan's
prices by period, and the value comes with its interval. Use case UC-67
in the schedule README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6RpnXB87vwhYETeh7ihtA
@derrynknife
derrynknife merged commit e636b52 into dev Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants