@mark1russell7/stack-endurance 0.0.0-stage → 0.3.1
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/LICENSE +21 -0
- package/README.md +87 -2
- package/build/add-on.d.ts +12 -0
- package/build/add-on.d.ts.map +1 -0
- package/build/add-on.js +23 -0
- package/build/add-on.js.map +1 -0
- package/build/index.d.ts +258 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +529 -0
- package/build/index.js.map +1 -0
- package/build/join-D7KyUpGf.js +557 -0
- package/build/join-D7KyUpGf.js.map +1 -0
- package/build/layer-DzGZC5XH.d.ts +143 -0
- package/build/layer-DzGZC5XH.d.ts.map +1 -0
- package/build/layer-a3Fr70Uh.js +6 -0
- package/build/layer-a3Fr70Uh.js.map +1 -0
- package/build/schema.d.ts +21 -0
- package/build/schema.d.ts.map +1 -0
- package/build/schema.js +99 -0
- package/build/schema.js.map +1 -0
- package/package.json +75 -3
package/build/index.js
ADDED
|
@@ -0,0 +1,529 @@
|
|
|
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) return p0 + (p1 - p0) * (days - t0) / (t1 - t0);
|
|
12
|
+
}
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.
|
|
17
|
+
* It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.
|
|
18
|
+
* With no horizon, the area goes to the end of the curve.
|
|
19
|
+
*/
|
|
20
|
+
function tailDays(curve, from, to = 1e400) {
|
|
21
|
+
let area = 0;
|
|
22
|
+
for (let index = 1; index < curve.length; index += 1) {
|
|
23
|
+
const [t0] = curve[index - 1] ?? [0, 1];
|
|
24
|
+
const [t1] = curve[index] ?? [0, 0];
|
|
25
|
+
const start = Math.max(t0, from);
|
|
26
|
+
const end = Math.min(t1, to);
|
|
27
|
+
if (start < end) area += (survivalAt(curve, start) + survivalAt(curve, end)) / 2 * (end - start);
|
|
28
|
+
}
|
|
29
|
+
return area;
|
|
30
|
+
}
|
|
31
|
+
function horizonOf(options) {
|
|
32
|
+
const horizon = options.horizon ?? 1e400;
|
|
33
|
+
if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);
|
|
34
|
+
return horizon;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 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.
|
|
38
|
+
* When the curve does not fall to `chance`, the result is `Infinity`.
|
|
39
|
+
*/
|
|
40
|
+
function survivalQuantile(curve, chance) {
|
|
41
|
+
for (let index = 1; index < curve.length; index += 1) {
|
|
42
|
+
const [t0, p0] = curve[index - 1] ?? [0, 1];
|
|
43
|
+
const [t1, p1] = curve[index] ?? [0, 0];
|
|
44
|
+
if (p0 <= chance) return t0;
|
|
45
|
+
if (p1 <= chance) return t0 + (p0 - chance) * (t1 - t0) / (p0 - p1);
|
|
46
|
+
}
|
|
47
|
+
return 1e400;
|
|
48
|
+
}
|
|
49
|
+
/** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */
|
|
50
|
+
function yearChance(prior) {
|
|
51
|
+
return 1 - Math.exp(-prior.perYear * prior.reach);
|
|
52
|
+
}
|
|
53
|
+
/** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */
|
|
54
|
+
function yearRate(prior) {
|
|
55
|
+
return prior.perYear * prior.reach;
|
|
56
|
+
}
|
|
57
|
+
/** 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. */
|
|
58
|
+
function bendTimes(curves) {
|
|
59
|
+
const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);
|
|
60
|
+
const out = new Set(times);
|
|
61
|
+
for (let index = 1; index < times.length; index += 1) {
|
|
62
|
+
const t0 = times[index - 1] ?? 0;
|
|
63
|
+
const t1 = times[index] ?? 0;
|
|
64
|
+
for (const [i, a] of curves.entries()) for (const b of curves.slice(i + 1)) {
|
|
65
|
+
const d0 = survivalAt(a, t0) - survivalAt(b, t0);
|
|
66
|
+
const d1 = survivalAt(a, t1) - survivalAt(b, t1);
|
|
67
|
+
if (d0 * d1 < 0) out.add(t0 + (t1 - t0) * d0 / (d0 - d1));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return [...out].sort((x, y) => x - y);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 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.
|
|
74
|
+
*
|
|
75
|
+
* @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
|
|
76
|
+
*/
|
|
77
|
+
function curveFrom(times, chanceAt) {
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const days of times) {
|
|
80
|
+
const chance = Math.min(out[out.length - 1]?.[1] ?? 1, chanceAt(days));
|
|
81
|
+
out.push([days, chance]);
|
|
82
|
+
if (chance === 0) return out;
|
|
83
|
+
}
|
|
84
|
+
throw new RangeError("The curves do not fall to a chance of 0 at their last point.");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* This function gives the curve of a stop of some cuts when one event makes each cut longer together.
|
|
88
|
+
* At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.
|
|
89
|
+
*
|
|
90
|
+
* - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).
|
|
91
|
+
* - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.
|
|
92
|
+
* - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.
|
|
93
|
+
* - 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.
|
|
94
|
+
*
|
|
95
|
+
* 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.
|
|
96
|
+
*
|
|
97
|
+
* @param curves - The curves of the cuts, each one good for `checkEndurance`
|
|
98
|
+
* @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.
|
|
99
|
+
* @throws RangeError when a curve does not end at a chance of 0
|
|
100
|
+
*/
|
|
101
|
+
function eventStop(curves, stops) {
|
|
102
|
+
return curveFrom(bendTimes(curves), (days) => {
|
|
103
|
+
const chances = curves.map((curve) => survivalAt(curve, days));
|
|
104
|
+
for (const level of [...new Set(chances)].sort((x, y) => y - x)) if (stops(chances.flatMap((chance, index) => chance >= level ? [index] : []))) return level;
|
|
105
|
+
return 0;
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.
|
|
110
|
+
* It is `eventStop` when any one cut stops the supply.
|
|
111
|
+
*
|
|
112
|
+
* @param curves - The curves, each one good for `checkEndurance`
|
|
113
|
+
* @throws RangeError when there is no curve, or when a curve does not end at a chance of 0
|
|
114
|
+
*/
|
|
115
|
+
function longestStop(curves) {
|
|
116
|
+
const first = curves[0];
|
|
117
|
+
if (first === void 0) throw new RangeError("longestStop needs one or more curves.");
|
|
118
|
+
return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* The largest count of cuts for which `minimalStops` examines each set.
|
|
122
|
+
* `stopCurves` counts only the cuts that can reach the supply. Past this count, its `upper` is coarse.
|
|
123
|
+
*/
|
|
124
|
+
const MINIMAL_STOP_CUTS = 12;
|
|
125
|
+
/**
|
|
126
|
+
* 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.
|
|
127
|
+
* With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.
|
|
128
|
+
*/
|
|
129
|
+
function minimalStops(count, stops) {
|
|
130
|
+
if (count > 12) return void 0;
|
|
131
|
+
const found = [];
|
|
132
|
+
const masks = [];
|
|
133
|
+
const all = Array.from({ length: 1 << count }, (_, mask) => mask).sort((x, y) => popCount(x) - popCount(y) || x - y);
|
|
134
|
+
for (const mask of all) {
|
|
135
|
+
if (mask === 0 || masks.some((other) => (other & mask) === other)) continue;
|
|
136
|
+
const cuts = Array.from({ length: count }, (_, index) => index).filter((index) => mask >> index & 1);
|
|
137
|
+
if (!stops(cuts)) continue;
|
|
138
|
+
masks.push(mask);
|
|
139
|
+
found.push(cuts);
|
|
140
|
+
}
|
|
141
|
+
return found;
|
|
142
|
+
}
|
|
143
|
+
function popCount(mask) {
|
|
144
|
+
let total = 0;
|
|
145
|
+
for (let rest = mask; rest > 0; rest &= rest - 1) total += 1;
|
|
146
|
+
return total;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* This function gives an upper limit of the curve of a stop for each dependence of the cuts.
|
|
150
|
+
* At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.
|
|
151
|
+
* With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.
|
|
152
|
+
*
|
|
153
|
+
* @param curves - The curves of the cuts
|
|
154
|
+
* @param sets - The minimal sets of `minimalStops`, or `undefined`
|
|
155
|
+
* @throws RangeError when a curve does not end at a chance of 0
|
|
156
|
+
*/
|
|
157
|
+
function upperStop(curves, sets) {
|
|
158
|
+
const groups = sets ?? curves.map((_, index) => [index]);
|
|
159
|
+
const sum = (days) => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);
|
|
160
|
+
const times = bendTimes(curves);
|
|
161
|
+
const bends = new Set(times);
|
|
162
|
+
for (let index = 1; index < times.length; index += 1) {
|
|
163
|
+
const t0 = times[index - 1] ?? 0;
|
|
164
|
+
const t1 = times[index] ?? 0;
|
|
165
|
+
const s0 = sum(t0) - 1;
|
|
166
|
+
const s1 = sum(t1) - 1;
|
|
167
|
+
if (s0 * s1 < 0) bends.add(t0 + (t1 - t0) * s0 / (s0 - s1));
|
|
168
|
+
}
|
|
169
|
+
return curveFrom([...bends].sort((x, y) => x - y), (days) => Math.min(1, sum(days)));
|
|
170
|
+
}
|
|
171
|
+
function stoppedMemo(caseCuts, options) {
|
|
172
|
+
const memo = /* @__PURE__ */ new Map();
|
|
173
|
+
return (cuts) => {
|
|
174
|
+
const key = cuts.join(",");
|
|
175
|
+
let found = memo.get(key);
|
|
176
|
+
if (found === void 0) {
|
|
177
|
+
found = caseStopped({
|
|
178
|
+
...caseCuts,
|
|
179
|
+
cuts: cuts.flatMap((index) => caseCuts.cuts[index] ?? [])
|
|
180
|
+
}, options);
|
|
181
|
+
memo.set(key, found);
|
|
182
|
+
}
|
|
183
|
+
return found;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** This function gives the parts whose cut can stop a supply: the supply, and each part that it needs through the stack. */
|
|
187
|
+
function supplyReach(supply, options) {
|
|
188
|
+
const reach = options.stack === void 0 ? /* @__PURE__ */ new Set() : neededParts(options.stack, supply);
|
|
189
|
+
reach.add(supply);
|
|
190
|
+
return reach;
|
|
191
|
+
}
|
|
192
|
+
function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
|
|
193
|
+
const reach = supplyReach(draw.supply, options);
|
|
194
|
+
const relevant = caseCuts.cuts.flatMap((cut, index) => reach.has(cut.part) ? [index] : []);
|
|
195
|
+
const stops = (cuts) => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);
|
|
196
|
+
if (stops([])) return void 0;
|
|
197
|
+
if (!stops(relevant.map((_, index) => index))) return void 0;
|
|
198
|
+
const curves = relevant.map((index) => caseCuts.cuts[index]?.duration ?? []);
|
|
199
|
+
const sets = minimalStops(curves.length, stops);
|
|
200
|
+
return {
|
|
201
|
+
event: eventStop(curves, stops),
|
|
202
|
+
upper: upperStop(curves, sets),
|
|
203
|
+
coarse: sets === void 0
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.
|
|
208
|
+
*
|
|
209
|
+
* - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.
|
|
210
|
+
* - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.
|
|
211
|
+
* - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.
|
|
212
|
+
* - `event` is `eventStop`. `upper` is `upperStop` over the minimal sets of the cuts that count.
|
|
213
|
+
* - Past `MINIMAL_STOP_CUTS` cuts that count, `upper` is the sum of their curves, and `coarse` is true.
|
|
214
|
+
*/
|
|
215
|
+
function stopCurves(caseCuts, draw, options = {}) {
|
|
216
|
+
return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));
|
|
217
|
+
}
|
|
218
|
+
function zeroLevels(layer) {
|
|
219
|
+
return Object.fromEntries(layer.levels.map((level) => [level, 0]));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.
|
|
223
|
+
* `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.
|
|
224
|
+
*
|
|
225
|
+
* @param layer - The endurance layer
|
|
226
|
+
* @param caseCuts - The case
|
|
227
|
+
* @param endurance - The endurance of the case, from `enduranceOf`
|
|
228
|
+
* @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon
|
|
229
|
+
* @throws RangeError when the horizon is not a number more than 0
|
|
230
|
+
*/
|
|
231
|
+
function caseShortfall(layer, caseCuts, endurance, options = {}) {
|
|
232
|
+
const horizon = horizonOf(options);
|
|
233
|
+
const levels = zeroLevels(layer);
|
|
234
|
+
const upper = zeroLevels(layer);
|
|
235
|
+
const unread = [];
|
|
236
|
+
const coarse = [];
|
|
237
|
+
const stoppedOf = stoppedMemo(caseCuts, options);
|
|
238
|
+
for (const draw of caseDraws(layer, caseCuts, caseStopped(caseCuts, options))) {
|
|
239
|
+
const held = endurance.needs[draw.need];
|
|
240
|
+
const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);
|
|
241
|
+
if (held === void 0 || curves === void 0) {
|
|
242
|
+
unread.push(draw.need);
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
if (curves.coarse) coarse.push(draw.need);
|
|
246
|
+
const users = draw.users ?? 1;
|
|
247
|
+
levels[draw.level] = (levels[draw.level] ?? 0) + tailDays(curves.event, held.days, horizon) * users;
|
|
248
|
+
upper[draw.level] = (upper[draw.level] ?? 0) + tailDays(curves.upper, held.days, horizon) * users;
|
|
249
|
+
}
|
|
250
|
+
return {
|
|
251
|
+
levels,
|
|
252
|
+
upper,
|
|
253
|
+
unread,
|
|
254
|
+
coarse
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* This function gives the shortfall of one year at one place.
|
|
259
|
+
* It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.
|
|
260
|
+
*
|
|
261
|
+
* - 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.
|
|
262
|
+
* - A case with no prior at the place is not in the sum.
|
|
263
|
+
* - `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.
|
|
264
|
+
*
|
|
265
|
+
* @param layer - The endurance layer, with its cases and priors
|
|
266
|
+
* @param place - The place of the priors
|
|
267
|
+
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
268
|
+
* @throws RangeError when the date is not `YYYY-MM-DD`, or when the horizon is not a number more than 0
|
|
269
|
+
*/
|
|
270
|
+
function yearShortfall(layer, place, options) {
|
|
271
|
+
horizonOf(options);
|
|
272
|
+
const levels = zeroLevels(layer);
|
|
273
|
+
const upper = zeroLevels(layer);
|
|
274
|
+
const unread = [];
|
|
275
|
+
const coarse = [];
|
|
276
|
+
const cases = [];
|
|
277
|
+
for (const caseCuts of layer.cases ?? []) {
|
|
278
|
+
const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);
|
|
279
|
+
if (prior === void 0) continue;
|
|
280
|
+
const rate = yearRate(prior);
|
|
281
|
+
const endurance = enduranceOf(layer, caseCuts, options);
|
|
282
|
+
const shortfall = caseShortfall(layer, caseCuts, endurance, options);
|
|
283
|
+
for (const [level, days] of Object.entries(shortfall.levels)) levels[level] = (levels[level] ?? 0) + rate * days;
|
|
284
|
+
for (const [level, days] of Object.entries(shortfall.upper)) upper[level] = (upper[level] ?? 0) + rate * days;
|
|
285
|
+
for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);
|
|
286
|
+
for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);
|
|
287
|
+
cases.push({
|
|
288
|
+
case: caseCuts.case,
|
|
289
|
+
rate,
|
|
290
|
+
endurance,
|
|
291
|
+
shortfall
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
place,
|
|
296
|
+
levels,
|
|
297
|
+
upper,
|
|
298
|
+
unread,
|
|
299
|
+
coarse,
|
|
300
|
+
cases
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
// src/sample.ts
|
|
304
|
+
/** The base stack of the sample: the supplies of the building and a camp stove. */
|
|
305
|
+
const SAMPLE_ENDURANCE_STACK = {
|
|
306
|
+
schema: STACK_SCHEMA,
|
|
307
|
+
parts: [
|
|
308
|
+
{
|
|
309
|
+
id: "grid",
|
|
310
|
+
kind: "power",
|
|
311
|
+
name: "The power grid"
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
id: "water-main",
|
|
315
|
+
kind: "water",
|
|
316
|
+
name: "The water main"
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
id: "road",
|
|
320
|
+
kind: "road",
|
|
321
|
+
name: "The local road to the shops"
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
id: "stove",
|
|
325
|
+
kind: "device",
|
|
326
|
+
name: "The camp stove"
|
|
327
|
+
}
|
|
328
|
+
]
|
|
329
|
+
};
|
|
330
|
+
/**
|
|
331
|
+
* The endurance layer of the sample.
|
|
332
|
+
*
|
|
333
|
+
* - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.
|
|
334
|
+
* - 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.
|
|
335
|
+
* - The power holds 1000 Wh / 150 Wh a day = 6.667 days.
|
|
336
|
+
* - The filled bottles are past their due date, so they give nothing.
|
|
337
|
+
*/
|
|
338
|
+
const SAMPLE_ENDURANCE = {
|
|
339
|
+
schema: ENDURANCE_SCHEMA,
|
|
340
|
+
levels: [
|
|
341
|
+
"life",
|
|
342
|
+
"health",
|
|
343
|
+
"comfort"
|
|
344
|
+
],
|
|
345
|
+
resources: [
|
|
346
|
+
{
|
|
347
|
+
code: "water.stored",
|
|
348
|
+
unit: "L"
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
code: "food.ready",
|
|
352
|
+
unit: "kcal"
|
|
353
|
+
},
|
|
354
|
+
{
|
|
355
|
+
code: "food.grain-dry",
|
|
356
|
+
unit: "kg"
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
code: "fuel.propane",
|
|
360
|
+
unit: "kg"
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
code: "energy.battery",
|
|
364
|
+
unit: "Wh"
|
|
365
|
+
}
|
|
366
|
+
],
|
|
367
|
+
stores: [
|
|
368
|
+
{
|
|
369
|
+
id: "jugs",
|
|
370
|
+
resource: "water.stored",
|
|
371
|
+
amount: 75.7,
|
|
372
|
+
due: "2028-06-01"
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
id: "bottles",
|
|
376
|
+
resource: "water.stored",
|
|
377
|
+
amount: 20,
|
|
378
|
+
due: "2026-09-30"
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
id: "cans",
|
|
382
|
+
resource: "food.ready",
|
|
383
|
+
amount: 4800,
|
|
384
|
+
due: "2028-10-01"
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
id: "rice",
|
|
388
|
+
resource: "food.grain-dry",
|
|
389
|
+
amount: 9,
|
|
390
|
+
due: "2036-09-28"
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
id: "propane",
|
|
394
|
+
resource: "fuel.propane",
|
|
395
|
+
amount: .908,
|
|
396
|
+
due: "2036-10-01"
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
id: "battery",
|
|
400
|
+
resource: "energy.battery",
|
|
401
|
+
amount: 1e3,
|
|
402
|
+
due: "2031-10-01"
|
|
403
|
+
}
|
|
404
|
+
],
|
|
405
|
+
draws: [
|
|
406
|
+
{
|
|
407
|
+
need: "hydration.drink",
|
|
408
|
+
level: "life",
|
|
409
|
+
perDay: 11.355,
|
|
410
|
+
users: 3,
|
|
411
|
+
supply: "water-main"
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
need: "food.energy",
|
|
415
|
+
level: "health",
|
|
416
|
+
perDay: 5400,
|
|
417
|
+
users: 3,
|
|
418
|
+
supply: "road"
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
need: "power.electric",
|
|
422
|
+
level: "comfort",
|
|
423
|
+
perDay: 150,
|
|
424
|
+
users: 3,
|
|
425
|
+
supply: "grid"
|
|
426
|
+
}
|
|
427
|
+
],
|
|
428
|
+
direct: [
|
|
429
|
+
{
|
|
430
|
+
resource: "water.stored",
|
|
431
|
+
need: "hydration.drink",
|
|
432
|
+
amount: 1
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
resource: "food.ready",
|
|
436
|
+
need: "food.energy",
|
|
437
|
+
amount: 1
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
resource: "energy.battery",
|
|
441
|
+
need: "power.electric",
|
|
442
|
+
amount: 1
|
|
443
|
+
}
|
|
444
|
+
],
|
|
445
|
+
converters: [{
|
|
446
|
+
id: "cook-rice",
|
|
447
|
+
device: "stove",
|
|
448
|
+
takes: [
|
|
449
|
+
{
|
|
450
|
+
resource: "food.grain-dry",
|
|
451
|
+
amount: 1
|
|
452
|
+
},
|
|
453
|
+
{
|
|
454
|
+
resource: "water.stored",
|
|
455
|
+
amount: 2
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
resource: "fuel.propane",
|
|
459
|
+
amount: .05
|
|
460
|
+
}
|
|
461
|
+
],
|
|
462
|
+
gives: {
|
|
463
|
+
need: "food.energy",
|
|
464
|
+
amount: 3600
|
|
465
|
+
}
|
|
466
|
+
}],
|
|
467
|
+
cases: [{
|
|
468
|
+
case: "storm",
|
|
469
|
+
title: "Winter storm",
|
|
470
|
+
cuts: [
|
|
471
|
+
{
|
|
472
|
+
part: "grid",
|
|
473
|
+
title: "Power outage",
|
|
474
|
+
duration: [
|
|
475
|
+
[0, 1],
|
|
476
|
+
[.5, .5],
|
|
477
|
+
[1, .36],
|
|
478
|
+
[7, .013],
|
|
479
|
+
[30, 0]
|
|
480
|
+
],
|
|
481
|
+
source: "nrel-83092"
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
part: "road",
|
|
485
|
+
title: "Closed local road",
|
|
486
|
+
duration: [
|
|
487
|
+
[0, 1],
|
|
488
|
+
[1, .6],
|
|
489
|
+
[3, .2],
|
|
490
|
+
[10, 0]
|
|
491
|
+
],
|
|
492
|
+
source: "sample"
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
part: "water-main",
|
|
496
|
+
title: "No water from the main",
|
|
497
|
+
duration: [
|
|
498
|
+
[0, 1],
|
|
499
|
+
[2, .3],
|
|
500
|
+
[7, 0]
|
|
501
|
+
],
|
|
502
|
+
source: "sample"
|
|
503
|
+
}
|
|
504
|
+
],
|
|
505
|
+
leadSeconds: 86400
|
|
506
|
+
}, {
|
|
507
|
+
case: "fire",
|
|
508
|
+
title: "Fire",
|
|
509
|
+
cuts: []
|
|
510
|
+
}],
|
|
511
|
+
priors: [{
|
|
512
|
+
case: "storm",
|
|
513
|
+
place: "home",
|
|
514
|
+
perYear: .8,
|
|
515
|
+
reach: 1,
|
|
516
|
+
source: "sample",
|
|
517
|
+
asOf: "2025-12-01"
|
|
518
|
+
}, {
|
|
519
|
+
case: "fire",
|
|
520
|
+
place: "home",
|
|
521
|
+
perYear: .003,
|
|
522
|
+
reach: 1,
|
|
523
|
+
source: "sample",
|
|
524
|
+
asOf: "2025-12-01"
|
|
525
|
+
}]
|
|
526
|
+
};
|
|
527
|
+
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, caseDraws, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, eventStop, giftNeed, giftResource, hasEnduranceError, joinEndurance, longestStop, minimalStops, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
528
|
+
|
|
529
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/shortfall.ts","../src/sample.ts"],"sourcesContent":["import { neededParts } from \"@mark1russell7/system-stack\";\nimport { caseDraws, caseStopped, enduranceOf, type CaseOptions } from \"./endurance.ts\";\nimport type { CaseCuts, Draw, Endurance, EnduranceLayer, Prior, Survival } from \"./layer.ts\";\n\n// The shortfall: the user-days in which a draw does not get its need, for one case and for one year.\n\n/** 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. */\nexport function survivalAt(curve: Survival, days: number): number {\n if (days <= 0) return curve[0]?.[1] ?? 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (days <= t1) return p0 + ((p1 - p0) * (days - t0)) / (t1 - t0);\n }\n return 0;\n}\n\n/**\n * This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.\n * It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.\n * With no horizon, the area goes to the end of the curve.\n */\nexport function tailDays(curve: Survival, from: number, to: number = Infinity): number {\n let area = 0;\n for (let index = 1; index < curve.length; index += 1) {\n const [t0] = curve[index - 1] ?? [0, 1];\n const [t1] = curve[index] ?? [0, 0];\n const start = Math.max(t0, from);\n const end = Math.min(t1, to);\n if (start < end) area += ((survivalAt(curve, start) + survivalAt(curve, end)) / 2) * (end - start);\n }\n return area;\n}\n\n/**\n * The options of a shortfall: the stack or the parts that are also down, as for `enduranceOf`, and a horizon.\n * With a horizon of `h` days, the shortfall counts only the first `h` days of each cut. A draw that holds `h` days has no shortfall.\n * Thus a plan can aim at a target, for example 14 days and then 90 days.\n */\nexport interface ShortfallOptions extends Pick<CaseOptions, \"stack\" | \"down\"> {\n /** The horizon in days, more than 0. The default is no horizon. */\n readonly horizon?: number | undefined;\n}\n\nfunction horizonOf(options: ShortfallOptions): number {\n const horizon = options.horizon ?? Infinity;\n if (!(horizon > 0)) throw new RangeError(`The horizon ${String(options.horizon)} is not a number of days more than 0.`);\n return horizon;\n}\n\n/**\n * 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.\n * When the curve does not fall to `chance`, the result is `Infinity`.\n */\nexport function survivalQuantile(curve: Survival, chance: number): number {\n for (let index = 1; index < curve.length; index += 1) {\n const [t0, p0] = curve[index - 1] ?? [0, 1];\n const [t1, p1] = curve[index] ?? [0, 0];\n if (p0 <= chance) return t0;\n if (p1 <= chance) return t0 + ((p0 - chance) * (t1 - t0)) / (p0 - p1);\n }\n return Infinity;\n}\n\n/** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */\nexport function yearChance(prior: Prior): number {\n return 1 - Math.exp(-prior.perYear * prior.reach);\n}\n\n/** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */\nexport function yearRate(prior: Prior): number {\n return prior.perYear * prior.reach;\n}\n\n/** 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. */\nfunction bendTimes(curves: readonly Survival[]): number[] {\n const times = [...new Set(curves.flatMap((curve) => curve.map(([days]) => days)))].sort((x, y) => x - y);\n const out = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n for (const [i, a] of curves.entries()) {\n for (const b of curves.slice(i + 1)) {\n const d0 = survivalAt(a, t0) - survivalAt(b, t0);\n const d1 = survivalAt(a, t1) - survivalAt(b, t1);\n if (d0 * d1 < 0) out.add(t0 + ((t1 - t0) * d0) / (d0 - d1));\n }\n }\n }\n return [...out].sort((x, y) => x - y);\n}\n\n/**\n * 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.\n *\n * @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\n */\nfunction curveFrom(times: readonly number[], chanceAt: (days: number) => number): Survival {\n const out: [number, number][] = [];\n for (const days of times) {\n const chance = Math.min(out[out.length - 1]?.[1] ?? 1, chanceAt(days));\n out.push([days, chance]);\n if (chance === 0) return out;\n }\n throw new RangeError(\"The curves do not fall to a chance of 0 at their last point.\");\n}\n\n/**\n * This function gives the curve of a stop of some cuts when one event makes each cut longer together.\n * At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.\n *\n * - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).\n * - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.\n * - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.\n * - 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.\n *\n * 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.\n *\n * @param curves - The curves of the cuts, each one good for `checkEndurance`\n * @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.\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function eventStop(curves: readonly Survival[], stops: (cuts: readonly number[]) => boolean): Survival {\n return curveFrom(bendTimes(curves), (days) => {\n const chances = curves.map((curve) => survivalAt(curve, days));\n for (const level of [...new Set(chances)].sort((x, y) => y - x)) {\n if (stops(chances.flatMap((chance, index) => (chance >= level ? [index] : [])))) return level;\n }\n return 0;\n });\n}\n\n/**\n * This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.\n * It is `eventStop` when any one cut stops the supply.\n *\n * @param curves - The curves, each one good for `checkEndurance`\n * @throws RangeError when there is no curve, or when a curve does not end at a chance of 0\n */\nexport function longestStop(curves: readonly Survival[]): Survival {\n const first = curves[0];\n if (first === undefined) throw new RangeError(\"longestStop needs one or more curves.\");\n return curves.length === 1 ? first : eventStop(curves, (cuts) => cuts.length > 0);\n}\n\n/**\n * The largest count of cuts for which `minimalStops` examines each set.\n * `stopCurves` counts only the cuts that can reach the supply. Past this count, its `upper` is coarse.\n */\nexport const MINIMAL_STOP_CUTS = 12;\n\n/**\n * 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.\n * With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.\n */\nexport function minimalStops(count: number, stops: (cuts: readonly number[]) => boolean): number[][] | undefined {\n if (count > MINIMAL_STOP_CUTS) return undefined;\n const found: number[][] = [];\n const masks: number[] = [];\n const all = Array.from({ length: 1 << count }, (_, mask) => mask).sort((x, y) => popCount(x) - popCount(y) || x - y);\n for (const mask of all) {\n if (mask === 0 || masks.some((other) => (other & mask) === other)) continue;\n const cuts = Array.from({ length: count }, (_, index) => index).filter((index) => (mask >> index) & 1);\n if (!stops(cuts)) continue;\n masks.push(mask);\n found.push(cuts);\n }\n return found;\n}\n\nfunction popCount(mask: number): number {\n let total = 0;\n for (let rest = mask; rest > 0; rest &= rest - 1) total += 1;\n return total;\n}\n\n/**\n * This function gives an upper limit of the curve of a stop for each dependence of the cuts.\n * At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.\n * With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.\n *\n * @param curves - The curves of the cuts\n * @param sets - The minimal sets of `minimalStops`, or `undefined`\n * @throws RangeError when a curve does not end at a chance of 0\n */\nexport function upperStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival {\n const groups = sets ?? curves.map((_, index) => [index]);\n const sum = (days: number): number => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);\n // The sum is linear between two times of bendTimes. A point where it falls through 1 is a bend of min(1, sum).\n const times = bendTimes(curves);\n const bends = new Set(times);\n for (let index = 1; index < times.length; index += 1) {\n const t0 = times[index - 1] ?? 0;\n const t1 = times[index] ?? 0;\n const s0 = sum(t0) - 1;\n const s1 = sum(t1) - 1;\n if (s0 * s1 < 0) bends.add(t0 + ((t1 - t0) * s0) / (s0 - s1));\n }\n return curveFrom([...bends].sort((x, y) => x - y), (days) => Math.min(1, sum(days)));\n}\n\n/** The curves of the stop of a draw: when one event makes each cut longer together, and an upper limit for each dependence. */\nexport interface StopCurves {\n readonly event: Survival;\n readonly upper: Survival;\n /** This is true when `upper` is the sum of the curves of the cuts that can reach the supply, because there are more than `MINIMAL_STOP_CUTS`. */\n readonly coarse: boolean;\n}\n\n/** This function gives the parts of the stack that are down for a list of cut indexes. A case uses one memo for each of its draws. */\ntype StoppedOf = (cuts: readonly number[]) => ReadonlySet<string>;\n\nfunction stoppedMemo(caseCuts: CaseCuts, options: Pick<CaseOptions, \"stack\" | \"down\">): StoppedOf {\n const memo = new Map<string, ReadonlySet<string>>();\n return (cuts) => {\n const key = cuts.join(\",\");\n let found = memo.get(key);\n if (found === undefined) {\n found = caseStopped({ ...caseCuts, cuts: cuts.flatMap((index) => caseCuts.cuts[index] ?? []) }, options);\n memo.set(key, found);\n }\n return found;\n };\n}\n\n/** This function gives the parts whose cut can stop a supply: the supply, and each part that it needs through the stack. */\nfunction supplyReach(supply: string, options: Pick<CaseOptions, \"stack\">): Set<string> {\n const reach = options.stack === undefined ? new Set<string>() : neededParts(options.stack, supply);\n reach.add(supply);\n return reach;\n}\n\nfunction stopCurvesWith(caseCuts: CaseCuts, draw: Draw, options: Pick<CaseOptions, \"stack\" | \"down\">, stoppedOf: StoppedOf): StopCurves | undefined {\n const reach = supplyReach(draw.supply, options);\n const relevant = caseCuts.cuts.flatMap((cut, index) => (reach.has(cut.part) ? [index] : []));\n const stops = (cuts: readonly number[]): boolean => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);\n if (stops([])) return undefined;\n if (!stops(relevant.map((_, index) => index))) return undefined;\n const curves = relevant.map((index) => caseCuts.cuts[index]?.duration ?? []);\n const sets = minimalStops(curves.length, stops);\n return { event: eventStop(curves, stops), upper: upperStop(curves, sets), coarse: sets === undefined };\n}\n\n/**\n * This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.\n *\n * - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.\n * - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.\n * - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.\n * - `event` is `eventStop`. `upper` is `upperStop` over the minimal sets of the cuts that count.\n * - Past `MINIMAL_STOP_CUTS` cuts that count, `upper` is the sum of their curves, and `coarse` is true.\n */\nexport function stopCurves(caseCuts: CaseCuts, draw: Draw, options: Pick<CaseOptions, \"stack\" | \"down\"> = {}): StopCurves | undefined {\n return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));\n}\n\n/** The shortfall of each level, in user-days, and the draws that the query cannot read. */\nexport interface Shortfall {\n /**\n * The user-days of each level of the layer, when one event makes each cut longer together. The query does not add two levels.\n * This value is not a limit. The true value can be more or less. `upper` is the limit.\n */\n readonly levels: Readonly<Record<string, number>>;\n /** The upper limit of the user-days of each level, for each dependence of the cuts. A gate of a high level can use it. */\n readonly upper: Readonly<Record<string, number>>;\n /**\n * The needs of the draws whose stop has no curve (`stopCurves`).\n * The query has no curve of their duration, so their shortfall is not in `levels`. A gate shows them as no read.\n */\n readonly unread: readonly string[];\n /** The needs of the draws whose `upper` is coarse (`StopCurves.coarse`). A gate on `upper` shows them. */\n readonly coarse: readonly string[];\n}\n\nfunction zeroLevels(layer: EnduranceLayer): Record<string, number> {\n return Object.fromEntries(layer.levels.map((level) => [level, 0]));\n}\n\n/**\n * This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.\n * `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.\n *\n * @param layer - The endurance layer\n * @param caseCuts - The case\n * @param endurance - The endurance of the case, from `enduranceOf`\n * @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon\n * @throws RangeError when the horizon is not a number more than 0\n */\nexport function caseShortfall(layer: EnduranceLayer, caseCuts: CaseCuts, endurance: Endurance, options: ShortfallOptions = {}): Shortfall {\n const horizon = horizonOf(options);\n const levels = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const stoppedOf = stoppedMemo(caseCuts, options);\n for (const draw of caseDraws(layer, caseCuts, caseStopped(caseCuts, options))) {\n const held = endurance.needs[draw.need];\n const curves = stopCurvesWith(caseCuts, draw, options, stoppedOf);\n if (held === undefined || curves === undefined) {\n unread.push(draw.need);\n continue;\n }\n if (curves.coarse) coarse.push(draw.need);\n const users = draw.users ?? 1;\n levels[draw.level] = (levels[draw.level] ?? 0) + tailDays(curves.event, held.days, horizon) * users;\n upper[draw.level] = (upper[draw.level] ?? 0) + tailDays(curves.upper, held.days, horizon) * users;\n }\n return { levels, upper, unread, coarse };\n}\n\n/** The shortfall of one year at one place, with the part of each case. */\nexport interface YearShortfall extends Shortfall {\n readonly place: string;\n /** The part of each case. `rate` is the expected count of its events in one year. */\n readonly cases: readonly { readonly case: string; readonly rate: number; readonly endurance: Endurance; readonly shortfall: Shortfall }[];\n}\n\n/**\n * This function gives the shortfall of one year at one place.\n * It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.\n *\n * - 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.\n * - A case with no prior at the place is not in the sum.\n * - `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.\n *\n * @param layer - The endurance layer, with its cases and priors\n * @param place - The place of the priors\n * @param options - The date, the stack or the parts that are also down, and the horizon\n * @throws RangeError when the date is not `YYYY-MM-DD`, or when the horizon is not a number more than 0\n */\nexport function yearShortfall(layer: EnduranceLayer, place: string, options: CaseOptions & ShortfallOptions): YearShortfall {\n horizonOf(options);\n const levels = zeroLevels(layer);\n const upper = zeroLevels(layer);\n const unread: string[] = [];\n const coarse: string[] = [];\n const cases: YearShortfall[\"cases\"][number][] = [];\n for (const caseCuts of layer.cases ?? []) {\n const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);\n if (prior === undefined) continue;\n const rate = yearRate(prior);\n const endurance = enduranceOf(layer, caseCuts, options);\n const shortfall = caseShortfall(layer, caseCuts, endurance, options);\n for (const [level, days] of Object.entries(shortfall.levels)) levels[level] = (levels[level] ?? 0) + rate * days;\n for (const [level, days] of Object.entries(shortfall.upper)) upper[level] = (upper[level] ?? 0) + rate * days;\n for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);\n for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);\n cases.push({ case: caseCuts.case, rate, endurance, shortfall });\n }\n return { place, levels, upper, unread, coarse, cases };\n}\n","import { STACK_SCHEMA, type Stack } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// A sample: a building with 3 users, and a storm that cuts the grid, the road and the water main.\n// Each name and each value is an example, except the grid curve (NREL, technical report 83092). The tests, the README files and the site use it.\n\n/** The base stack of the sample: the supplies of the building and a camp stove. */\nexport const SAMPLE_ENDURANCE_STACK: Stack = {\n schema: STACK_SCHEMA,\n parts: [\n { id: \"grid\", kind: \"power\", name: \"The power grid\" },\n { id: \"water-main\", kind: \"water\", name: \"The water main\" },\n { id: \"road\", kind: \"road\", name: \"The local road to the shops\" },\n { id: \"stove\", kind: \"device\", name: \"The camp stove\" },\n ],\n};\n\n/**\n * The endurance layer of the sample.\n *\n * - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.\n * - 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.\n * - The power holds 1000 Wh / 150 Wh a day = 6.667 days.\n * - The filled bottles are past their due date, so they give nothing.\n */\nexport const SAMPLE_ENDURANCE: EnduranceLayer = {\n schema: ENDURANCE_SCHEMA,\n levels: [\"life\", \"health\", \"comfort\"],\n resources: [\n { code: \"water.stored\", unit: \"L\" },\n { code: \"food.ready\", unit: \"kcal\" },\n { code: \"food.grain-dry\", unit: \"kg\" },\n { code: \"fuel.propane\", unit: \"kg\" },\n { code: \"energy.battery\", unit: \"Wh\" },\n ],\n stores: [\n { id: \"jugs\", resource: \"water.stored\", amount: 75.7, due: \"2028-06-01\" },\n { id: \"bottles\", resource: \"water.stored\", amount: 20, due: \"2026-09-30\" },\n { id: \"cans\", resource: \"food.ready\", amount: 4800, due: \"2028-10-01\" },\n { id: \"rice\", resource: \"food.grain-dry\", amount: 9, due: \"2036-09-28\" },\n { id: \"propane\", resource: \"fuel.propane\", amount: 0.908, due: \"2036-10-01\" },\n { id: \"battery\", resource: \"energy.battery\", amount: 1000, due: \"2031-10-01\" },\n ],\n draws: [\n { need: \"hydration.drink\", level: \"life\", perDay: 11.355, users: 3, supply: \"water-main\" },\n { need: \"food.energy\", level: \"health\", perDay: 5400, users: 3, supply: \"road\" },\n { need: \"power.electric\", level: \"comfort\", perDay: 150, users: 3, supply: \"grid\" },\n ],\n direct: [\n { resource: \"water.stored\", need: \"hydration.drink\", amount: 1 },\n { resource: \"food.ready\", need: \"food.energy\", amount: 1 },\n { resource: \"energy.battery\", need: \"power.electric\", amount: 1 },\n ],\n converters: [\n {\n id: \"cook-rice\",\n device: \"stove\",\n takes: [\n { resource: \"food.grain-dry\", amount: 1 },\n { resource: \"water.stored\", amount: 2 },\n { resource: \"fuel.propane\", amount: 0.05 },\n ],\n gives: { need: \"food.energy\", amount: 3600 },\n },\n ],\n cases: [\n {\n case: \"storm\",\n title: \"Winter storm\",\n cuts: [\n { part: \"grid\", title: \"Power outage\", duration: [[0, 1], [0.5, 0.5], [1, 0.36], [7, 0.013], [30, 0]], source: \"nrel-83092\" },\n { part: \"road\", title: \"Closed local road\", duration: [[0, 1], [1, 0.6], [3, 0.2], [10, 0]], source: \"sample\" },\n { part: \"water-main\", title: \"No water from the main\", duration: [[0, 1], [2, 0.3], [7, 0]], source: \"sample\" },\n ],\n leadSeconds: 86_400,\n },\n { case: \"fire\", title: \"Fire\", cuts: [] },\n ],\n priors: [\n { case: \"storm\", place: \"home\", perYear: 0.8, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n { case: \"fire\", place: \"home\", perYear: 0.003, reach: 1, source: \"sample\", asOf: \"2025-12-01\" },\n ],\n};\n"],"mappings":";;;;;AAOA,SAAgB,WAAW,OAAiB,MAAsB;CAChE,IAAI,QAAQ,GAAG,OAAO,MAAM,EAAE,GAAG,MAAM;CACvC,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS,GAAG;EACpD,MA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