Skerry/ Guides

Supplies that run out

Use set or learned, the runs-out date, the reorder point and a draft refill.

Things a person or a business uses up: paper, coffee, cleaning, stock, household items. Skerry knows how much was bought, learns or is told how fast it is used, says when it runs out, and drafts the refill.

Migration: db/050_subscriptions_supplies.sql. Code: lib/supplies.ts; the forecast is pure code in lib/pure/supply.ts. It is worked out whenever a supply is read, so it is never stale.

Use

  • Set by the person: usage: { per: "day" | "week" | "month", qty }.
  • Learned from purchases when none is set (use_method): the plain rate for steady use (what was bought and used between the first and last purchase). When purchases are lumpy (average interval above 1.32 weeks and a squared coefficient of variation of size above 0.49, the Syntetos-Boylan classification), Croston's method with the Syntetos-Boylan correction, which removes Croston's upward bias. With fewer than two purchases nothing is learned and use_method is unknown.

When to reorder

reorder_point = use per day x lead days + z x sd x sqrt(lead days), with z from service_level (0.95 gives 1.645) and the spread of use taken as half the mean until it is measured. The point is an upper quantile of use over the lead time, not the mean, so a late delivery does not leave the person without. lead_days is the median of order-to-delivery days over purchases that carry delivered_on, else the value set (default 3). needs_reorder is true at or below the point; reorder_by is the day stock reaches it; runs_out the day it reaches zero.

Corrections and refill

POST /supplies/{id}/ran-out and /counted restart the forecast from what is true. GET /supplies/{id}/reorder is a draft: quantity (use over cover_days, default 30), the usual supplier and price, the date to order by. Nothing is ordered or paid by it; the order is a bill, a payout under the person's limits, or a shop order from a connected shop. supply.runs_out_soon is sent once per runs-out date.

Scopes: supplies:read, supplies:write. A business with Rivier keeps stock in Rivier (stock_ref links it); Skerry reads that instead of keeping a second count.

Written and kept by Skerry. Read from https://api.skerry.xyz/guides/supplies.md.

This page as Markdown