@mark1russell7/stack-endurance 0.0.0-stage → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js ADDED
@@ -0,0 +1,604 @@
1
+ import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
+ import { a as hasEnduranceError, c as drawDemand, d as giftResource, f as storeAmounts, i as curveFault, l as enduranceOf, n as ENDURANCE_CODES, o as caseDraws, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed } from "./join-D7KyUpGf.js";
3
+ import { STACK_SCHEMA, neededParts } from "@mark1russell7/system-stack";
4
+ // src/shortfall.ts
5
+ /** This function gives the chance that a cut lasts more than `days`, linear between the points of the curve. After the last point it is 0. */
6
+ function survivalAt(curve, days) {
7
+ if (days <= 0) return curve[0]?.[1] ?? 0;
8
+ for (let index = 1; index < curve.length; index += 1) {
9
+ const [t0, p0] = curve[index - 1] ?? [0, 1];
10
+ const [t1, p1] = curve[index] ?? [0, 0];
11
+ if (days < t1) {
12
+ const chance = p0 + (p1 - p0) * ((days - t0) / (t1 - t0));
13
+ return Math.min(Math.max(p0, p1), Math.max(Math.min(p0, p1), chance));
14
+ }
15
+ if (days === t1) return p1;
16
+ }
17
+ return 0;
18
+ }
19
+ /**
20
+ * This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.
21
+ * It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.
22
+ * With no horizon, the area goes to the end of the curve.
23
+ */
24
+ function tailDays(curve, from, to = 1e400) {
25
+ let area = 0;
26
+ for (let index = 1; index < curve.length; index += 1) {
27
+ const [t0] = curve[index - 1] ?? [0, 1];
28
+ const [t1] = curve[index] ?? [0, 0];
29
+ const start = Math.max(t0, from);
30
+ const end = Math.min(t1, to);
31
+ if (start < end) area += (survivalAt(curve, start) + survivalAt(curve, end)) / 2 * (end - start);
32
+ }
33
+ return area;
34
+ }
35
+ function horizonOf(options) {
36
+ const horizon = options.horizon ?? 1e400;
37
+ if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);
38
+ return horizon;
39
+ }
40
+ /**
41
+ * This function gives the days at which the chance of the curve falls to `chance`. With `0.1`, it is the 90th percentile of the duration.
42
+ * When the curve does not fall to `chance`, the result is `Infinity`.
43
+ */
44
+ function survivalQuantile(curve, chance) {
45
+ for (let index = 1; index < curve.length; index += 1) {
46
+ const [t0, p0] = curve[index - 1] ?? [0, 1];
47
+ const [t1, p1] = curve[index] ?? [0, 0];
48
+ if (p0 <= chance) return t0;
49
+ if (p1 <= chance) return t0 + (p0 - chance) * (t1 - t0) / (p0 - p1);
50
+ }
51
+ return 1e400;
52
+ }
53
+ /** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */
54
+ function yearChance(prior) {
55
+ return 1 - Math.exp(-prior.perYear * prior.reach);
56
+ }
57
+ /** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */
58
+ function yearRate(prior) {
59
+ return prior.perYear * prior.reach;
60
+ }
61
+ /** This function gives the times at which a curve of the result can bend: each point of each curve, and each crossing of two curves. */
62
+ function bendTimes(curves) {
63
+ const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);
64
+ const out = new Set(times);
65
+ for (let index = 1; index < times.length; index += 1) {
66
+ const t0 = times[index - 1] ?? 0;
67
+ const t1 = times[index] ?? 0;
68
+ for (const [i, a] of curves.entries()) for (const b of curves.slice(i + 1)) {
69
+ const d0 = survivalAt(a, t0) - survivalAt(b, t0);
70
+ const d1 = survivalAt(a, t1) - survivalAt(b, t1);
71
+ if (d0 * d1 < 0) out.add(t0 + (t1 - t0) * d0 / (d0 - d1));
72
+ }
73
+ }
74
+ return [...out].sort((x, y) => x - y);
75
+ }
76
+ /**
77
+ * This function makes a survival curve from a chance at each time. It stops at the first chance of 0, and it removes an increase of rounding.
78
+ *
79
+ * @throws RangeError when the chance at the last time is more than 0, as for curves that do not end at a chance of 0
80
+ */
81
+ function curveFrom(times, chanceAt) {
82
+ const out = [];
83
+ for (const days of times) {
84
+ const chance = Math.min(out[out.length - 1]?.[1] ?? 1, chanceAt(days));
85
+ out.push([days, chance]);
86
+ if (chance === 0) return out;
87
+ }
88
+ throw new RangeError("The curves do not fall to a chance of 0 at their last point.");
89
+ }
90
+ /**
91
+ * This function gives the curve of a stop of some cuts when one event makes each cut longer together.
92
+ * At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.
93
+ *
94
+ * - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).
95
+ * - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.
96
+ * - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.
97
+ * - When no set of cuts stops the supply, the result is `[[0, 0]]`. This curve does not start at `[0, 1]`, so `checkEndurance` refuses it.
98
+ *
99
+ * The result is not a limit. When the cuts are independent, a stop of two cuts in series can be longer. A stop through a need of `any` can be shorter.
100
+ *
101
+ * @param curves - The curves of the cuts, each one good for `checkEndurance`
102
+ * @param stops - This function tells if the cuts of a list of indexes stop the supply. A larger list stops it when a smaller list does.
103
+ * @throws RangeError when a curve does not end at a chance of 0
104
+ */
105
+ function eventStop(curves, stops) {
106
+ return curveFrom(bendTimes(curves), (days) => {
107
+ const chances = curves.map((curve) => survivalAt(curve, days));
108
+ for (const level of [...new Set(chances)].sort((x, y) => y - x)) if (stops(chances.flatMap((chance, index) => chance >= level ? [index] : []))) return level;
109
+ return 0;
110
+ });
111
+ }
112
+ /**
113
+ * This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.
114
+ * It is `eventStop` when any one cut stops the supply.
115
+ *
116
+ * @param curves - The curves, each one good for `checkEndurance`
117
+ * @throws RangeError when there is no curve, or when a curve does not end at a chance of 0
118
+ */
119
+ function longestStop(curves) {
120
+ const first = curves[0];
121
+ if (first === void 0) throw new RangeError("longestStop needs one or more curves.");
122
+ return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);
123
+ }
124
+ /**
125
+ * The largest count of cuts for which `minimalStops` examines each set.
126
+ * `stopCurves` counts only the cuts that can reach the supply. Past this count, its `upper` is coarse.
127
+ */
128
+ const MINIMAL_STOP_CUTS = 12;
129
+ /**
130
+ * This function gives the minimal sets of cuts that stop the supply: each set stops it, and no smaller part of a set stops it.
131
+ * With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.
132
+ */
133
+ function minimalStops(count, stops) {
134
+ if (count > 12) return void 0;
135
+ const found = [];
136
+ const masks = [];
137
+ const all = Array.from({ length: 1 << count }, (_, mask) => mask).sort((x, y) => popCount(x) - popCount(y) || x - y);
138
+ for (const mask of all) {
139
+ if (mask === 0 || masks.some((other) => (other & mask) === other)) continue;
140
+ const cuts = Array.from({ length: count }, (_, index) => index).filter((index) => mask >> index & 1);
141
+ if (!stops(cuts)) continue;
142
+ masks.push(mask);
143
+ found.push(cuts);
144
+ }
145
+ return found;
146
+ }
147
+ function popCount(mask) {
148
+ let total = 0;
149
+ for (let rest = mask; rest > 0; rest &= rest - 1) total += 1;
150
+ return total;
151
+ }
152
+ /**
153
+ * This function gives an upper limit of the curve of a stop for each dependence of the cuts.
154
+ * At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.
155
+ * With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.
156
+ *
157
+ * @param curves - The curves of the cuts
158
+ * @param sets - The minimal sets of `minimalStops`, or `undefined`
159
+ * @throws RangeError when a curve does not end at a chance of 0
160
+ */
161
+ function upperStop(curves, sets) {
162
+ const groups = sets ?? curves.map((_, index) => [index]);
163
+ const sum = (days) => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);
164
+ const times = bendTimes(curves);
165
+ const bends = new Set(times);
166
+ for (let index = 1; index < times.length; index += 1) {
167
+ const t0 = times[index - 1] ?? 0;
168
+ const t1 = times[index] ?? 0;
169
+ const s0 = sum(t0) - 1;
170
+ const s1 = sum(t1) - 1;
171
+ if (s0 * s1 < 0) bends.add(t0 + (t1 - t0) * s0 / (s0 - s1));
172
+ }
173
+ return curveFrom([...bends].sort((x, y) => x - y), (days) => Math.min(1, sum(days)));
174
+ }
175
+ /** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */
176
+ const INDEPENDENT_TOLERANCE = 1e-6;
177
+ /**
178
+ * This function gives the curve of a stop of some cuts when the cuts are independent.
179
+ * At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.
180
+ * Its chance is a sum over each set of cuts that stops the supply.
181
+ * Each term is the product of `s(t)` for the cuts that are on, and of `1 - s(t)` for the other cuts.
182
+ *
183
+ * - When any one cut stops the supply, the result is `1 - prod(1 - s)`. It is not less than the longest cut (`eventStop`).
184
+ * - When the supply needs `any` of two parts, the stop of the two is `s1 * s2`. It is not more than the shorter cut.
185
+ * - The result is not more than `upperStop` of the same sets, because `upperStop` is a limit for each dependence.
186
+ * - Between two points of the curves the chance is a polynomial, not a line. The function splits each such segment into equal pieces.
187
+ * The chance is linear in each `s`, and each mixed second derivative is between -1 and 1.
188
+ * Thus `|f''| <= (sum |s'|)^2 - sum s'^2`, and the line of a piece of length `h` is within `h^2 |f''| / 8` of the chance.
189
+ * The count of pieces keeps each line within `INDEPENDENT_TOLERANCE`. With a margin of 10 %, the count of points is less than `n / sqrt(7.2 * INDEPENDENT_TOLERANCE)` plus the segments, for `n` cuts.
190
+ *
191
+ * @param curves - The curves of the cuts, each one good for `checkEndurance`
192
+ * @param sets - The minimal sets of `minimalStops`. With `undefined`, as for too many cuts, the result is `undefined`. With no sets, it is `[[0, 0]]`
193
+ * @throws RangeError when a curve does not end at a chance of 0
194
+ */
195
+ function independentStop(curves, sets) {
196
+ if (sets === void 0) return void 0;
197
+ if (sets.length === 0) return [[0, 0]];
198
+ const used = [...new Set(sets.flat())].sort((x, y) => x - y);
199
+ const usedCurves = used.map((index) => curves[index] ?? []);
200
+ const setMasks = sets.map((set) => set.reduce((mask, index) => mask | 1 << used.indexOf(index), 0));
201
+ const stopping = Array.from({ length: 1 << used.length }, (_, mask) => setMasks.some((set) => (set & mask) === set));
202
+ const states = new Float64Array(1 << used.length);
203
+ const chanceAt = (days) => {
204
+ states[0] = 1;
205
+ let length = 1;
206
+ for (const curve of usedCurves) {
207
+ const on = survivalAt(curve, days);
208
+ for (let mask = 0; mask < length; mask += 1) {
209
+ const chance = states[mask] ?? 0;
210
+ states[mask + length] = chance * on;
211
+ states[mask] = chance * (1 - on);
212
+ }
213
+ length *= 2;
214
+ }
215
+ let total = 0;
216
+ for (let mask = 0; mask < length; mask += 1) if (stopping[mask]) total += states[mask] ?? 0;
217
+ return Math.min(1, Math.max(0, total));
218
+ };
219
+ const times = [...new Set(usedCurves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);
220
+ const points = [];
221
+ for (const [index, t1] of times.entries()) {
222
+ const t0 = times[index - 1];
223
+ if (t0 !== void 0) {
224
+ const h = t1 - t0;
225
+ const slopes = usedCurves.map((curve) => Math.abs(survivalAt(curve, t1) - survivalAt(curve, t0)) / h);
226
+ const sum = slopes.reduce((total, slope) => total + slope, 0);
227
+ const bound = Math.max(0, sum * sum - slopes.reduce((total, slope) => total + slope * slope, 0));
228
+ const pieces = Math.ceil(h * Math.sqrt(bound / (7.2 * INDEPENDENT_TOLERANCE)));
229
+ for (let piece = 1; piece < pieces; piece += 1) {
230
+ const days = t0 + h * piece / pieces;
231
+ if (days > (points[points.length - 1] ?? t0) && days < t1) points.push(days);
232
+ }
233
+ }
234
+ points.push(t1);
235
+ }
236
+ return curveFrom(points, chanceAt);
237
+ }
238
+ function stoppedMemo(caseCuts, options) {
239
+ const memo = /* @__PURE__ */ new Map();
240
+ return (cuts) => {
241
+ const key = cuts.join(",");
242
+ let found = memo.get(key);
243
+ if (found === void 0) {
244
+ found = caseStopped({
245
+ ...caseCuts,
246
+ cuts: cuts.flatMap((index) => caseCuts.cuts[index] ?? [])
247
+ }, options);
248
+ memo.set(key, found);
249
+ }
250
+ return found;
251
+ };
252
+ }
253
+ /** This function gives the parts whose cut can stop a supply: the supply, and each part that it needs through the stack. */
254
+ function supplyReach(supply, options) {
255
+ const reach = options.stack === void 0 ? /* @__PURE__ */ new Set() : neededParts(options.stack, supply);
256
+ reach.add(supply);
257
+ return reach;
258
+ }
259
+ function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
260
+ const reach = supplyReach(draw.supply, options);
261
+ const relevant = caseCuts.cuts.flatMap((cut, index) => reach.has(cut.part) ? [index] : []);
262
+ const stops = (cuts) => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);
263
+ if (stops([])) return void 0;
264
+ if (!stops(relevant.map((_, index) => index))) return void 0;
265
+ const curves = relevant.map((index) => caseCuts.cuts[index]?.duration ?? []);
266
+ const sets = minimalStops(curves.length, stops);
267
+ const upper = upperStop(curves, sets);
268
+ return {
269
+ event: eventStop(curves, stops),
270
+ independent: independentStop(curves, sets) ?? upper,
271
+ upper,
272
+ coarse: sets === void 0
273
+ };
274
+ }
275
+ /**
276
+ * This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.
277
+ *
278
+ * - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.
279
+ * - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.
280
+ * - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.
281
+ * - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.
282
+ * - Past `MINIMAL_STOP_CUTS` cuts that count, `upper` is the sum of their curves, `independent` is `upper`, and `coarse` is true.
283
+ */
284
+ function stopCurves(caseCuts, draw, options = {}) {
285
+ return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));
286
+ }
287
+ function zeroLevels(layer) {
288
+ return Object.fromEntries(layer.levels.map((level) => [level, 0]));
289
+ }
290
+ /**
291
+ * This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.
292
+ * `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.
293
+ *
294
+ * @param layer - The endurance layer
295
+ * @param caseCuts - The case
296
+ * @param endurance - The endurance of the case, from `enduranceOf`
297
+ * @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon
298
+ * @throws RangeError when the horizon is not a number more than 0
299
+ */
300
+ function caseShortfall(layer, caseCuts, endurance, options = {}) {
301
+ const horizon = horizonOf(options);
302
+ const levels = zeroLevels(layer);
303
+ const independent = zeroLevels(layer);
304
+ const upper = zeroLevels(layer);
305
+ const unread = [];
306
+ const coarse = [];
307
+ const stoppedOf = stoppedMemo(caseCuts, options);
308
+ for (const draw of caseDraws(layer, caseCuts, caseStopped(caseCuts, options))) {
309
+ const held = endurance.needs[draw.need];
310
+ const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);
311
+ if (held === void 0 || curves === void 0) {
312
+ unread.push(draw.need);
313
+ continue;
314
+ }
315
+ if (curves.coarse) coarse.push(draw.need);
316
+ const users = draw.users ?? 1;
317
+ levels[draw.level] = (levels[draw.level] ?? 0) + tailDays(curves.event, held.days, horizon) * users;
318
+ independent[draw.level] = (independent[draw.level] ?? 0) + tailDays(curves.independent, held.days, horizon) * users;
319
+ upper[draw.level] = (upper[draw.level] ?? 0) + tailDays(curves.upper, held.days, horizon) * users;
320
+ }
321
+ return {
322
+ levels,
323
+ independent,
324
+ upper,
325
+ unread,
326
+ coarse
327
+ };
328
+ }
329
+ /**
330
+ * This function gives the shortfall of one year at one place.
331
+ * It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.
332
+ *
333
+ * - The expected count of a case is `perYear * reach`, from the first prior of the case at the place. Thus the result is the expected user-days of one year.
334
+ * - A case with no prior at the place is not in the sum.
335
+ * - `unread` is the union of the needs that a case cannot read, in the order of the cases. `coarse` is the union of the coarse needs.
336
+ *
337
+ * @param layer - The endurance layer, with its cases and priors
338
+ * @param place - The place of the priors
339
+ * @param options - The date, the stack or the parts that are also down, and the horizon
340
+ * @throws RangeError when the date is not `YYYY-MM-DD`, or when the horizon is not a number more than 0
341
+ */
342
+ function yearShortfall(layer, place, options) {
343
+ horizonOf(options);
344
+ const levels = zeroLevels(layer);
345
+ const independent = zeroLevels(layer);
346
+ const upper = zeroLevels(layer);
347
+ const unread = [];
348
+ const coarse = [];
349
+ const cases = [];
350
+ for (const caseCuts of layer.cases ?? []) {
351
+ const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);
352
+ if (prior === void 0) continue;
353
+ const rate = yearRate(prior);
354
+ const endurance = enduranceOf(layer, caseCuts, options);
355
+ const shortfall = caseShortfall(layer, caseCuts, endurance, options);
356
+ for (const [level, days] of Object.entries(shortfall.levels)) levels[level] = (levels[level] ?? 0) + rate * days;
357
+ for (const [level, days] of Object.entries(shortfall.independent)) independent[level] = (independent[level] ?? 0) + rate * days;
358
+ for (const [level, days] of Object.entries(shortfall.upper)) upper[level] = (upper[level] ?? 0) + rate * days;
359
+ for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);
360
+ for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);
361
+ cases.push({
362
+ case: caseCuts.case,
363
+ rate,
364
+ endurance,
365
+ shortfall
366
+ });
367
+ }
368
+ return {
369
+ place,
370
+ levels,
371
+ independent,
372
+ upper,
373
+ unread,
374
+ coarse,
375
+ cases
376
+ };
377
+ }
378
+ // src/sample.ts
379
+ /** The base stack of the sample: the supplies of the building and a camp stove. */
380
+ const SAMPLE_ENDURANCE_STACK = {
381
+ schema: STACK_SCHEMA,
382
+ parts: [
383
+ {
384
+ id: "grid",
385
+ kind: "power",
386
+ name: "The power grid"
387
+ },
388
+ {
389
+ id: "water-main",
390
+ kind: "water",
391
+ name: "The water main"
392
+ },
393
+ {
394
+ id: "road",
395
+ kind: "road",
396
+ name: "The local road to the shops"
397
+ },
398
+ {
399
+ id: "stove",
400
+ kind: "device",
401
+ name: "The camp stove"
402
+ }
403
+ ]
404
+ };
405
+ /**
406
+ * The endurance layer of the sample.
407
+ *
408
+ * - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.
409
+ * - The food holds 4800 / 5400 = 0.889 days. The rice needs 2 L of water for each kg, and the drinking water keeps back all the water.
410
+ * - The power holds 1000 Wh / 150 Wh a day = 6.667 days.
411
+ * - The filled bottles are past their due date, so they give nothing.
412
+ */
413
+ const SAMPLE_ENDURANCE = {
414
+ schema: ENDURANCE_SCHEMA,
415
+ levels: [
416
+ "life",
417
+ "health",
418
+ "comfort"
419
+ ],
420
+ resources: [
421
+ {
422
+ code: "water.stored",
423
+ unit: "L"
424
+ },
425
+ {
426
+ code: "food.ready",
427
+ unit: "kcal"
428
+ },
429
+ {
430
+ code: "food.grain-dry",
431
+ unit: "kg"
432
+ },
433
+ {
434
+ code: "fuel.propane",
435
+ unit: "kg"
436
+ },
437
+ {
438
+ code: "energy.battery",
439
+ unit: "Wh"
440
+ }
441
+ ],
442
+ stores: [
443
+ {
444
+ id: "jugs",
445
+ resource: "water.stored",
446
+ amount: 75.7,
447
+ due: "2028-06-01"
448
+ },
449
+ {
450
+ id: "bottles",
451
+ resource: "water.stored",
452
+ amount: 20,
453
+ due: "2026-09-30"
454
+ },
455
+ {
456
+ id: "cans",
457
+ resource: "food.ready",
458
+ amount: 4800,
459
+ due: "2028-10-01"
460
+ },
461
+ {
462
+ id: "rice",
463
+ resource: "food.grain-dry",
464
+ amount: 9,
465
+ due: "2036-09-28"
466
+ },
467
+ {
468
+ id: "propane",
469
+ resource: "fuel.propane",
470
+ amount: .908,
471
+ due: "2036-10-01"
472
+ },
473
+ {
474
+ id: "battery",
475
+ resource: "energy.battery",
476
+ amount: 1e3,
477
+ due: "2031-10-01"
478
+ }
479
+ ],
480
+ draws: [
481
+ {
482
+ need: "hydration.drink",
483
+ level: "life",
484
+ perDay: 11.355,
485
+ users: 3,
486
+ supply: "water-main"
487
+ },
488
+ {
489
+ need: "food.energy",
490
+ level: "health",
491
+ perDay: 5400,
492
+ users: 3,
493
+ supply: "road"
494
+ },
495
+ {
496
+ need: "power.electric",
497
+ level: "comfort",
498
+ perDay: 150,
499
+ users: 3,
500
+ supply: "grid"
501
+ }
502
+ ],
503
+ direct: [
504
+ {
505
+ resource: "water.stored",
506
+ need: "hydration.drink",
507
+ amount: 1
508
+ },
509
+ {
510
+ resource: "food.ready",
511
+ need: "food.energy",
512
+ amount: 1
513
+ },
514
+ {
515
+ resource: "energy.battery",
516
+ need: "power.electric",
517
+ amount: 1
518
+ }
519
+ ],
520
+ converters: [{
521
+ id: "cook-rice",
522
+ device: "stove",
523
+ takes: [
524
+ {
525
+ resource: "food.grain-dry",
526
+ amount: 1
527
+ },
528
+ {
529
+ resource: "water.stored",
530
+ amount: 2
531
+ },
532
+ {
533
+ resource: "fuel.propane",
534
+ amount: .05
535
+ }
536
+ ],
537
+ gives: {
538
+ need: "food.energy",
539
+ amount: 3600
540
+ }
541
+ }],
542
+ cases: [{
543
+ case: "storm",
544
+ title: "Winter storm",
545
+ cuts: [
546
+ {
547
+ part: "grid",
548
+ title: "Power outage",
549
+ duration: [
550
+ [0, 1],
551
+ [.5, .5],
552
+ [1, .36],
553
+ [7, .013],
554
+ [30, 0]
555
+ ],
556
+ source: "nrel-83092"
557
+ },
558
+ {
559
+ part: "road",
560
+ title: "Closed local road",
561
+ duration: [
562
+ [0, 1],
563
+ [1, .6],
564
+ [3, .2],
565
+ [10, 0]
566
+ ],
567
+ source: "sample"
568
+ },
569
+ {
570
+ part: "water-main",
571
+ title: "No water from the main",
572
+ duration: [
573
+ [0, 1],
574
+ [2, .3],
575
+ [7, 0]
576
+ ],
577
+ source: "sample"
578
+ }
579
+ ],
580
+ leadSeconds: 86400
581
+ }, {
582
+ case: "fire",
583
+ title: "Fire",
584
+ cuts: []
585
+ }],
586
+ priors: [{
587
+ case: "storm",
588
+ place: "home",
589
+ perYear: .8,
590
+ reach: 1,
591
+ source: "sample",
592
+ asOf: "2025-12-01"
593
+ }, {
594
+ case: "fire",
595
+ place: "home",
596
+ perYear: .003,
597
+ reach: 1,
598
+ source: "sample",
599
+ asOf: "2025-12-01"
600
+ }]
601
+ };
602
+ export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, caseDraws, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, independentStop, joinEndurance, longestStop, minimalStops, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
603
+
604
+ //# sourceMappingURL=index.js.map