@mark1russell7/stack-endurance 0.8.24 → 0.8.26

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
@@ -154,12 +154,40 @@ if (storm !== undefined) {
154
154
  }
155
155
  ```
156
156
 
157
+ ## The days for one unit of money
158
+
159
+ `daysPerDollar(sensitivity, prices, options)` names the next buy. It ranks the inputs of a sensitivity by the days that they add for one unit of money. Since 0.8.25 (M2-days-per-dollar).
160
+
161
+ - The prices are input data: a `PriceTable` with a currency code and the price of one unit of each input. The caller owns the source of the prices.
162
+ - The key of a price is the key of the input, for example `store:jugs`. The kind and the target are not sufficient, because the inputs of one converter have one target.
163
+ - The function reads the result of `enduranceSensitivity`. It does not calculate the days again.
164
+ - `perUnit` gives the days of each level for one unit of the input. `perDollar` divides them by the price.
165
+ - The rank is by level, as the rank of the sensitivity. It compares the days for one unit of money of the first level, then of the next level. The largest value comes first. Two equal inputs go in the order of their keys.
166
+ - Thus a buy that adds days to a higher level comes before each buy for a lower level.
167
+ - An input with a change of 0 days stays in the rank, after each input that adds days at its level.
168
+ - An input with no price has no rank. It goes in `unpriced` with the reason `no-price`. It does not get a price of 0.
169
+ - A price that is not a finite number more than 0 is a bad price. The input goes in `unpriced` with the reason `bad-price`. The function does not throw, so one bad price does not stop the rank.
170
+ - `unused` names each key of the table that is not the key of an input. Thus an error in a key shows.
171
+
172
+ ```ts
173
+ import { daysPerDollar, enduranceSensitivity, SAMPLE_ENDURANCE } from "@mark1russell7/stack-endurance";
174
+
175
+ const storm = SAMPLE_ENDURANCE.cases?.find((item) => item.case === "storm");
176
+ if (storm !== undefined) {
177
+ const sensitivity = enduranceSensitivity(SAMPLE_ENDURANCE, storm, { at: "2026-12-01" });
178
+ const prices = { currency: "XTS", prices: { "store:jugs": 0.5 } };
179
+ const rank = daysPerDollar(sensitivity, prices, { levels: SAMPLE_ENDURANCE.levels });
180
+ // rank.ranked[0] is the next buy. Each input with no price is in rank.unpriced.
181
+ }
182
+ ```
183
+
157
184
  ## The joint days
158
185
 
159
186
  `jointDays(layer, caseCuts, options, needs)` gives the joint days of a set of draws. These are the largest count of days `d` at which each draw of the set holds `d` days together.
160
187
 
161
188
  - The function finds the best share of the stores and of the runs of the converters. It does not use the take order.
162
189
  - It solves a linear program with exact rationals (`@mark1russell7/linear`). Only the change back to a number rounds.
190
+ - Each later objective starts from the optimal basis of the objective before it (the warm start of `@mark1russell7/linear`). Thus it does no phase 1.
163
191
  - The variables are the days, the take of each direct use, the runs of each converter, and the share of each stock for each draw.
164
192
  - Each draw of the set gets `d` times its demand. The takes of a resource are not more than its stock plus the gifts of its makers.
165
193
  - The runs of a converter with a limit `perDay` are not more than `perDay` times `devices` times `d`. The converters of one device share the limit.
@@ -239,7 +267,7 @@ With no horizon, the drink takes all the water for 10 days, and the food gets 0
239
267
 
240
268
  | Entry | What it has |
241
269
  | --- | --- |
242
- | `@mark1russell7/stack-endurance` | The records of a layer, the endurance, joint days, best endurance, shortfall and sensitivity queries, the gate, the join and a sample. |
270
+ | `@mark1russell7/stack-endurance` | The records of a layer, the endurance, joint days, best endurance, shortfall and sensitivity queries, the rank of a buy by days for one unit of money, the gate, the join and a sample. |
243
271
  | `@mark1russell7/stack-endurance/schema` | `enduranceSchema`, the zod schema of a layer, with `parseEndurance`. |
244
272
  | `@mark1russell7/stack-endurance/add-on` | `enduranceAddOn`, the add-on in the form of the layer contract of the core. |
245
273
 
package/build/add-on.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as checkEndurance, t as joinEndurance } from "./join-CxA4Td_Z.js";
1
+ import { r as checkEndurance, t as joinEndurance } from "./join-BwTee3Ue.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
@@ -811,5 +811,88 @@ export interface Sensitivity {
811
811
  * @throws RangeError for a step that is not a finite number more than 0, and for the errors of `enduranceOf` and `caseOutlook`
812
812
  */
813
813
  export declare function enduranceSensitivity(layer: EnduranceLayer, caseCuts: CaseCuts, options: SensitivityOptions): Sensitivity;
814
+ /**
815
+ * A table of prices: the price of one unit of each input, in one currency.
816
+ * The key of a price is the key of the input (`SensitivityInput.id`), for example `store:jugs` or `converter:cook.gives`.
817
+ * The key is the input key, because the kind and the target do not identify one input. A converter has an input
818
+ * for its gift, for each take and for its limit, all with the same target.
819
+ */
820
+ export interface PriceTable {
821
+ /** The code of the currency of each price, for example `USD`. The rank does not convert a currency. */
822
+ readonly currency: string;
823
+ /** The price of one unit of each input, by the key of the input. The unit is the unit of the input, for example 1 L of a store. */
824
+ readonly prices: Readonly<Record<string, number>>;
825
+ }
826
+ /** The options of `daysPerDollar`. */
827
+ export interface DaysPerDollarOptions {
828
+ /** The levels of the layer, the most important first (`EnduranceLayer.levels`). The rank compares the levels in this order. */
829
+ readonly levels: readonly string[];
830
+ }
831
+ /** The reason why an input has no rank: the table has no price for it, or its price is bad. A bad price is not a finite number more than 0. */
832
+ export type UnpricedReason = "no-price" | "bad-price";
833
+ /** One input with a price, and its days for one unit and for one unit of money. */
834
+ export interface PricedInput {
835
+ readonly id: string;
836
+ readonly kind: SensitivityKind;
837
+ readonly target: string;
838
+ readonly field: string;
839
+ /** The price of one unit of the input, in the currency of the table. */
840
+ readonly price: number;
841
+ /** The days of each level for one unit of the input: the sum of the changes of the level divided by the size of `delta`. */
842
+ readonly perUnit: Readonly<Record<string, number>>;
843
+ /** The days of each level for one unit of money: `perUnit` divided by `price`. */
844
+ readonly perDollar: Readonly<Record<string, number>>;
845
+ }
846
+ /** One input with no rank, and the reason. It has no price, so it has no days for one unit of money. */
847
+ export interface UnpricedInput {
848
+ readonly id: string;
849
+ readonly kind: SensitivityKind;
850
+ readonly target: string;
851
+ readonly field: string;
852
+ /** The days of each level for one unit of the input. */
853
+ readonly perUnit: Readonly<Record<string, number>>;
854
+ readonly reason: UnpricedReason;
855
+ }
856
+ /** The rank of the inputs by the days that they add for one unit of money. */
857
+ export interface DaysPerDollar {
858
+ readonly case: string;
859
+ readonly at: IsoDate;
860
+ /** The currency of the table. */
861
+ readonly currency: string;
862
+ /** The inputs with a price, in the order of the rank. The first input is the next buy. Refer to `daysPerDollar`. */
863
+ readonly ranked: readonly PricedInput[];
864
+ /** The inputs with no price or with a bad price, in the order of the sensitivity. They have no rank. */
865
+ readonly unpriced: readonly UnpricedInput[];
866
+ /** The keys of the table that are not the key of an input, in the order of their codes. A key with an error shows here. */
867
+ readonly unused: readonly string[];
868
+ }
869
+ /**
870
+ * This function ranks the inputs of a sensitivity by the days that they add for one unit of money.
871
+ * With the price of one unit of each input, the first input of the rank is the next buy.
872
+ *
873
+ * - The function reads the result of `enduranceSensitivity`. It does not calculate the days again.
874
+ * - The days of an input for one unit are the sum of the changes of each level divided by the size of `delta`.
875
+ * Thus a step of 2, or a half step of a low draw, gives the days of 1 unit.
876
+ * - The days for one unit of money are the days for one unit divided by the price of one unit.
877
+ * - The rank is by level, as the rank of the sensitivity. It compares the days for one unit of money of the first level,
878
+ * then of the next level, and so on. The largest value comes first. Two equal inputs go in the order of their keys.
879
+ * - Thus an input that adds days to a higher level comes before each input that adds days only to lower levels. A buy
880
+ * for a lower level does not go before a buy for a higher level, also when it gives more days for its money.
881
+ * - An input with a change of 0 days has 0 days for one unit of money. It stays in the rank, after each input that adds
882
+ * days at its level.
883
+ * - An input with no price in the table has no rank. It goes in `unpriced` with the reason `no-price`. It does not get a price of 0.
884
+ * - A price that is not a finite number more than 0 is a bad price. The input goes in `unpriced` with the reason
885
+ * `bad-price`. The function does not throw, so one bad price of a live table does not stop the rank of the others.
886
+ * A lower draw costs nothing, but the table gives it a price only when a buy lowers it.
887
+ * - `unused` names each key of the table that is not the key of an input.
888
+ *
889
+ * The function is pure.
890
+ *
891
+ * @param sensitivity - The result of `enduranceSensitivity`
892
+ * @param prices - The price of one unit of each input, by the key of the input
893
+ * @param options - The levels of the layer, the most important first
894
+ * @returns The inputs with a price in the order of the rank, the inputs with no rank, and the keys that are not used
895
+ */
896
+ export declare function daysPerDollar(sensitivity: Sensitivity, prices: PriceTable, options: DaysPerDollarOptions): DaysPerDollar;
814
897
  export { type CaseCuts, Converter, type Cut, type CutBound, DirectUse, Draw, DrawEndurance, ENDURANCE_SCHEMA, Endurance, EnduranceLayer, Gift, Harvest, IsoDate, MonthDay, type Prior, Resource, Season, Store, type Survival, curveFault, survivalAt };
815
898
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts","../src/sensitivity.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,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;;;;;;;;wBAmMxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,OAAO;;;;;;wBAOF,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;;;;;wBAkB9F,UAAU,OAAO,gBAAgB,cAAc;;;;;;;;;;;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qBAkBxB,kBAAkB;;qBChBlB;;iBAGI,2BAA2B,aAAa;;WAE9C;;;YAIC;;;;;iBAMK;;WAEN,QAAQ;;WAER,OAAO;;WAEP,QAAQ;;WAER,aAAa;;WAEb,YAAY;;;iBAIN;WACN;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,SAAS;;;iBAIH;;;;;WAKN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,gBAAgB;;WAEhB,QAAQ,SAAS;;;iBAIX;WACN;WACA,IAAI;;WAEJ;;WAEA,MAAM;;WAEN,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2GZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB"}
1
+ {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts","../src/sensitivity.ts","../src/buy.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,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;;;;;;;;wBAmMxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP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,eAAe,OAAO,gBAAgB,QAAQ,QAAQ;;wBAwNtD,kBAAkB,iBAAiB;;;;;;;;;;;;;;;;;wBCnSnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB;;qBChBlB;;iBAGI,2BAA2B,aAAa;;WAE9C;;;YAIC;;;;;iBAMK;;WAEN,QAAQ;;WAER,OAAO;;WAEP,QAAQ;;WAER,aAAa;;WAEb,YAAY;;;iBAIN;WACN;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,SAAS;;;iBAIH;;;;;WAKN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,gBAAgB;;WAEhB,QAAQ,SAAS;;;iBAIX;WACN;WACA,IAAI;;WAEJ;;WAEA,MAAM;;WAEN,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2GZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB;;;;;;;iBCnL7F;;WAEN;;WAEA,QAAQ,SAAS;;;iBAIX;;WAEN;;;YAIC;;iBAGK;WACN;WACA,MAAM;WACN;WACA;;WAEA;;WAEA,SAAS,SAAS;;WAElB,WAAW,SAAS;;;iBAId;WACN;WACA,MAAM;WACN;WACA;;WAEA,SAAS,SAAS;WAClB,QAAQ;;;iBAIF;WACN;WACA,IAAI;;WAEJ;;WAEA,iBAAiB;;WAEjB,mBAAmB;;WAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgDK,cAAc,aAAa,aAAa,QAAQ,YAAY,SAAS,uBAAuB"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
- import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as deviceKey, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as drawBlock, k as caseParts, l as drawDemand, m as monthEdges, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as shareOf, w as seasonBest, x as fewestOpen, y as sowDays, z as isSource } from "./join-CxA4Td_Z.js";
2
+ import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as deviceKey, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as drawBlock, k as caseParts, l as drawDemand, m as monthEdges, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as shareOf, w as seasonBest, x as fewestOpen, y as sowDays, z as isSource } from "./join-BwTee3Ue.js";
3
3
  import { DEFAULT_MAX_SETS, STACK_SCHEMA, dateOfDay, dayNumber, 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";
@@ -113,7 +113,7 @@ function jointDays(layer, caseCuts, options, needs) {
113
113
  coefficients: dense(fewestRow(runCols), program.count)
114
114
  }
115
115
  ];
116
- const solved = solveLexicographic(program.constraints(), objectives);
116
+ const solved = solveLexicographic(program.constraints(), objectives, { warm: true });
117
117
  if (solved.status !== "optimal") return endless;
118
118
  const x = solved.x;
119
119
  const takes = {};
@@ -261,7 +261,7 @@ function bestEndurance(layer, caseCuts, options) {
261
261
  sense: "min",
262
262
  coefficients: dense(fewestRow(last.blocks.flatMap((block) => [...block.runs])), last.program.count)
263
263
  }];
264
- const solved = solveLexicographic(last.program.constraints(), objectives);
264
+ const solved = solveLexicographic(last.program.constraints(), objectives, { warm: true });
265
265
  if (solved.status !== "optimal") throw new Error("The last program of the best endurance has no optimum. The point of the last step is a point of it.");
266
266
  const withStore = new Set(layer.stores.map((store) => store.resource));
267
267
  for (const block of last.blocks) {
@@ -1580,7 +1580,7 @@ function minus(a, b) {
1580
1580
  };
1581
1581
  }
1582
1582
  /** This function compares two inputs for the rank: the sums of the levels in the order of the levels, the largest first, then the key. */
1583
- function rankOrder(levels) {
1583
+ function rankOrder$1(levels) {
1584
1584
  return (a, b) => {
1585
1585
  for (const level of levels) {
1586
1586
  const diff = (b.levels[level] ?? 0) - (a.levels[level] ?? 0);
@@ -1663,7 +1663,7 @@ function enduranceSensitivity(layer, caseCuts, options) {
1663
1663
  levels: Object.fromEntries(sums)
1664
1664
  };
1665
1665
  });
1666
- inputs.sort(rankOrder(layer.levels));
1666
+ inputs.sort(rankOrder$1(layer.levels));
1667
1667
  return {
1668
1668
  case: caseCuts.case,
1669
1669
  at: options.at,
@@ -1672,6 +1672,104 @@ function enduranceSensitivity(layer, caseCuts, options) {
1672
1672
  inputs
1673
1673
  };
1674
1674
  }
1675
- export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SENSITIVITY_STEP, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, drawDemand, enduranceOf, enduranceSensitivity, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, isSource, joinEndurance, jointDays, longestStop, minimalStops, monthEdges, monthOf, monthlyShares, seasonSupply, shareOf, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
1675
+ // src/buy.ts
1676
+ /** This function gives the days of each level for one unit of an input, in the order of the levels. */
1677
+ function perUnitOf(input, levels) {
1678
+ const size = Math.abs(input.delta);
1679
+ return Object.fromEntries(levels.map((level) => [level, (input.levels[level] ?? 0) / size]));
1680
+ }
1681
+ /** This function compares two inputs with a price. It compares the days for one unit of money of each level in order, the largest first, then the key. */
1682
+ function rankOrder(levels) {
1683
+ return (a, b) => {
1684
+ for (const level of levels) {
1685
+ const diff = (b.perDollar[level] ?? 0) - (a.perDollar[level] ?? 0);
1686
+ if (diff > 0) return 1;
1687
+ if (diff < 0) return -1;
1688
+ }
1689
+ return a.id < b.id ? -1 : a.id > b.id ? 1 : 0;
1690
+ };
1691
+ }
1692
+ /**
1693
+ * This function ranks the inputs of a sensitivity by the days that they add for one unit of money.
1694
+ * With the price of one unit of each input, the first input of the rank is the next buy.
1695
+ *
1696
+ * - The function reads the result of `enduranceSensitivity`. It does not calculate the days again.
1697
+ * - The days of an input for one unit are the sum of the changes of each level divided by the size of `delta`.
1698
+ * Thus a step of 2, or a half step of a low draw, gives the days of 1 unit.
1699
+ * - The days for one unit of money are the days for one unit divided by the price of one unit.
1700
+ * - The rank is by level, as the rank of the sensitivity. It compares the days for one unit of money of the first level,
1701
+ * then of the next level, and so on. The largest value comes first. Two equal inputs go in the order of their keys.
1702
+ * - Thus an input that adds days to a higher level comes before each input that adds days only to lower levels. A buy
1703
+ * for a lower level does not go before a buy for a higher level, also when it gives more days for its money.
1704
+ * - An input with a change of 0 days has 0 days for one unit of money. It stays in the rank, after each input that adds
1705
+ * days at its level.
1706
+ * - An input with no price in the table has no rank. It goes in `unpriced` with the reason `no-price`. It does not get a price of 0.
1707
+ * - A price that is not a finite number more than 0 is a bad price. The input goes in `unpriced` with the reason
1708
+ * `bad-price`. The function does not throw, so one bad price of a live table does not stop the rank of the others.
1709
+ * A lower draw costs nothing, but the table gives it a price only when a buy lowers it.
1710
+ * - `unused` names each key of the table that is not the key of an input.
1711
+ *
1712
+ * The function is pure.
1713
+ *
1714
+ * @param sensitivity - The result of `enduranceSensitivity`
1715
+ * @param prices - The price of one unit of each input, by the key of the input
1716
+ * @param options - The levels of the layer, the most important first
1717
+ * @returns The inputs with a price in the order of the rank, the inputs with no rank, and the keys that are not used
1718
+ */
1719
+ function daysPerDollar(sensitivity, prices, options) {
1720
+ const { levels } = options;
1721
+ const ranked = [];
1722
+ const unpriced = [];
1723
+ const ids = /* @__PURE__ */ new Set();
1724
+ for (const input of sensitivity.inputs) {
1725
+ ids.add(input.id);
1726
+ const { id, kind, target, field } = input;
1727
+ const perUnit = perUnitOf(input, levels);
1728
+ const price = Object.hasOwn(prices.prices, id) ? prices.prices[id] : void 0;
1729
+ if (price === void 0) {
1730
+ unpriced.push({
1731
+ id,
1732
+ kind,
1733
+ target,
1734
+ field,
1735
+ perUnit,
1736
+ reason: "no-price"
1737
+ });
1738
+ continue;
1739
+ }
1740
+ if (!(price > 0) || !Number.isFinite(price)) {
1741
+ unpriced.push({
1742
+ id,
1743
+ kind,
1744
+ target,
1745
+ field,
1746
+ perUnit,
1747
+ reason: "bad-price"
1748
+ });
1749
+ continue;
1750
+ }
1751
+ const perDollar = Object.fromEntries(levels.map((level) => [level, (perUnit[level] ?? 0) / price]));
1752
+ ranked.push({
1753
+ id,
1754
+ kind,
1755
+ target,
1756
+ field,
1757
+ price,
1758
+ perUnit,
1759
+ perDollar
1760
+ });
1761
+ }
1762
+ ranked.sort(rankOrder(levels));
1763
+ const unused = Object.keys(prices.prices).filter((key) => !ids.has(key)).sort();
1764
+ return {
1765
+ case: sensitivity.case,
1766
+ at: sensitivity.at,
1767
+ currency: prices.currency,
1768
+ ranked,
1769
+ unpriced,
1770
+ unused
1771
+ };
1772
+ }
1773
+ export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SENSITIVITY_STEP, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, daysPerDollar, drawDemand, enduranceOf, enduranceSensitivity, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, isSource, joinEndurance, jointDays, longestStop, minimalStops, monthEdges, monthOf, monthlyShares, seasonSupply, shareOf, sowDays, stopCurves, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
1676
1774
 
1677
1775
  //# sourceMappingURL=index.js.map