@mark1russell7/stack-endurance 0.8.14 → 0.8.15

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/README.md CHANGED
@@ -50,6 +50,8 @@ With the option `horizon` of `h` days, the shortfall counts only the first `h` d
50
50
 
51
51
  The option `share` of `yearShortfall` sets the share of the stores in each case. The default `take` uses `enduranceOf`. With `best`, the query uses `bestEndurance`, and the horizon of the shortfall is the horizon of the share. Thus a draw at the horizon keeps back only `h` times its demand, and the lower levels get the rest.
52
52
 
53
+ Since 0.8.15, a prior can have an `interval` of its `perYear` at a level (`RateInterval` of the core). Then `yearShortfall` gives a `range`. It is the same sum with the rate of each case at the low end of its interval, and at the high end. Each end holds only for each case alone, so the range shows the sampling error of the rates. It is not a joint interval. A case with no interval is in `range.without`, and its rate is at the two ends.
54
+
53
55
  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.
54
56
 
55
57
  A cut can have no `duration`, as before a source gives its curve. Then each draw whose stop the cut can be part of goes in `unread`. A draw whose minimal stop sets do not have the cut keeps its curves. When the query has no minimal sets, it cannot tell, so the draw goes in `unread`. The gate gives the warning `endurance-cut-no-curve` for each such cut.
package/build/add-on.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as checkEndurance, t as joinEndurance } from "./join-Cc6JzE5G.js";
1
+ import { r as checkEndurance, t as joinEndurance } from "./join-C9nJDe7B.js";
2
2
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
3
3
  import { parseEndurance } from "./schema.js";
4
4
  // src/add-on.ts
package/build/index.d.ts CHANGED
@@ -372,16 +372,39 @@ export interface YearShortfallOptions extends CaseOptions, ShortfallOptions {
372
372
  */
373
373
  readonly share?: Share | undefined;
374
374
  }
375
+ /** The user-days of each level for each curve of the stop: the three sums of a shortfall. Since 0.8.15. */
376
+ export type ShortfallDays = Pick<Shortfall, "levels" | "independent" | "upper">;
377
+ /**
378
+ * The range of the shortfall of one year from the intervals of the rates of its cases (`Prior.interval`). Since 0.8.15.
379
+ * `low` puts the rate of each case at the low end of its interval, and `high` puts it at the high end.
380
+ * Each end holds only for each case alone, so the two values are a range of the sampling error, not a joint interval.
381
+ * The mean of a skewed law can be above the high end, so the expected value can be above `high`.
382
+ */
383
+ export interface RateRange {
384
+ /** The least level of the intervals of the cases in the sum. */
385
+ readonly level: number;
386
+ readonly low: ShortfallDays;
387
+ readonly high: ShortfallDays;
388
+ /** The cases in the sum with no interval of their rate. Their rate is at the two ends. */
389
+ readonly without: readonly string[];
390
+ }
391
+ /** The part of one case in the shortfall of one year. */
392
+ export interface YearCase {
393
+ readonly case: string;
394
+ /** The expected count of the events of the case at the place in one year (`yearRate`). */
395
+ readonly rate: number;
396
+ /** The interval of `rate` from the interval of the prior, times its reach. A prior with no interval gives none. Since 0.8.15. */
397
+ readonly rateInterval?: readonly [low: number, high: number] | undefined;
398
+ readonly endurance: Endurance;
399
+ readonly shortfall: Shortfall;
400
+ }
375
401
  /** The shortfall of one year at one place, with the part of each case. */
376
402
  export interface YearShortfall extends Shortfall {
377
403
  readonly place: string;
378
404
  /** The part of each case. `rate` is the expected count of its events in one year. */
379
- readonly cases: readonly {
380
- readonly case: string;
381
- readonly rate: number;
382
- readonly endurance: Endurance;
383
- readonly shortfall: Shortfall;
384
- }[];
405
+ readonly cases: readonly YearCase[];
406
+ /** The range from the intervals of the rates. A year with no case with an interval has no range. Since 0.8.15. */
407
+ readonly range?: RateRange | undefined;
385
408
  }
386
409
  /**
387
410
  * This function gives the shortfall of one year at one place.
@@ -393,6 +416,7 @@ export interface YearShortfall extends Shortfall {
393
416
  * - `bound` is the weakest bound of the cases in the sum. A case with no prior, or with an expected count of 0, adds 0, so it does not change the bound.
394
417
  *
395
418
  * - With `share: "best"`, the endurance of each case comes from `bestEndurance` with the horizon of the shortfall.
419
+ * - `range` is the same sum with the rate of each case at each end of its interval (`RateRange`).
396
420
  *
397
421
  * @param layer - The endurance layer, with its cases and priors
398
422
  * @param place - The place of the priors
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAUiB;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuLxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBC3P7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+BK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;iBC/CrG,oBAAoB;;;;;;WAM1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyDK,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBCvEhF,SAAS,OAAO,UAAU,cAAc;;;;;;;;;;iBAqBvC,yBAAyB,KAAK,gCAAgC,KAAK;;WAEzE;;iBAGM,yBAAyB;;WAE/B;;;;;;wBAqBK,iBAAiB,OAAO,UAAU;;wBAWlC,WAAW,OAAO;;wBAKlB,SAAS,OAAO;;;;;;;;;;;;;;;;wBAoDhB,UAAU,iBAAiB,YAAY,QAAQ,sCAAsC;;;;;;;;wBAiBrF,YAAY,iBAAiB,aAAa;;;;;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AuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBAoJtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBChNnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
1
+ {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts"],"mappings":";;;iBAUiB;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuLxB,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBC3P7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA+BK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;iBC/CrG,oBAAoB;;;;;;WAM1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAyDK,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBCvEhF,SAAS,OAAO,UAAU,cAAc;;;;;;;;;;iBAqBvC,yBAAyB,KAAK,gCAAgC,KAAK;;WAEzE;;iBAGM,yBAAyB;;WAE/B;;;;;;wBAqBK,iBAAiB,OAAO,UAA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EP,WAAW;;WAEX,OAAOA;;WAEP;;;;;WAKA,OAAO;;;iBAID;WACN;WACA;WACA;WACA,OAAO;;WAEP;;WAEA,gBAAgB;;WAEhB;;WAEA;;WAEA,OAAOA;;;;;;;;;;;;;;;;wBAiBF,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;qBC9vBpF;;YAmCD,wBAAwB;;iBAGnB,uBAAuB;WAC7B,MAAM;;;;;;;;;;;wBAcD,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBAsJtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBClNnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
- import { S as exact, _ as fewestRow, a as hasEnduranceError, b as addTo, c as drawDemand, d as giftResource, f as storeAmounts, g as drawBlock, h as deviceUse, i as curveFault, l as enduranceOf, m as caseParts, n as ENDURANCE_CODES, o as caseDraws, p as Program, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed, v as reachOf, x as dense, y as valueAt } from "./join-Cc6JzE5G.js";
2
+ import { S as exact, _ as fewestRow, a as hasEnduranceError, b as addTo, c as drawDemand, d as giftResource, f as storeAmounts, g as drawBlock, h as deviceUse, i as curveFault, l as enduranceOf, m as caseParts, n as ENDURANCE_CODES, o as caseDraws, p as Program, r as checkEndurance, s as caseStopped, t as joinEndurance, u as giftNeed, v as reachOf, x as dense, y as valueAt } from "./join-C9nJDe7B.js";
3
3
  import { DEFAULT_MAX_SETS, STACK_SCHEMA, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
4
4
  import { ONE, ZERO, add, div, equals, mul, neg, sign, sub, toNumber } from "@mark1russell7/rational";
5
5
  import { solveLexicographic } from "@mark1russell7/linear";
@@ -918,6 +918,7 @@ function shareEndurance(layer, caseCuts, options, share) {
918
918
  * - `bound` is the weakest bound of the cases in the sum. A case with no prior, or with an expected count of 0, adds 0, so it does not change the bound.
919
919
  *
920
920
  * - With `share: "best"`, the endurance of each case comes from `bestEndurance` with the horizon of the shortfall.
921
+ * - `range` is the same sum with the rate of each case at each end of its interval (`RateRange`).
921
922
  *
922
923
  * @param layer - The endurance layer, with its cases and priors
923
924
  * @param place - The place of the priors
@@ -936,15 +937,34 @@ function yearShortfall(layer, place, options) {
936
937
  const independentUpper = [];
937
938
  const cases = [];
938
939
  const bounds = [];
940
+ const low = {
941
+ levels: zeroLevels(layer),
942
+ independent: zeroLevels(layer),
943
+ upper: zeroLevels(layer)
944
+ };
945
+ const high = {
946
+ levels: zeroLevels(layer),
947
+ independent: zeroLevels(layer),
948
+ upper: zeroLevels(layer)
949
+ };
950
+ const without = [];
951
+ let level = 1e400;
939
952
  for (const caseCuts of layer.cases ?? []) {
940
953
  const prior = (layer.priors ?? []).find((item) => item.case === caseCuts.case && item.place === place);
941
954
  if (prior === void 0) continue;
942
955
  const rate = yearRate(prior);
943
956
  const endurance = shareEndurance(layer, caseCuts, options, share);
944
957
  const shortfall = caseShortfall(layer, caseCuts, endurance, options);
945
- for (const [level, days] of Object.entries(shortfall.levels)) levels[level] = (levels[level] ?? 0) + rate * days;
946
- for (const [level, days] of Object.entries(shortfall.independent)) independent[level] = (independent[level] ?? 0) + rate * days;
947
- for (const [level, days] of Object.entries(shortfall.upper)) upper[level] = (upper[level] ?? 0) + rate * days;
958
+ addDays({
959
+ levels,
960
+ independent,
961
+ upper
962
+ }, shortfall, rate);
963
+ const rateInterval = prior.interval === void 0 ? void 0 : [prior.interval.low * prior.reach, prior.interval.high * prior.reach];
964
+ if (rateInterval === void 0) without.push(caseCuts.case);
965
+ else level = Math.min(level, prior.interval?.level ?? level);
966
+ addDays(low, shortfall, rateInterval?.[0] ?? rate);
967
+ addDays(high, shortfall, rateInterval?.[1] ?? rate);
948
968
  for (const need of shortfall.unread) if (!unread.includes(need)) unread.push(need);
949
969
  for (const need of shortfall.coarse) if (!coarse.includes(need)) coarse.push(need);
950
970
  for (const need of shortfall.independentUpper) if (!independentUpper.includes(need)) independentUpper.push(need);
@@ -952,10 +972,17 @@ function yearShortfall(layer, place, options) {
952
972
  cases.push({
953
973
  case: caseCuts.case,
954
974
  rate,
975
+ ...rateInterval === void 0 ? {} : { rateInterval },
955
976
  endurance,
956
977
  shortfall
957
978
  });
958
979
  }
980
+ const range = Number.isFinite(level) ? { range: {
981
+ level,
982
+ low,
983
+ high,
984
+ without
985
+ } } : {};
959
986
  return {
960
987
  place,
961
988
  levels,
@@ -965,9 +992,16 @@ function yearShortfall(layer, place, options) {
965
992
  coarse,
966
993
  independentUpper,
967
994
  bound: weakestBound(bounds),
968
- cases
995
+ cases,
996
+ ...range
969
997
  };
970
998
  }
999
+ /** This function adds the user-days of a shortfall times a count of events to each sum of the days. */
1000
+ function addDays(days, shortfall, count) {
1001
+ for (const [level, value] of Object.entries(shortfall.levels)) days.levels[level] = (days.levels[level] ?? 0) + count * value;
1002
+ for (const [level, value] of Object.entries(shortfall.independent)) days.independent[level] = (days.independent[level] ?? 0) + count * value;
1003
+ for (const [level, value] of Object.entries(shortfall.upper)) days.upper[level] = (days.upper[level] ?? 0) + count * value;
1004
+ }
971
1005
  /**
972
1006
  * This function gives the outlook of one event of a case. For each draw, it gives the days, the chance that the
973
1007
  * stores last through the stop, and the shortfall. A page of a place can show it for each case of its region.