@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/LICENSE +21 -0
- package/README.md +89 -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 +286 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +604 -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/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Russell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mark1russell7/stack-endurance
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The stores, the draws and the converters of a system stack. The package tells how many days each draw holds when a case cuts its supply. It also tells the shortfall of each level in one year.
|
|
4
|
+
|
|
5
|
+
It is the endurance add-on of [`@mark1russell7/system-stack`](../system-stack/README.md). The core knows only parts and needs. This package tells what a part takes each day, and what the stores give when its supply stops.
|
|
6
|
+
|
|
7
|
+
The package names no topic. One query gives the battery days of a rack and the days of water of a building. The resources, the needs and the levels are data.
|
|
8
|
+
|
|
9
|
+
Each function is a plain function with no clock, no network and no file. The unit of time is the day.
|
|
10
|
+
|
|
11
|
+
## The records
|
|
12
|
+
|
|
13
|
+
| Record | What it tells |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `Resource` | A resource of a store and its unit, for example `water.stored` in `L`. |
|
|
16
|
+
| `Store` | An amount of one resource, with an optional due date and an optional part that holds it. |
|
|
17
|
+
| `Draw` | A need that a load takes each day, its level, its count of users and the part that supplies it. |
|
|
18
|
+
| `DirectUse` | One unit of a resource gives an amount of a need. |
|
|
19
|
+
| `Converter` | A run takes some resources and gives an amount of a need or of a resource. Examples are a stove that cooks dry rice with water and fuel, and a generator that charges a battery from fuel. |
|
|
20
|
+
| `CaseCuts` | A case: the parts that it cuts, the survival curve of the duration of each cut, and factors on the rates. |
|
|
21
|
+
| `Prior` | The events of a case in one year at one place, and the share that reach the place. |
|
|
22
|
+
|
|
23
|
+
## The rule of endurance
|
|
24
|
+
|
|
25
|
+
- A draw takes from the stores only when the case stops its supply part.
|
|
26
|
+
- The draws take the resources in the order of their level, then of the codes of their needs.
|
|
27
|
+
- A draw takes from its direct uses first, then from its converters.
|
|
28
|
+
- A take of a resource uses its stock first, then the converters that make it, through each chain. Thus a direct use of the battery can use the fuel of the generator.
|
|
29
|
+
- The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.
|
|
30
|
+
- Each higher draw keeps back its own days times its demand. Thus the takes of all the draws are not more than the stores at any time.
|
|
31
|
+
- The take order is a rule, not the best share. The days are the days of this order. `takes` gives the amount of each resource that a draw takes.
|
|
32
|
+
- A store gives nothing on its due date and after it. A store or a converter whose part stops gives nothing.
|
|
33
|
+
|
|
34
|
+
With a base stack, a cut also stops each part that cannot work without the cut part. Thus a pump that needs the grid stops with the grid.
|
|
35
|
+
|
|
36
|
+
## The rule of shortfall
|
|
37
|
+
|
|
38
|
+
- For one draw in one case, the shortfall is `E[max(0, D - T)] * users`. `T` is the endurance of the draw. `D` is the duration of the stop of its supply.
|
|
39
|
+
- A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack. A need of `any` parts stops only when enough of them are cut.
|
|
40
|
+
- `E[max(0, D - T)]` is the area under the survival curve from `T` on. The curve is linear between its points, so the area is exact.
|
|
41
|
+
- For one year, the shortfall is the sum over the cases of `perYear * reach` times the shortfall of the case. Thus it is the expected user-days of one year.
|
|
42
|
+
- The query adds the draws of one level. It does not add two levels.
|
|
43
|
+
|
|
44
|
+
With the option `horizon` of `h` days, the shortfall counts only the first `h` days of each cut: `E[max(0, min(D, h) - T)] * users`. A draw that holds `h` days has no shortfall. Thus a buy plan can aim at a target, for example 14 days and then 90 days.
|
|
45
|
+
|
|
46
|
+
A draw that only the parts of `down` stop has no curve of its duration. The query puts it in `unread`, and its shortfall is not in the sum. A gate shows it as no read, not as a pass.
|
|
47
|
+
|
|
48
|
+
The cuts of one case come from one event. `levels` takes each cut longer together with the event (`eventStop`). Then a stop with two cuts lasts as long as the longer cut. A stop through a need of `any` of two parts ends with the shorter cut. `levels` is not a limit: when the cuts are independent, the true stop can be longer or shorter.
|
|
49
|
+
|
|
50
|
+
`upper` is an upper limit for each dependence of the cuts (`upperStop`). At each time, its chance is the sum over the minimal sets of cuts of the smallest chance of the set, to 1 or less. A gate of a high level can use `upper`.
|
|
51
|
+
|
|
52
|
+
`independent` is the shortfall when the cuts are independent (`independentStop`). At each time, the supply is stopped when the cuts that are still on contain a minimal set. The query adds the chance of each such state of the cuts. A stop of two cuts in series is then `1 - (1 - s1)(1 - s2)`, and a stop through a need of `any` of two parts is `s1 * s2`. `independent` is not more than `upper`. Between two bend times the chance is not linear, so the curve has more points, each within `1e-6` of the chance.
|
|
53
|
+
|
|
54
|
+
Only the cuts of the supply, and of the parts that it needs through the stack, count. Past 12 such cuts, `upper` is the sum of their curves, `independent` is `upper`, and `coarse` names the need.
|
|
55
|
+
|
|
56
|
+
## The entries
|
|
57
|
+
|
|
58
|
+
| Entry | What it has |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `@mark1russell7/stack-endurance` | The records of a layer, the endurance and shortfall queries, the gate, the join and a sample. |
|
|
61
|
+
| `@mark1russell7/stack-endurance/schema` | `enduranceSchema`, the zod schema of a layer, with `parseEndurance`. |
|
|
62
|
+
| `@mark1russell7/stack-endurance/add-on` | `enduranceAddOn`, the add-on in the form of the layer contract of the core. |
|
|
63
|
+
|
|
64
|
+
The root entry has no schema library.
|
|
65
|
+
|
|
66
|
+
## Install
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
npm install @mark1russell7/stack-endurance @mark1russell7/system-stack
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## An example
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { enduranceOf, SAMPLE_ENDURANCE, yearShortfall } from "@mark1russell7/stack-endurance";
|
|
76
|
+
|
|
77
|
+
const storm = SAMPLE_ENDURANCE.cases?.find((item) => item.case === "storm");
|
|
78
|
+
if (storm !== undefined) {
|
|
79
|
+
const held = enduranceOf(SAMPLE_ENDURANCE, storm, { at: "2026-12-01" });
|
|
80
|
+
// held.needs["food.energy"] is { days: 0.889, binding: ["food.ready", "water.stored"] }.
|
|
81
|
+
}
|
|
82
|
+
const year = yearShortfall(SAMPLE_ENDURANCE, "home", { at: "2026-12-01" });
|
|
83
|
+
// year.levels is { life: 0.008, health: 3.766, comfort: 0.377 }, in user-days.
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
In the sample, the rice needs 2 L of water for each kg. The drinking water holds 6.667 days, and it keeps back all the water for these days. So the rice gives nothing, and the food holds 0.889 days on the cans.
|
|
87
|
+
|
|
88
|
+
## The gate
|
|
89
|
+
|
|
90
|
+
`checkEndurance(layer, stack)` gives the faults of a layer. `ENDURANCE_CODES` lists the codes. The gate finds two records with one key, and an unknown level, resource or part. It also finds a value out of range, a bad date, an empty converter and a bad survival curve. Converters that make a resource from itself are a cycle, and the gate refuses them. A draw with no way to get its need is a warning.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { l as EnduranceLayer } from "./layer-DzGZC5XH.js";
|
|
2
|
+
import { StackJoiner } from "@mark1russell7/system-stack";
|
|
3
|
+
/**
|
|
4
|
+
* This function gives the endurance add-on.
|
|
5
|
+
*
|
|
6
|
+
* - `schema` is `endurance/1`, the key of the layer in `Stack.layers`.
|
|
7
|
+
* - `parse` is `parseEndurance`.
|
|
8
|
+
* - `check` is the gate `checkEndurance`.
|
|
9
|
+
* - `join` is `joinEndurance`. It joins the endurance layers of the fragments of a stack.
|
|
10
|
+
*/
|
|
11
|
+
export declare function enduranceAddOn(): StackJoiner<EnduranceLayer>;
|
|
12
|
+
//# sourceMappingURL=add-on.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-on.d.ts","names":[],"sources":["../src/add-on.ts"],"mappings":";;;;;;;;;;wBAiBgB,kBAAkB,YAAY"}
|
package/build/add-on.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { r as checkEndurance, t as joinEndurance } from "./join-D7KyUpGf.js";
|
|
2
|
+
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
3
|
+
import { parseEndurance } from "./schema.js";
|
|
4
|
+
// src/add-on.ts
|
|
5
|
+
/**
|
|
6
|
+
* This function gives the endurance add-on.
|
|
7
|
+
*
|
|
8
|
+
* - `schema` is `endurance/1`, the key of the layer in `Stack.layers`.
|
|
9
|
+
* - `parse` is `parseEndurance`.
|
|
10
|
+
* - `check` is the gate `checkEndurance`.
|
|
11
|
+
* - `join` is `joinEndurance`. It joins the endurance layers of the fragments of a stack.
|
|
12
|
+
*/
|
|
13
|
+
function enduranceAddOn() {
|
|
14
|
+
return {
|
|
15
|
+
schema: ENDURANCE_SCHEMA,
|
|
16
|
+
parse: parseEndurance,
|
|
17
|
+
check: checkEndurance,
|
|
18
|
+
join: joinEndurance
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export { enduranceAddOn };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=add-on.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-on.js","names":[],"sources":["../src/add-on.ts"],"sourcesContent":["import type { StackJoiner } from \"@mark1russell7/system-stack\";\nimport { checkEndurance } from \"./check.ts\";\nimport { joinEndurance } from \"./join.ts\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\nimport { parseEndurance } from \"./schema.ts\";\n\n// The endurance add-on in the form of the layer contract. A host gives it to `checkStackLayers` and to `joinStacks` of the core.\n// This entry has the schema library, so the root entry does not import it.\n\n/**\n * This function gives the endurance add-on.\n *\n * - `schema` is `endurance/1`, the key of the layer in `Stack.layers`.\n * - `parse` is `parseEndurance`.\n * - `check` is the gate `checkEndurance`.\n * - `join` is `joinEndurance`. It joins the endurance layers of the fragments of a stack.\n */\nexport function enduranceAddOn(): StackJoiner<EnduranceLayer> {\n return { schema: ENDURANCE_SCHEMA, parse: parseEndurance, check: checkEndurance, join: joinEndurance };\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAgB,iBAA8C;CAC5D,OAAO;EAAE,QAAQ;EAAkB,OAAO;EAAgB,OAAO;EAAgB,MAAM;CAAc;AACvG"}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { a as Draw, c as Endurance, d as IsoDate, f as Prior, h as Survival, i as DirectUse, l as EnduranceLayer, m as Store, n as Converter, o as DrawEndurance, p as Resource, r as Cut, s as ENDURANCE_SCHEMA, t as CaseCuts, u as Gift } from "./layer-DzGZC5XH.js";
|
|
2
|
+
import { Fault, LayerParse, LayerPiece, Stack } from "@mark1russell7/system-stack";
|
|
3
|
+
/** The options of the queries of a case. */
|
|
4
|
+
export interface CaseOptions {
|
|
5
|
+
/** The date of the query. A store whose due date is on this date or before it gives nothing. */
|
|
6
|
+
readonly at: IsoDate;
|
|
7
|
+
/** The base stack. With it, a cut also stops each part that cannot work without a cut part (`stopped` of the core). */
|
|
8
|
+
readonly stack?: Stack | undefined;
|
|
9
|
+
/** The `id` of more parts that are down, with the cuts of the case. */
|
|
10
|
+
readonly down?: readonly string[] | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* This function gives the `id` of each part that does not work in a case: the cut parts and the parts of `down`.
|
|
14
|
+
* With a stack, it also gives each part that stops.
|
|
15
|
+
*/
|
|
16
|
+
export declare function caseStopped(caseCuts: CaseCuts, options: Pick<CaseOptions, "stack" | "down">): Set<string>;
|
|
17
|
+
/**
|
|
18
|
+
* This function gives the amount of each resource in the stores at a date, by the code of the resource.
|
|
19
|
+
*
|
|
20
|
+
* - A store gives nothing on its due date and after it.
|
|
21
|
+
* - A store gives nothing when its part is in `stoppedParts`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function storeAmounts(layer: EnduranceLayer, at: IsoDate, stoppedParts?: ReadonlySet<string>): Map<string, number>;
|
|
24
|
+
/** This function gives the amount of a need for each day in a case: the rate of the draw times the factor of the case. */
|
|
25
|
+
export declare function drawDemand(draw: Draw, caseCuts: CaseCuts): number;
|
|
26
|
+
/**
|
|
27
|
+
* This function gives the draws that take from the stores in a case: each draw whose supply stops, with a demand more than 0.
|
|
28
|
+
* The sequence is by the level (the order of `levels`), then by the code of the need.
|
|
29
|
+
*/
|
|
30
|
+
export declare function caseDraws(layer: EnduranceLayer, caseCuts: CaseCuts, stoppedParts: ReadonlySet<string>): Draw[];
|
|
31
|
+
/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */
|
|
32
|
+
export declare function giftNeed(converter: Converter): string | undefined;
|
|
33
|
+
/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */
|
|
34
|
+
export declare function giftResource(converter: Converter): string | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* This function gives the days that each draw holds when a case stops its supply, and the resources that are used up then.
|
|
37
|
+
*
|
|
38
|
+
* - A draw takes from the stores only when the case stops its supply part. Each other draw holds without end, and the result leaves it out.
|
|
39
|
+
* - The demand of a draw for each day is its rate times the factor of the case.
|
|
40
|
+
* - The draws take the resources in the order of their level, then of their codes. A draw takes from its direct uses first, then from its converters.
|
|
41
|
+
* - The days of a draw are the largest `T` at which the stores give `T` days of its demand, after each higher draw.
|
|
42
|
+
* - Each higher draw keeps back its own days times its demand. Thus the takes of all the draws are not more than the stores at any time.
|
|
43
|
+
* - The take order is a rule, not the best share: the direct uses in the order of the list, then the converters. The days are the days of this order.
|
|
44
|
+
* - A converter whose device stops gives nothing. A store whose part stops gives nothing.
|
|
45
|
+
* - A converter can give a resource. A take of a resource uses the stock first, then the converters that make it, through each chain.
|
|
46
|
+
*
|
|
47
|
+
* The function is pure, but for an internal count of the tries of its fits for the tests. It throws a `RangeError` for a date that is not `YYYY-MM-DD`. The gate `checkEndurance` examines the layer before.
|
|
48
|
+
*
|
|
49
|
+
* @param layer - The endurance layer
|
|
50
|
+
* @param caseCuts - The case
|
|
51
|
+
* @param options - The date, and the stack or the parts that are also down
|
|
52
|
+
* @returns The endurance of each draw whose supply stops
|
|
53
|
+
*/
|
|
54
|
+
export declare function enduranceOf(layer: EnduranceLayer, caseCuts: CaseCuts, options: CaseOptions): Endurance;
|
|
55
|
+
/** 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. */
|
|
56
|
+
export declare function survivalAt(curve: Survival, days: number): number;
|
|
57
|
+
/**
|
|
58
|
+
* This function gives the expected days of a cut after a time, up to a horizon: `E[max(0, min(D, to) - from)]`.
|
|
59
|
+
* It is the area under the curve from `from` to `to`. The curve is linear between its points, so the area is exact.
|
|
60
|
+
* With no horizon, the area goes to the end of the curve.
|
|
61
|
+
*/
|
|
62
|
+
export declare function tailDays(curve: Survival, from: number, to?: number): number;
|
|
63
|
+
/**
|
|
64
|
+
* The options of a shortfall: the stack or the parts that are also down, as for `enduranceOf`, and a horizon.
|
|
65
|
+
* 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.
|
|
66
|
+
* Thus a plan can aim at a target, for example 14 days and then 90 days.
|
|
67
|
+
*/
|
|
68
|
+
export interface ShortfallOptions extends Pick<CaseOptions, "stack" | "down"> {
|
|
69
|
+
/** The horizon in days, more than 0. The default is no horizon. */
|
|
70
|
+
readonly horizon?: number | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 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.
|
|
74
|
+
* When the curve does not fall to `chance`, the result is `Infinity`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function survivalQuantile(curve: Survival, chance: number): number;
|
|
77
|
+
/** This function gives the chance that a case reaches its place one or more times in one year: `1 - exp(-perYear * reach)`. */
|
|
78
|
+
export declare function yearChance(prior: Prior): number;
|
|
79
|
+
/** This function gives the expected count of the events of a case at its place in one year: `perYear * reach`. */
|
|
80
|
+
export declare function yearRate(prior: Prior): number;
|
|
81
|
+
/**
|
|
82
|
+
* This function gives the curve of a stop of some cuts when one event makes each cut longer together.
|
|
83
|
+
* At each time, the chance is the largest `s` at which the cuts with a chance of `s` or more stop the supply.
|
|
84
|
+
*
|
|
85
|
+
* - When any one cut stops the supply, the result is the largest chance of the curves (`longestStop`).
|
|
86
|
+
* - When the supply needs `any` of two parts, the stop ends with the shorter of the two cuts.
|
|
87
|
+
* - Between two times of `bendTimes` the order of the curves does not change. So the result is linear between its points.
|
|
88
|
+
* - 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.
|
|
89
|
+
*
|
|
90
|
+
* 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.
|
|
91
|
+
*
|
|
92
|
+
* @param curves - The curves of the cuts, each one good for `checkEndurance`
|
|
93
|
+
* @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.
|
|
94
|
+
* @throws RangeError when a curve does not end at a chance of 0
|
|
95
|
+
*/
|
|
96
|
+
export declare function eventStop(curves: readonly Survival[], stops: (cuts: readonly number[]) => boolean): Survival;
|
|
97
|
+
/**
|
|
98
|
+
* This function gives the curve of the longest of some stops: at each time, the largest chance of the curves.
|
|
99
|
+
* It is `eventStop` when any one cut stops the supply.
|
|
100
|
+
*
|
|
101
|
+
* @param curves - The curves, each one good for `checkEndurance`
|
|
102
|
+
* @throws RangeError when there is no curve, or when a curve does not end at a chance of 0
|
|
103
|
+
*/
|
|
104
|
+
export declare function longestStop(curves: readonly Survival[]): Survival;
|
|
105
|
+
/**
|
|
106
|
+
* The largest count of cuts for which `minimalStops` examines each set.
|
|
107
|
+
* `stopCurves` counts only the cuts that can reach the supply. Past this count, its `upper` is coarse.
|
|
108
|
+
*/
|
|
109
|
+
export declare const MINIMAL_STOP_CUTS = 12;
|
|
110
|
+
/**
|
|
111
|
+
* 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.
|
|
112
|
+
* With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function minimalStops(count: number, stops: (cuts: readonly number[]) => boolean): number[][] | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* This function gives an upper limit of the curve of a stop for each dependence of the cuts.
|
|
117
|
+
* At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.
|
|
118
|
+
* With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.
|
|
119
|
+
*
|
|
120
|
+
* @param curves - The curves of the cuts
|
|
121
|
+
* @param sets - The minimal sets of `minimalStops`, or `undefined`
|
|
122
|
+
* @throws RangeError when a curve does not end at a chance of 0
|
|
123
|
+
*/
|
|
124
|
+
export declare function upperStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival;
|
|
125
|
+
/** The largest difference between `independentStop` and the true chance of a stop of independent cuts, at each time. */
|
|
126
|
+
export declare const INDEPENDENT_TOLERANCE = 1e-6;
|
|
127
|
+
/**
|
|
128
|
+
* This function gives the curve of a stop of some cuts when the cuts are independent.
|
|
129
|
+
* At each time `t`, the supply is stopped when the cuts that are still on contain a minimal set.
|
|
130
|
+
* Its chance is a sum over each set of cuts that stops the supply.
|
|
131
|
+
* Each term is the product of `s(t)` for the cuts that are on, and of `1 - s(t)` for the other cuts.
|
|
132
|
+
*
|
|
133
|
+
* - When any one cut stops the supply, the result is `1 - prod(1 - s)`. It is not less than the longest cut (`eventStop`).
|
|
134
|
+
* - When the supply needs `any` of two parts, the stop of the two is `s1 * s2`. It is not more than the shorter cut.
|
|
135
|
+
* - The result is not more than `upperStop` of the same sets, because `upperStop` is a limit for each dependence.
|
|
136
|
+
* - Between two points of the curves the chance is a polynomial, not a line. The function splits each such segment into equal pieces.
|
|
137
|
+
* The chance is linear in each `s`, and each mixed second derivative is between -1 and 1.
|
|
138
|
+
* 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.
|
|
139
|
+
* 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.
|
|
140
|
+
*
|
|
141
|
+
* @param curves - The curves of the cuts, each one good for `checkEndurance`
|
|
142
|
+
* @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]]`
|
|
143
|
+
* @throws RangeError when a curve does not end at a chance of 0
|
|
144
|
+
*/
|
|
145
|
+
export declare function independentStop(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): Survival | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* The curves of the stop of a draw. `event` is for one event that makes each cut longer together, and `independent` is for independent cuts.
|
|
148
|
+
* `upper` is an upper limit for each dependence.
|
|
149
|
+
*/
|
|
150
|
+
export interface StopCurves {
|
|
151
|
+
readonly event: Survival;
|
|
152
|
+
/** The stop when the cuts are independent (`independentStop`). When `coarse` is true, it is `upper`. */
|
|
153
|
+
readonly independent: Survival;
|
|
154
|
+
readonly upper: Survival;
|
|
155
|
+
/** 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`. */
|
|
156
|
+
readonly coarse: boolean;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.
|
|
160
|
+
*
|
|
161
|
+
* - A set of cuts stops the supply when the supply cannot work without the cut parts, through the needs of the stack.
|
|
162
|
+
* - Only the cuts of the supply, and of the parts that it needs through the stack, count. Another cut does not change the curves.
|
|
163
|
+
* - The parts of `down` are down for the full event. When they stop the supply with no cut, the query has no curve.
|
|
164
|
+
* - `event` is `eventStop`. `independent` is `independentStop`, and `upper` is `upperStop`, over the minimal sets of the cuts that count.
|
|
165
|
+
* - Past `MINIMAL_STOP_CUTS` cuts that count, `upper` is the sum of their curves, `independent` is `upper`, and `coarse` is true.
|
|
166
|
+
*/
|
|
167
|
+
export declare function stopCurves(caseCuts: CaseCuts, draw: Draw, options?: Pick<CaseOptions, "stack" | "down">): StopCurves | undefined;
|
|
168
|
+
/** The shortfall of each level, in user-days, and the draws that the query cannot read. */
|
|
169
|
+
export interface Shortfall {
|
|
170
|
+
/**
|
|
171
|
+
* The user-days of each level of the layer, when one event makes each cut longer together. The query does not add two levels.
|
|
172
|
+
* This value is not a limit. The true value can be more or less. `upper` is the limit.
|
|
173
|
+
*/
|
|
174
|
+
readonly levels: Readonly<Record<string, number>>;
|
|
175
|
+
/** The user-days of each level when the cuts are independent (`StopCurves.independent`). This value is not more than `upper`. */
|
|
176
|
+
readonly independent: Readonly<Record<string, number>>;
|
|
177
|
+
/** 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. */
|
|
178
|
+
readonly upper: Readonly<Record<string, number>>;
|
|
179
|
+
/**
|
|
180
|
+
* The needs of the draws whose stop has no curve (`stopCurves`).
|
|
181
|
+
* The query has no curve of their duration, so their shortfall is not in `levels`. A gate shows them as no read.
|
|
182
|
+
*/
|
|
183
|
+
readonly unread: readonly string[];
|
|
184
|
+
/** The needs of the draws whose `upper` is coarse (`StopCurves.coarse`). A gate on `upper` shows them. */
|
|
185
|
+
readonly coarse: readonly string[];
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* This function gives the shortfall of one event of a case: for each draw, `E[max(0, min(D, h) - T)] * users`.
|
|
189
|
+
* `T` is the endurance of the draw, `D` is the duration of the stop of its supply (`stopCurves`), and `h` is the horizon.
|
|
190
|
+
*
|
|
191
|
+
* @param layer - The endurance layer
|
|
192
|
+
* @param caseCuts - The case
|
|
193
|
+
* @param endurance - The endurance of the case, from `enduranceOf`
|
|
194
|
+
* @param options - The stack or the parts that are also down, as for `enduranceOf`, and the horizon
|
|
195
|
+
* @throws RangeError when the horizon is not a number more than 0
|
|
196
|
+
*/
|
|
197
|
+
export declare function caseShortfall(layer: EnduranceLayer, caseCuts: CaseCuts, endurance: Endurance, options?: ShortfallOptions): Shortfall;
|
|
198
|
+
/** The shortfall of one year at one place, with the part of each case. */
|
|
199
|
+
export interface YearShortfall extends Shortfall {
|
|
200
|
+
readonly place: string;
|
|
201
|
+
/** The part of each case. `rate` is the expected count of its events in one year. */
|
|
202
|
+
readonly cases: readonly {
|
|
203
|
+
readonly case: string;
|
|
204
|
+
readonly rate: number;
|
|
205
|
+
readonly endurance: Endurance;
|
|
206
|
+
readonly shortfall: Shortfall;
|
|
207
|
+
}[];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* This function gives the shortfall of one year at one place.
|
|
211
|
+
* It is the sum over the cases of the layer of the expected count of the events of each case times its shortfall.
|
|
212
|
+
*
|
|
213
|
+
* - 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.
|
|
214
|
+
* - A case with no prior at the place is not in the sum.
|
|
215
|
+
* - `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.
|
|
216
|
+
*
|
|
217
|
+
* @param layer - The endurance layer, with its cases and priors
|
|
218
|
+
* @param place - The place of the priors
|
|
219
|
+
* @param options - The date, the stack or the parts that are also down, and the horizon
|
|
220
|
+
* @throws RangeError when the date is not `YYYY-MM-DD`, or when the horizon is not a number more than 0
|
|
221
|
+
*/
|
|
222
|
+
export declare function yearShortfall(layer: EnduranceLayer, place: string, options: CaseOptions & ShortfallOptions): YearShortfall;
|
|
223
|
+
/**
|
|
224
|
+
* These are the codes of the gate. Each code is an error, except `endurance-no-way`, which is a warning.
|
|
225
|
+
*
|
|
226
|
+
* - `endurance-twice`: two or more records of one list have one key. A key is a level, a resource, a store, a need, a converter or a case.
|
|
227
|
+
* The key of a prior is its case and its place. A converter takes each resource on one line, and a case cuts each part one time.
|
|
228
|
+
* - `endurance-level-unknown`: the level of a draw is not a level of the layer.
|
|
229
|
+
* - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.
|
|
230
|
+
* - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.
|
|
231
|
+
* - `endurance-range`: an amount, a rate, a count or a factor is not a finite number of 0 or more. Or a reach is not from 0 to 1.
|
|
232
|
+
* - `endurance-date`: a date is not a date `YYYY-MM-DD`.
|
|
233
|
+
* - `endurance-converter-empty`: a converter takes nothing, or it gives an amount of 0.
|
|
234
|
+
* - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.
|
|
235
|
+
* Or its days do not increase, or its chance increases.
|
|
236
|
+
* - `endurance-prior-case`: a prior names a case that the layer does not have.
|
|
237
|
+
* - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.
|
|
238
|
+
* - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.
|
|
239
|
+
*/
|
|
240
|
+
export declare const ENDURANCE_CODES: readonly ["endurance-twice", "endurance-level-unknown", "endurance-resource-unknown", "endurance-part-unknown", "endurance-range", "endurance-date", "endurance-converter-empty", "endurance-curve", "endurance-prior-case", "endurance-cycle", "endurance-no-way"];
|
|
241
|
+
/** A code of `ENDURANCE_CODES`. */
|
|
242
|
+
export type EnduranceCode = (typeof ENDURANCE_CODES)[number];
|
|
243
|
+
/** A fault of the gate of an endurance layer. */
|
|
244
|
+
export interface EnduranceFault extends Fault {
|
|
245
|
+
readonly code: EnduranceCode;
|
|
246
|
+
}
|
|
247
|
+
/** This function gives the first fault of a survival curve, or `undefined`. */
|
|
248
|
+
export declare function curveFault(curve: Survival): string | undefined;
|
|
249
|
+
/**
|
|
250
|
+
* This function gives each fault of an endurance layer. With a base stack, it also examines the `id` of each part. A list with no error tells that the gate passes.
|
|
251
|
+
*
|
|
252
|
+
* The faults are in the order of the layer. The function is pure.
|
|
253
|
+
*
|
|
254
|
+
* @param layer - The endurance layer
|
|
255
|
+
* @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.
|
|
256
|
+
* @returns The faults
|
|
257
|
+
*/
|
|
258
|
+
export declare function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[];
|
|
259
|
+
/** This function tells if a list of faults has an error. */
|
|
260
|
+
export declare function hasEnduranceError(faults: readonly EnduranceFault[]): boolean;
|
|
261
|
+
/**
|
|
262
|
+
* This function joins the endurance layers of the fragments of a stack into one layer.
|
|
263
|
+
*
|
|
264
|
+
* - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.
|
|
265
|
+
* - The records of each list are in the order of the fragments.
|
|
266
|
+
* - One key in two or more fragments is a fault, also when the records are equal. The key of a direct use is its resource and its need.
|
|
267
|
+
*
|
|
268
|
+
* The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.
|
|
269
|
+
*
|
|
270
|
+
* @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.
|
|
271
|
+
* @returns The joined layer, or the faults of the join.
|
|
272
|
+
*/
|
|
273
|
+
export declare function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer>;
|
|
274
|
+
/** The base stack of the sample: the supplies of the building and a camp stove. */
|
|
275
|
+
export declare const SAMPLE_ENDURANCE_STACK: Stack;
|
|
276
|
+
/**
|
|
277
|
+
* The endurance layer of the sample.
|
|
278
|
+
*
|
|
279
|
+
* - The drinking water holds 75.7 L / 11.355 L a day = 6.667 days.
|
|
280
|
+
* - 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.
|
|
281
|
+
* - The power holds 1000 Wh / 150 Wh a day = 6.667 days.
|
|
282
|
+
* - The filled bottles are past their due date, so they give nothing.
|
|
283
|
+
*/
|
|
284
|
+
export declare const SAMPLE_ENDURANCE: EnduranceLayer;
|
|
285
|
+
export { CaseCuts, Converter, Cut, DirectUse, Draw, DrawEndurance, ENDURANCE_SCHEMA, Endurance, EnduranceLayer, Gift, IsoDate, Prior, Resource, Store, Survival };
|
|
286
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/endurance.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAOiB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;wBAOK,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAoB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;;;;;;;;;;;;;wBAiKxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;wBCtO9E,WAAW,OAAO,UAAU;;;;;;wBAoB5B,SAAS,OAAO,UAAU,cAAc;;;;;;iBAiBvC,yBAAyB,KAAK;;WAEpC;;;;;;wBAaK,iBAAiB,OAAO,UAAU;;wBAWlC,WAAW,OAAO;;wBAKlB,SAAS,OAAO;;;;;;;;;;;;;;;;wBAoDhB,UAAU,iBAAiB,YAAY,QAAQ,sCAAsC;;;;;;;;wBAiBrF,YAAY,iBAAiB,aAAa;;;;;qBAU7C;;;;;wBAMG,aAAa,eAAe,QAAQ;;;;;;;;;;wBA8BpC,UAAU,iBAAiB,YAAY,mDAAmD;;qBAiB7F;;;;;;;;;;;;;;;;;;;wBAoBG,gBAAgB,iBAAiB,YAAY,mDAAmD;;;;;iBAqD/F;WACN,OAAO;;WAEP,aAAa;WACb,OAAO;;WAEP;;;;;;;;;;;wBA+CK,WAAW,UAAU,UAAU,MAAM,MAAM,UAAS,KAAK,iCAAsC;;iBAK9F;;;;;WAKN,QAAQ,SAAS;;WAEjB,aAAa,SAAS;;WAEtB,OAAO,SAAS;;;;;WAKhB;;WAEA;;;;;;;;;;;;wBAiBK,cAAc,OAAO,gBAAgB,UAAU,UAAU,WAAW,WAAW,UAAS,mBAAwB;;iBAyB/G,sBAAsB;WAC5B;;WAEA;aAA2B;aAAuB;aAAuB,WAAW;aAAoB,WAAW;;;;;;;;;;;;;;;;wBAgB9G,cAAc,OAAO,gBAAgB,eAAe,SAAS,cAAc,mBAAmB;;;;;;;;;;;;;;;;;;qBCvYjG;;YA2BD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;wBAID,WAAW,OAAO;;;;;;;;;;wBAsBlB,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBAqHtD,kBAAkB,iBAAiB;;;;;;;;;;;;;wBCrLnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCV5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
|