@mark1russell7/stack-endurance 0.8.36 → 0.8.38

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.
@@ -52,7 +52,7 @@ function shareOf(shares, key, month) {
52
52
  }
53
53
  // src/check.ts
54
54
  /**
55
- * These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.
55
+ * These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way`, `endurance-cut-no-curve` and `endurance-store-unused`, which are warnings.
56
56
  *
57
57
  * - `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.
58
58
  * 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.
@@ -83,6 +83,8 @@ function shareOf(shares, key, month) {
83
83
  * - `endurance-capacity`: the capacity of a store is not a finite number more than 0, or it is less than the amount.
84
84
  * Or a store with a capacity has a due date. Or a resource has a store with a capacity and a store with no capacity.
85
85
  * Since 0.8.21 (M2-solar-charge).
86
+ * - `endurance-store-unused` (warning): no direct use and no converter takes the resource of a store, so its amount adds no day.
87
+ * One fault names each such resource, at the resource. Since 0.8.37.
86
88
  */
87
89
  const ENDURANCE_CODES = [
88
90
  "endurance-twice",
@@ -102,7 +104,8 @@ const ENDURANCE_CODES = [
102
104
  "endurance-cut-no-curve",
103
105
  "endurance-season",
104
106
  "endurance-monthly",
105
- "endurance-capacity"
107
+ "endurance-capacity",
108
+ "endurance-store-unused"
106
109
  ];
107
110
  /**
108
111
  * 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.
@@ -178,6 +181,8 @@ function checkEndurance(layer, stack) {
178
181
  part(draw.need, "supply", draw.supply);
179
182
  if (!(direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need))) add("warning", "endurance-no-way", draw.need, `The draw "${draw.need}" has no direct use and no converter. It holds 0 days when its supply stops.`);
180
183
  }
184
+ const taken = /* @__PURE__ */ new Set([...direct.map((use) => use.resource), ...converters.flatMap((converter) => converter.takes.map((input) => input.resource))]);
185
+ for (const code of new Set(layer.stores.map((store) => store.resource))) if (!taken.has(code)) add("warning", "endurance-store-unused", code, `No direct use and no converter takes the resource "${code}" of a store. Its amount adds no day.`);
181
186
  for (const use of direct) {
182
187
  const at = `${use.resource}>${use.need}`;
183
188
  resource(at, use.resource);
@@ -383,4 +388,4 @@ function joinEndurance(pieces) {
383
388
  }
384
389
  export { hasEnduranceError as a, giftNeed as c, isSource as d, monthlyShares as f, curveFault as i, giftResource as l, ENDURANCE_CODES as n, canRun as o, shareOf as p, checkEndurance as r, deviceKey as s, joinEndurance as t, inputsOf as u };
385
390
 
386
- //# sourceMappingURL=join-CsR-FKzr.js.map
391
+ //# sourceMappingURL=join-DwYqzX7_.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join-DwYqzX7_.js","names":["curveFault"],"sources":["../src/converter.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import type { Converter } from \"./layer.ts\";\n\n// The internal rules of a converter that the endurance query and the joint days share. The root entry does not give them.\n\n/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */\nexport function inputsOf(converter: Converter): Map<string, number> {\n const out = new Map<string, number>();\n for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);\n return out;\n}\n\n/**\n * This function tells if a converter is a source (M2-solar): it takes nothing, and it has a limit `perDay` more than 0.\n * Its runs of a day are lost when no draw uses them. Thus a take uses a source before a store.\n */\nexport function isSource(converter: Converter): boolean {\n if (!(converter.perDay !== undefined && converter.perDay > 0)) return false;\n // The same test as `inputsOf(converter).size === 0`, with no map: the take loops call it.\n for (const input of converter.takes) if (input.amount > 0) return false;\n return true;\n}\n\n/**\n * This function tells if a converter can run in a case. Its device works, it takes a resource or it is a source, and it\n * gives an amount more than 0.\n */\nexport function canRun(converter: Converter, stoppedParts: ReadonlySet<string>): boolean {\n return converter.gives.amount > 0 && (inputsOf(converter).size > 0 || isSource(converter)) && (converter.device === undefined || !stoppedParts.has(converter.device));\n}\n\n/**\n * This function gives the key of the device-days that a converter uses. The converters of one device share one key.\n * A converter with no device has a key of its own.\n */\nexport function deviceKey(converter: Converter): string {\n return converter.device === undefined ? `converter:${converter.id}` : `device:${converter.device}`;\n}\n\n/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */\nexport function giftNeed(converter: Converter): string | undefined {\n return \"need\" in converter.gives ? converter.gives.need : undefined;\n}\n\n/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */\nexport function giftResource(converter: Converter): string | undefined {\n return \"resource\" in converter.gives ? converter.gives.resource : undefined;\n}\n\n/** This function gives the shares `monthly` of each device key of the converters with a limit and shares (M2-solar). */\nexport function monthlyShares(converters: Iterable<Converter>): Map<string, readonly number[]> {\n const out = new Map<string, readonly number[]>();\n for (const converter of converters) if (converter.monthly !== undefined && converter.perDay !== undefined) out.set(deviceKey(converter), converter.monthly);\n return out;\n}\n\n/** This function gives the share of the device-days of a key in a month: its share `monthly`, or 1. */\nexport function shareOf(shares: ReadonlyMap<string, readonly number[]>, key: string, month: number): number {\n return shares.get(key)?.[month] ?? 1;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { bandFault, countsFault, CUT_BOUNDS, curveFault, dayNumber, intervalFault, isCutBound, sumsFault, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./converter.ts\";\nimport type { Converter, EnduranceLayer } from \"./layer.ts\";\n\n// The gate of an endurance layer: the meaning of a layer with a correct form, for its base stack.\n\n/**\n * These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way`, `endurance-cut-no-curve` and `endurance-store-unused`, which are warnings.\n *\n * - `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.\n * 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.\n * - `endurance-level-unknown`: the level of a draw is not a level of the layer.\n * - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.\n * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.\n * - `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.\n * - `endurance-date`: a date is not a date `YYYY-MM-DD`.\n * - `endurance-converter-empty`: a converter takes nothing and has no limit `perDay` more than 0, or it gives an amount of 0.\n * A converter with a limit can take nothing: it is a source, for example a solar panel. Since 0.8.20 (M2-solar).\n * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.\n * Or its days do not increase, or its chance increases.\n * Or the band, the counts or the sums of a cut do not agree with its curve (`bandFault`, `countsFault`, `sumsFault`).\n * Or the cut has them and no curve.\n * - `endurance-bound`: the bound of a cut is not a value of `CUT_BOUNDS` of the core. Since 0.8.4.\n * - `endurance-prior-case`: a prior names a case that the layer does not have.\n * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.\n * - `endurance-devices`: two converters of one device give two different counts of devices.\n * - `endurance-device-mix` (warning): a device has a converter with a limit `perDay` and a converter with no limit. The\n * converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.\n * - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.\n * - `endurance-cut-no-curve` (warning): a cut has no curve of its duration. The draws whose stop it can be part of are no read in the shortfall.\n * - `endurance-season`: the season of a converter has a day that is not `MM-DD`. Or its delay or its shelf life is not more than 0.\n * Or its count of sowings is not a finite number of 0 or more. Or the converter with a season gives a need, or it has\n * `perDay` or `devices`. Since 0.8.16 (M2-grow).\n * - `endurance-monthly`: the shares `monthly` of a converter are not 12 numbers from 0 to 1. Or the converter has\n * `monthly` and no `perDay`, or a season. Or two converters of one device have different shares. Since 0.8.20 (M2-solar).\n * - `endurance-capacity`: the capacity of a store is not a finite number more than 0, or it is less than the amount.\n * Or a store with a capacity has a due date. Or a resource has a store with a capacity and a store with no capacity.\n * Since 0.8.21 (M2-solar-charge).\n * - `endurance-store-unused` (warning): no direct use and no converter takes the resource of a store, so its amount adds no day.\n * One fault names each such resource, at the resource. Since 0.8.37.\n */\nexport const ENDURANCE_CODES: readonly [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-bound\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n \"endurance-season\",\n \"endurance-monthly\",\n \"endurance-capacity\",\n \"endurance-store-unused\",\n] = [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-bound\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n \"endurance-season\",\n \"endurance-monthly\",\n \"endurance-capacity\",\n \"endurance-store-unused\",\n];\n\n/** A code of `ENDURANCE_CODES`. */\nexport type EnduranceCode = (typeof ENDURANCE_CODES)[number];\n\n/** A fault of the gate of an endurance layer. */\nexport interface EnduranceFault extends Fault {\n readonly code: EnduranceCode;\n}\n\nexport { curveFault } from \"@mark1russell7/system-stack\";\n\n/**\n * 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.\n *\n * The faults are in the order of the layer. The function is pure.\n *\n * @param layer - The endurance layer\n * @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.\n * @returns The faults\n */\nexport function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[] {\n const faults: EnduranceFault[] = [];\n const add = (level: EnduranceFault[\"level\"], code: EnduranceCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const once = (what: string, keys: readonly string[]): void => {\n const seen = new Set<string>();\n for (const key of keys) {\n if (seen.has(key)) add(\"error\", \"endurance-twice\", key, `Two or more ${what} have the key \"${key}\".`);\n seen.add(key);\n }\n };\n const range = (at: string, what: string, value: number): void => {\n if (!(Number.isFinite(value) && value >= 0)) add(\"error\", \"endurance-range\", at, `The ${what} of \"${at}\" is ${String(value)}. It must be a finite number of 0 or more.`);\n };\n const date = (at: string, value: string): void => {\n if (dayNumber(value) === undefined) add(\"error\", \"endurance-date\", at, `The date \"${value}\" of \"${at}\" is not a date YYYY-MM-DD.`);\n };\n const parts = stack === undefined ? undefined : new Set(stack.parts.map((part) => part.id));\n const part = (at: string, what: string, id: string | undefined): void => {\n if (parts !== undefined && id !== undefined && !parts.has(id)) add(\"error\", \"endurance-part-unknown\", at, `The ${what} \"${id}\" of \"${at}\" is not a part of the stack.`);\n };\n const resources = new Set(layer.resources.map((resource) => resource.code));\n const resource = (at: string, code: string): void => {\n if (!resources.has(code)) add(\"error\", \"endurance-resource-unknown\", at, `The resource \"${code}\" of \"${at}\" is not a resource of the layer.`);\n };\n const direct = layer.direct ?? [];\n const converters = layer.converters ?? [];\n const cases = layer.cases ?? [];\n const priors = layer.priors ?? [];\n\n once(\"levels\", layer.levels);\n once(\"resources\", layer.resources.map((item) => item.code));\n once(\"stores\", layer.stores.map((store) => store.id));\n once(\"draws\", layer.draws.map((draw) => draw.need));\n once(\"converters\", converters.map((converter) => converter.id));\n once(\"cases\", cases.map((item) => item.case));\n once(\"priors\", priors.map((prior) => `${prior.case}@${prior.place}`));\n\n for (const store of layer.stores) {\n resource(store.id, store.resource);\n range(store.id, \"amount\", store.amount);\n if (store.due !== undefined) date(store.id, store.due);\n part(store.id, \"part\", store.part);\n if (store.capacity !== undefined) {\n if (!(Number.isFinite(store.capacity) && store.capacity > 0 && store.capacity >= store.amount)) {\n add(\"error\", \"endurance-capacity\", store.id, `The capacity of \"${store.id}\" is ${String(store.capacity)}. It must be a finite number more than 0, and not less than the amount.`);\n }\n if (store.due !== undefined) add(\"error\", \"endurance-capacity\", store.id, `The store \"${store.id}\" has a capacity and a due date. A store with a charge has no due date.`);\n }\n }\n for (const code of new Set(layer.stores.map((store) => store.resource))) {\n const all = layer.stores.filter((store) => store.resource === code);\n const charged = all.filter((store) => store.capacity !== undefined);\n if (charged.length > 0 && charged.length < all.length) {\n add(\"error\", \"endurance-capacity\", code, `The resource \"${code}\" has a store with a capacity and a store with no capacity. Its stores all have a capacity, or none has one.`);\n }\n }\n const levels = new Set(layer.levels);\n for (const draw of layer.draws) {\n if (!levels.has(draw.level)) add(\"error\", \"endurance-level-unknown\", draw.need, `The level \"${draw.level}\" of the draw \"${draw.need}\" is not a level of the layer.`);\n range(draw.need, \"rate\", draw.perDay);\n if (draw.users !== undefined) range(draw.need, \"count of users\", draw.users);\n part(draw.need, \"supply\", draw.supply);\n const ways = direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need);\n if (!ways) add(\"warning\", \"endurance-no-way\", draw.need, `The draw \"${draw.need}\" has no direct use and no converter. It holds 0 days when its supply stops.`);\n }\n // One fault names each resource with a store that no direct use and no converter takes.\n const taken = new Set([...direct.map((use) => use.resource), ...converters.flatMap((converter) => converter.takes.map((input) => input.resource))]);\n for (const code of new Set(layer.stores.map((store) => store.resource))) {\n if (!taken.has(code)) add(\"warning\", \"endurance-store-unused\", code, `No direct use and no converter takes the resource \"${code}\" of a store. Its amount adds no day.`);\n }\n for (const use of direct) {\n const at = `${use.resource}>${use.need}`;\n resource(at, use.resource);\n range(at, \"amount\", use.amount);\n }\n for (const converter of converters) {\n once(`resources of the converter \"${converter.id}\"`, converter.takes.map((input) => input.resource));\n for (const input of converter.takes) {\n resource(converter.id, input.resource);\n range(converter.id, \"amount\", input.amount);\n }\n range(converter.id, \"amount\", converter.gives.amount);\n const made = giftResource(converter);\n if (made !== undefined) resource(converter.id, made);\n const source = converter.perDay !== undefined && converter.perDay > 0;\n if ((!source && !converter.takes.some((input) => input.amount > 0)) || converter.gives.amount === 0) add(\"error\", \"endurance-converter-empty\", converter.id, `The converter \"${converter.id}\" takes nothing, or it gives nothing.`);\n part(converter.id, \"device\", converter.device);\n if (converter.perDay !== undefined) range(converter.id, \"rate perDay\", converter.perDay);\n if (converter.devices !== undefined && !(Number.isSafeInteger(converter.devices) && converter.devices >= 1))\n add(\"error\", \"endurance-range\", converter.id, `The count of devices of \"${converter.id}\" is ${String(converter.devices)}. It must be a whole number of 1 or more.`);\n if (converter.season !== undefined) for (const message of seasonFaults(converter)) add(\"error\", \"endurance-season\", converter.id, message);\n for (const message of monthlyFaults(converter)) add(\"error\", \"endurance-monthly\", converter.id, message);\n }\n const shares = new Map<string, Converter>();\n for (const converter of converters) {\n if (converter.device === undefined || converter.perDay === undefined) continue;\n const seen = shares.get(converter.device);\n if (seen === undefined) shares.set(converter.device, converter);\n else if (!sameShares(seen.monthly, converter.monthly))\n add(\"error\", \"endurance-monthly\", converter.id, `The converter \"${converter.id}\" and the converter \"${seen.id}\" of the device \"${converter.device}\" have different shares monthly. The converters of one device have the same shares.`);\n }\n const counts = new Map<string, number>();\n for (const converter of converters) {\n if (converter.device === undefined) continue;\n const count = converter.devices ?? 1;\n const seen = counts.get(converter.device);\n if (seen !== undefined && seen !== count)\n add(\"error\", \"endurance-devices\", converter.id, `The converter \"${converter.id}\" gives the count ${String(count)} for the device \"${converter.device}\". An other converter gives the count ${String(seen)}.`);\n if (seen === undefined) counts.set(converter.device, count);\n }\n // One fault names each device with a limited converter and a converter with no limit, at the first converter with no limit.\n const mixed = new Set<string>();\n for (const converter of converters) {\n const device = converter.device;\n if (device === undefined || converter.perDay !== undefined || mixed.has(device)) continue;\n const limited = converters.find((other) => other.device === device && other.perDay !== undefined);\n if (limited === undefined) continue;\n mixed.add(device);\n add(\"warning\", \"endurance-device-mix\", converter.id, `The device \"${device}\" has the limited converter \"${limited.id}\" and the converter \"${converter.id}\" with no limit. \"${converter.id}\" uses no device-days.`);\n }\n const caseCodes = new Set(cases.map((item) => item.case));\n for (const item of cases) {\n once(`cuts of the case \"${item.case}\"`, item.cuts.map((cut) => cut.part));\n for (const cut of item.cuts) {\n const at = `${item.case}/${cut.part}`;\n part(at, \"cut\", cut.part);\n if (cut.bound !== undefined && !isCutBound(cut.bound))\n add(\"error\", \"endurance-bound\", at, `The bound of the cut \"${at}\" is ${JSON.stringify(cut.bound)}. It must be one of ${CUT_BOUNDS.join(\", \")}.`);\n if (cut.duration === undefined) {\n add(\"warning\", \"endurance-cut-no-curve\", at, `The cut \"${at}\" has no curve of its duration, so the draws that it can stop are no read.`);\n if (cut.band !== undefined) add(\"error\", \"endurance-curve\", at, `The cut \"${at}\" has a band and no curve of its duration.`);\n if (cut.counts !== undefined) add(\"error\", \"endurance-curve\", at, `The cut \"${at}\" has counts and no curve of its duration.`);\n if (cut.sums !== undefined) add(\"error\", \"endurance-curve\", at, `The cut \"${at}\" has sums and no curve of its duration.`);\n continue;\n }\n const fault = curveFault(cut.duration);\n if (fault !== undefined) add(\"error\", \"endurance-curve\", at, `The duration of the cut \"${at}\": ${fault}`);\n const band = cut.band === undefined || fault !== undefined ? undefined : bandFault(cut.duration, cut.band);\n if (band !== undefined) add(\"error\", \"endurance-curve\", at, `The band of the cut \"${at}\": ${band}`);\n const counts = cut.counts === undefined || fault !== undefined ? undefined : countsFault(cut.duration, cut.counts);\n if (counts !== undefined) add(\"error\", \"endurance-curve\", at, `The counts of the cut \"${at}\": ${counts}`);\n const sums = cut.sums === undefined || fault !== undefined ? undefined : sumsFault(cut.duration, cut.sums);\n if (sums !== undefined) add(\"error\", \"endurance-curve\", at, `The sums of the cut \"${at}\": ${sums}`);\n }\n for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, \"factor\", factor);\n if (item.leadSeconds !== undefined) range(item.case, \"lead time\", item.leadSeconds);\n }\n for (const cycle of resourceCycles(converters)) {\n const [first = \"\"] = cycle;\n const names = cycle.map((code) => `\"${code}\"`).join(\", \");\n const message = cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`;\n add(\"error\", \"endurance-cycle\", first, `${message} A chain of converters cannot end.`);\n }\n for (const prior of priors) {\n const at = `${prior.case}@${prior.place}`;\n if (!caseCodes.has(prior.case)) add(\"error\", \"endurance-prior-case\", at, `The prior \"${at}\" names the case \"${prior.case}\", which the layer does not have.`);\n range(at, \"count of events in one year\", prior.perYear);\n if (!(prior.reach >= 0 && prior.reach <= 1)) add(\"error\", \"endurance-range\", at, `The reach of \"${at}\" is ${String(prior.reach)}. It must be from 0 to 1.`);\n date(at, prior.asOf);\n const fault = prior.interval === undefined ? undefined : intervalFault(prior.interval);\n if (fault !== undefined) add(\"error\", \"endurance-range\", at, `The interval of the count of events in one year of \"${at}\" is not valid. ${fault}`);\n }\n return faults;\n}\n\n/** This function tells if a text is a day `MM-DD` of a leap year. */\nfunction isMonthDay(value: string): boolean {\n return /^\\d{2}-\\d{2}$/.test(value) && dayNumber(`2000-${value}`) !== undefined;\n}\n\n/** This function gives the messages of the faults of the season of a converter. */\nfunction seasonFaults(converter: Converter): string[] {\n const season = converter.season;\n if (season === undefined) return [];\n const out: string[] = [];\n for (const day of [season.from, season.to]) if (!isMonthDay(day)) out.push(`The season of \"${converter.id}\" has the day \"${day}\". It is not a day MM-DD.`);\n if (!(Number.isFinite(season.delayDays) && season.delayDays > 0)) out.push(`The delay of the season of \"${converter.id}\" is ${String(season.delayDays)}. It must be a finite number of days more than 0.`);\n if (season.shelfDays !== undefined && !(Number.isFinite(season.shelfDays) && season.shelfDays > 0)) out.push(`The shelf life of the season of \"${converter.id}\" is ${String(season.shelfDays)}. It must be a finite number of days more than 0.`);\n if (!(Number.isFinite(season.runs) && season.runs >= 0)) out.push(`The runs of the season of \"${converter.id}\" are ${String(season.runs)}. They must be a finite number of 0 or more.`);\n if (giftResource(converter) === undefined) out.push(`The converter \"${converter.id}\" has a season and gives a need. A converter with a season gives a resource.`);\n if (converter.perDay !== undefined || converter.devices !== undefined) out.push(`The converter \"${converter.id}\" has a season and a limit perDay or devices. A converter with a season has no such limit.`);\n return out;\n}\n\n/** This function gives the messages of the faults of the shares `monthly` of a converter (M2-solar). */\nfunction monthlyFaults(converter: Converter): string[] {\n const monthly = converter.monthly;\n if (monthly === undefined) return [];\n const out: string[] = [];\n if (monthly.length !== 12 || !monthly.every((share) => Number.isFinite(share) && share >= 0 && share <= 1))\n out.push(`The shares monthly of \"${converter.id}\" are not 12 numbers from 0 to 1.`);\n if (converter.perDay === undefined) out.push(`The converter \"${converter.id}\" has shares monthly and no limit perDay. The shares are parts of the limit.`);\n if (converter.season !== undefined) out.push(`The converter \"${converter.id}\" has shares monthly and a season. A converter has one or the other.`);\n return out;\n}\n\n/** This function tells if two lists of shares `monthly` are equal. No list is equal to a list of 12 ones. */\nfunction sameShares(a: readonly number[] | undefined, b: readonly number[] | undefined): boolean {\n const full = (shares: readonly number[] | undefined): readonly number[] => shares ?? Array.from({ length: 12 }, () => 1);\n const left = full(a);\n const right = full(b);\n return left.length === right.length && left.every((share, index) => share === right[index]);\n}\n\n/**\n * This function gives each cycle of resources: a resource is made from a resource that a converter makes from it. Each cycle is a list of codes.\n * A converter with a season is not part of a cycle: its harvest comes after its sowing, thus a chain of it ends.\n */\nfunction resourceCycles(converters: readonly Converter[]): string[][] {\n const from = new Map<string, Set<string>>();\n for (const converter of converters) {\n const made = giftResource(converter);\n if (made === undefined || converter.season !== undefined) continue;\n const inputs = from.get(made) ?? new Set<string>();\n for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);\n from.set(made, inputs);\n }\n const successors = (code: string): Iterable<string> => from.get(code) ?? [];\n return stronglyConnectedComponents(from.keys(), successors).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (from.get(only)?.has(only) ?? false);\n });\n}\n\n/** This function tells if a list of faults has an error. */\nexport function hasEnduranceError(faults: readonly EnduranceFault[]): boolean {\n return faults.some((fault) => fault.level === \"error\");\n}\n","import { canonicalJson } from \"@mark1russell7/rigor-generators\";\nimport { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The join of the endurance layers of the fragments of a stack, for example one file of stores for each owner.\n\n/**\n * This function joins the endurance layers of the fragments of a stack into one layer.\n *\n * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.\n * - The records of each list are in the order of the fragments.\n * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.\n * Its message gives the canonical JSON of the record of each fragment.\n * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.\n * - One key of each other list in two or more fragments is a fault, also when the records are equal.\n * - The key of a direct use is its resource and its need.\n *\n * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer> {\n const levels = joinSetting(pieces, (layer) => (layer.levels.length > 0 ? layer.levels.join(\"\\n\") : undefined), \"levels\");\n // Two fragments can declare one resource, for example `water.stored` in `L`. Canonical JSON (RFC 8785) compares the records,\n // so the order of the keys has no effect. The message of a fault gives the canonical JSON of the record of each fragment.\n const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\", {\n equal: (first, other) => canonicalJson(first) === canonicalJson(other),\n text: canonicalJson,\n });\n const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, \"store\");\n const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, \"draw\");\n const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, \"direct use\");\n const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, \"converter\");\n const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, \"case\");\n const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, \"prior\");\n const errors = [levels, resources, stores, draws, direct, converters, cases, priors].flatMap((join) => join.errors);\n if (errors.length > 0) return { ok: false, errors };\n const has = (key: \"direct\" | \"converters\" | \"cases\" | \"priors\"): boolean => pieces.some((piece) => piece.layer[key] !== undefined);\n return {\n ok: true,\n layer: {\n schema: ENDURANCE_SCHEMA,\n levels: levels.value === undefined ? [] : levels.value.split(\"\\n\"),\n resources: resources.items,\n stores: stores.items,\n draws: draws.items,\n ...(has(\"direct\") ? { direct: direct.items } : {}),\n ...(has(\"converters\") ? { converters: converters.items } : {}),\n ...(has(\"cases\") ? { cases: cases.items } : {}),\n ...(has(\"priors\") ? { priors: priors.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;;AAKA,SAAgB,SAAS,WAA2C;CAClE,MAAM,sBAAM,IAAI,IAAoB;CACpC,KAAK,MAAM,SAAS,UAAU,OAAO,IAAI,MAAM,SAAS,GAAG,IAAI,IAAI,MAAM,WAAW,IAAI,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM;CAChI,OAAO;AACT;;;;;AAMA,SAAgB,SAAS,WAA+B;CACtD,IAAI,EAAE,UAAU,WAAW,KAAA,KAAa,UAAU,SAAS,IAAI,OAAO;CAEtE,KAAK,MAAM,SAAS,UAAU,OAAO,IAAI,MAAM,SAAS,GAAG,OAAO;CAClE,OAAO;AACT;;;;;AAMA,SAAgB,OAAO,WAAsB,cAA4C;CACvF,OAAO,UAAU,MAAM,SAAS,MAAM,SAAS,SAAS,CAAC,CAAC,OAAO,KAAK,SAAS,SAAS,OAAO,UAAU,WAAW,KAAA,KAAa,CAAC,aAAa,IAAI,UAAU,MAAM;AACrK;;;;;AAMA,SAAgB,UAAU,WAA8B;CACtD,OAAO,UAAU,WAAW,KAAA,IAAY,aAAa,UAAU,OAAO,UAAU,UAAU;AAC5F;;AAGA,SAAgB,SAAS,WAA0C;CACjE,OAAO,UAAU,UAAU,QAAQ,UAAU,MAAM,OAAO,KA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G,KAAK,SAAS,OAAO;CAC3G,MAAM,SAAS;EAAC;EAAQ;EAAW;EAAQ;EAAO;EAAQ;EAAY;EAAO;CAAM,CAAC,CAAC,SAAS,SAAS,KAAK,MAAM;CAClH,IAAI,OAAO,SAAS,GAAG,OAAO;EAAE,IAAI;EAAO;CAAO;CAClD,MAAM,OAAO,QAA+D,OAAO,MAAM,UAAU,MAAM,MAAM,SAAS,KAAA,CAAS;CACjI,OAAO;EACL,IAAI;EACJ,OAAO;GACL,QAAQ;GACR,QAAQ,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,OAAO,MAAM,MAAM,IAAI;GACjE,WAAW,UAAU;GACrB,QAAQ,OAAO;GACf,OAAO,MAAM;GACb,GAAI,IAAI,QAAQ,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;GAChD,GAAI,IAAI,YAAY,IAAI,EAAE,YAAY,WAAW,MAAM,IAAI,CAAC;GAC5D,GAAI,IAAI,OAAO,IAAI,EAAE,OAAO,MAAM,MAAM,IAAI,CAAC;GAC7C,GAAI,IAAI,QAAQ,IAAI,EAAE,QAAQ,OAAO,MAAM,IAAI,CAAC;EAClD;CACF;AACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/stack-endurance",
4
- "version": "0.8.36",
4
+ "version": "0.8.38",
5
5
  "description": "Stores, draws and converters of a system stack: the days that each draw holds when a case cuts its supply, and the shortfall of each level in one year. An add-on of system-stack.",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "@mark1russell7/linear": "^0.1.3",
54
54
  "@mark1russell7/rational": "^0.1.3",
55
55
  "@mark1russell7/rigor-generators": "^0.2.4",
56
- "@mark1russell7/rigor-statistics": "^0.2.41",
56
+ "@mark1russell7/rigor-statistics": "^0.2.42",
57
57
  "@mark1russell7/system-stack": "0.1.21",
58
58
  "zod": "^4.6.7"
59
59
  },
@@ -1 +0,0 @@
1
- {"version":3,"file":"join-CsR-FKzr.js","names":["curveFault"],"sources":["../src/converter.ts","../src/check.ts","../src/join.ts"],"sourcesContent":["import type { Converter } from \"./layer.ts\";\n\n// The internal rules of a converter that the endurance query and the joint days share. The root entry does not give them.\n\n/** This function gives the amount of each resource that one run of a converter takes. Two lines of one resource add. */\nexport function inputsOf(converter: Converter): Map<string, number> {\n const out = new Map<string, number>();\n for (const input of converter.takes) if (input.amount > 0) out.set(input.resource, (out.get(input.resource) ?? 0) + input.amount);\n return out;\n}\n\n/**\n * This function tells if a converter is a source (M2-solar): it takes nothing, and it has a limit `perDay` more than 0.\n * Its runs of a day are lost when no draw uses them. Thus a take uses a source before a store.\n */\nexport function isSource(converter: Converter): boolean {\n if (!(converter.perDay !== undefined && converter.perDay > 0)) return false;\n // The same test as `inputsOf(converter).size === 0`, with no map: the take loops call it.\n for (const input of converter.takes) if (input.amount > 0) return false;\n return true;\n}\n\n/**\n * This function tells if a converter can run in a case. Its device works, it takes a resource or it is a source, and it\n * gives an amount more than 0.\n */\nexport function canRun(converter: Converter, stoppedParts: ReadonlySet<string>): boolean {\n return converter.gives.amount > 0 && (inputsOf(converter).size > 0 || isSource(converter)) && (converter.device === undefined || !stoppedParts.has(converter.device));\n}\n\n/**\n * This function gives the key of the device-days that a converter uses. The converters of one device share one key.\n * A converter with no device has a key of its own.\n */\nexport function deviceKey(converter: Converter): string {\n return converter.device === undefined ? `converter:${converter.id}` : `device:${converter.device}`;\n}\n\n/** This function gives the need that a converter gives, or `undefined` when it gives a resource. */\nexport function giftNeed(converter: Converter): string | undefined {\n return \"need\" in converter.gives ? converter.gives.need : undefined;\n}\n\n/** This function gives the resource that a converter gives, or `undefined` when it gives a need. */\nexport function giftResource(converter: Converter): string | undefined {\n return \"resource\" in converter.gives ? converter.gives.resource : undefined;\n}\n\n/** This function gives the shares `monthly` of each device key of the converters with a limit and shares (M2-solar). */\nexport function monthlyShares(converters: Iterable<Converter>): Map<string, readonly number[]> {\n const out = new Map<string, readonly number[]>();\n for (const converter of converters) if (converter.monthly !== undefined && converter.perDay !== undefined) out.set(deviceKey(converter), converter.monthly);\n return out;\n}\n\n/** This function gives the share of the device-days of a key in a month: its share `monthly`, or 1. */\nexport function shareOf(shares: ReadonlyMap<string, readonly number[]>, key: string, month: number): number {\n return shares.get(key)?.[month] ?? 1;\n}\n","import { stronglyConnectedComponents } from \"@mark1russell7/collections/graph\";\nimport { bandFault, countsFault, CUT_BOUNDS, curveFault, dayNumber, intervalFault, isCutBound, sumsFault, type Fault, type Stack } from \"@mark1russell7/system-stack\";\nimport { giftNeed, giftResource } from \"./converter.ts\";\nimport type { Converter, EnduranceLayer } from \"./layer.ts\";\n\n// The gate of an endurance layer: the meaning of a layer with a correct form, for its base stack.\n\n/**\n * These are the codes of the gate. Each code is an error, except `endurance-device-mix`, `endurance-no-way` and `endurance-cut-no-curve`, which are warnings.\n *\n * - `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.\n * 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.\n * - `endurance-level-unknown`: the level of a draw is not a level of the layer.\n * - `endurance-resource-unknown`: a store, a use or a converter names a resource that the layer does not have.\n * - `endurance-part-unknown`: a supply, a device, the part of a store or a cut is not a part of the base stack.\n * - `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.\n * - `endurance-date`: a date is not a date `YYYY-MM-DD`.\n * - `endurance-converter-empty`: a converter takes nothing and has no limit `perDay` more than 0, or it gives an amount of 0.\n * A converter with a limit can take nothing: it is a source, for example a solar panel. Since 0.8.20 (M2-solar).\n * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.\n * Or its days do not increase, or its chance increases.\n * Or the band, the counts or the sums of a cut do not agree with its curve (`bandFault`, `countsFault`, `sumsFault`).\n * Or the cut has them and no curve.\n * - `endurance-bound`: the bound of a cut is not a value of `CUT_BOUNDS` of the core. Since 0.8.4.\n * - `endurance-prior-case`: a prior names a case that the layer does not have.\n * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.\n * - `endurance-devices`: two converters of one device give two different counts of devices.\n * - `endurance-device-mix` (warning): a device has a converter with a limit `perDay` and a converter with no limit. The\n * converter with no limit uses no device-days, so its runs do not reduce the runs of the limited converter.\n * - `endurance-no-way` (warning): a draw has no direct use and no converter, so it holds 0 days when its supply stops.\n * - `endurance-cut-no-curve` (warning): a cut has no curve of its duration. The draws whose stop it can be part of are no read in the shortfall.\n * - `endurance-season`: the season of a converter has a day that is not `MM-DD`. Or its delay or its shelf life is not more than 0.\n * Or its count of sowings is not a finite number of 0 or more. Or the converter with a season gives a need, or it has\n * `perDay` or `devices`. Since 0.8.16 (M2-grow).\n * - `endurance-monthly`: the shares `monthly` of a converter are not 12 numbers from 0 to 1. Or the converter has\n * `monthly` and no `perDay`, or a season. Or two converters of one device have different shares. Since 0.8.20 (M2-solar).\n * - `endurance-capacity`: the capacity of a store is not a finite number more than 0, or it is less than the amount.\n * Or a store with a capacity has a due date. Or a resource has a store with a capacity and a store with no capacity.\n * Since 0.8.21 (M2-solar-charge).\n */\nexport const ENDURANCE_CODES: readonly [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-bound\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n \"endurance-season\",\n \"endurance-monthly\",\n \"endurance-capacity\",\n] = [\n \"endurance-twice\",\n \"endurance-level-unknown\",\n \"endurance-resource-unknown\",\n \"endurance-part-unknown\",\n \"endurance-range\",\n \"endurance-date\",\n \"endurance-converter-empty\",\n \"endurance-curve\",\n \"endurance-bound\",\n \"endurance-prior-case\",\n \"endurance-cycle\",\n \"endurance-devices\",\n \"endurance-device-mix\",\n \"endurance-no-way\",\n \"endurance-cut-no-curve\",\n \"endurance-season\",\n \"endurance-monthly\",\n \"endurance-capacity\",\n];\n\n/** A code of `ENDURANCE_CODES`. */\nexport type EnduranceCode = (typeof ENDURANCE_CODES)[number];\n\n/** A fault of the gate of an endurance layer. */\nexport interface EnduranceFault extends Fault {\n readonly code: EnduranceCode;\n}\n\nexport { curveFault } from \"@mark1russell7/system-stack\";\n\n/**\n * 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.\n *\n * The faults are in the order of the layer. The function is pure.\n *\n * @param layer - The endurance layer\n * @param stack - The base stack, with the layer. With no stack, the gate does not examine the parts.\n * @returns The faults\n */\nexport function checkEndurance(layer: EnduranceLayer, stack?: Stack): EnduranceFault[] {\n const faults: EnduranceFault[] = [];\n const add = (level: EnduranceFault[\"level\"], code: EnduranceCode, at: string, message: string): void => {\n faults.push({ level, code, at, message });\n };\n const once = (what: string, keys: readonly string[]): void => {\n const seen = new Set<string>();\n for (const key of keys) {\n if (seen.has(key)) add(\"error\", \"endurance-twice\", key, `Two or more ${what} have the key \"${key}\".`);\n seen.add(key);\n }\n };\n const range = (at: string, what: string, value: number): void => {\n if (!(Number.isFinite(value) && value >= 0)) add(\"error\", \"endurance-range\", at, `The ${what} of \"${at}\" is ${String(value)}. It must be a finite number of 0 or more.`);\n };\n const date = (at: string, value: string): void => {\n if (dayNumber(value) === undefined) add(\"error\", \"endurance-date\", at, `The date \"${value}\" of \"${at}\" is not a date YYYY-MM-DD.`);\n };\n const parts = stack === undefined ? undefined : new Set(stack.parts.map((part) => part.id));\n const part = (at: string, what: string, id: string | undefined): void => {\n if (parts !== undefined && id !== undefined && !parts.has(id)) add(\"error\", \"endurance-part-unknown\", at, `The ${what} \"${id}\" of \"${at}\" is not a part of the stack.`);\n };\n const resources = new Set(layer.resources.map((resource) => resource.code));\n const resource = (at: string, code: string): void => {\n if (!resources.has(code)) add(\"error\", \"endurance-resource-unknown\", at, `The resource \"${code}\" of \"${at}\" is not a resource of the layer.`);\n };\n const direct = layer.direct ?? [];\n const converters = layer.converters ?? [];\n const cases = layer.cases ?? [];\n const priors = layer.priors ?? [];\n\n once(\"levels\", layer.levels);\n once(\"resources\", layer.resources.map((item) => item.code));\n once(\"stores\", layer.stores.map((store) => store.id));\n once(\"draws\", layer.draws.map((draw) => draw.need));\n once(\"converters\", converters.map((converter) => converter.id));\n once(\"cases\", cases.map((item) => item.case));\n once(\"priors\", priors.map((prior) => `${prior.case}@${prior.place}`));\n\n for (const store of layer.stores) {\n resource(store.id, store.resource);\n range(store.id, \"amount\", store.amount);\n if (store.due !== undefined) date(store.id, store.due);\n part(store.id, \"part\", store.part);\n if (store.capacity !== undefined) {\n if (!(Number.isFinite(store.capacity) && store.capacity > 0 && store.capacity >= store.amount)) {\n add(\"error\", \"endurance-capacity\", store.id, `The capacity of \"${store.id}\" is ${String(store.capacity)}. It must be a finite number more than 0, and not less than the amount.`);\n }\n if (store.due !== undefined) add(\"error\", \"endurance-capacity\", store.id, `The store \"${store.id}\" has a capacity and a due date. A store with a charge has no due date.`);\n }\n }\n for (const code of new Set(layer.stores.map((store) => store.resource))) {\n const all = layer.stores.filter((store) => store.resource === code);\n const charged = all.filter((store) => store.capacity !== undefined);\n if (charged.length > 0 && charged.length < all.length) {\n add(\"error\", \"endurance-capacity\", code, `The resource \"${code}\" has a store with a capacity and a store with no capacity. Its stores all have a capacity, or none has one.`);\n }\n }\n const levels = new Set(layer.levels);\n for (const draw of layer.draws) {\n if (!levels.has(draw.level)) add(\"error\", \"endurance-level-unknown\", draw.need, `The level \"${draw.level}\" of the draw \"${draw.need}\" is not a level of the layer.`);\n range(draw.need, \"rate\", draw.perDay);\n if (draw.users !== undefined) range(draw.need, \"count of users\", draw.users);\n part(draw.need, \"supply\", draw.supply);\n const ways = direct.some((use) => use.need === draw.need) || converters.some((converter) => giftNeed(converter) === draw.need);\n if (!ways) add(\"warning\", \"endurance-no-way\", draw.need, `The draw \"${draw.need}\" has no direct use and no converter. It holds 0 days when its supply stops.`);\n }\n for (const use of direct) {\n const at = `${use.resource}>${use.need}`;\n resource(at, use.resource);\n range(at, \"amount\", use.amount);\n }\n for (const converter of converters) {\n once(`resources of the converter \"${converter.id}\"`, converter.takes.map((input) => input.resource));\n for (const input of converter.takes) {\n resource(converter.id, input.resource);\n range(converter.id, \"amount\", input.amount);\n }\n range(converter.id, \"amount\", converter.gives.amount);\n const made = giftResource(converter);\n if (made !== undefined) resource(converter.id, made);\n const source = converter.perDay !== undefined && converter.perDay > 0;\n if ((!source && !converter.takes.some((input) => input.amount > 0)) || converter.gives.amount === 0) add(\"error\", \"endurance-converter-empty\", converter.id, `The converter \"${converter.id}\" takes nothing, or it gives nothing.`);\n part(converter.id, \"device\", converter.device);\n if (converter.perDay !== undefined) range(converter.id, \"rate perDay\", converter.perDay);\n if (converter.devices !== undefined && !(Number.isSafeInteger(converter.devices) && converter.devices >= 1))\n add(\"error\", \"endurance-range\", converter.id, `The count of devices of \"${converter.id}\" is ${String(converter.devices)}. It must be a whole number of 1 or more.`);\n if (converter.season !== undefined) for (const message of seasonFaults(converter)) add(\"error\", \"endurance-season\", converter.id, message);\n for (const message of monthlyFaults(converter)) add(\"error\", \"endurance-monthly\", converter.id, message);\n }\n const shares = new Map<string, Converter>();\n for (const converter of converters) {\n if (converter.device === undefined || converter.perDay === undefined) continue;\n const seen = shares.get(converter.device);\n if (seen === undefined) shares.set(converter.device, converter);\n else if (!sameShares(seen.monthly, converter.monthly))\n add(\"error\", \"endurance-monthly\", converter.id, `The converter \"${converter.id}\" and the converter \"${seen.id}\" of the device \"${converter.device}\" have different shares monthly. The converters of one device have the same shares.`);\n }\n const counts = new Map<string, number>();\n for (const converter of converters) {\n if (converter.device === undefined) continue;\n const count = converter.devices ?? 1;\n const seen = counts.get(converter.device);\n if (seen !== undefined && seen !== count)\n add(\"error\", \"endurance-devices\", converter.id, `The converter \"${converter.id}\" gives the count ${String(count)} for the device \"${converter.device}\". An other converter gives the count ${String(seen)}.`);\n if (seen === undefined) counts.set(converter.device, count);\n }\n // One fault names each device with a limited converter and a converter with no limit, at the first converter with no limit.\n const mixed = new Set<string>();\n for (const converter of converters) {\n const device = converter.device;\n if (device === undefined || converter.perDay !== undefined || mixed.has(device)) continue;\n const limited = converters.find((other) => other.device === device && other.perDay !== undefined);\n if (limited === undefined) continue;\n mixed.add(device);\n add(\"warning\", \"endurance-device-mix\", converter.id, `The device \"${device}\" has the limited converter \"${limited.id}\" and the converter \"${converter.id}\" with no limit. \"${converter.id}\" uses no device-days.`);\n }\n const caseCodes = new Set(cases.map((item) => item.case));\n for (const item of cases) {\n once(`cuts of the case \"${item.case}\"`, item.cuts.map((cut) => cut.part));\n for (const cut of item.cuts) {\n const at = `${item.case}/${cut.part}`;\n part(at, \"cut\", cut.part);\n if (cut.bound !== undefined && !isCutBound(cut.bound))\n add(\"error\", \"endurance-bound\", at, `The bound of the cut \"${at}\" is ${JSON.stringify(cut.bound)}. It must be one of ${CUT_BOUNDS.join(\", \")}.`);\n if (cut.duration === undefined) {\n add(\"warning\", \"endurance-cut-no-curve\", at, `The cut \"${at}\" has no curve of its duration, so the draws that it can stop are no read.`);\n if (cut.band !== undefined) add(\"error\", \"endurance-curve\", at, `The cut \"${at}\" has a band and no curve of its duration.`);\n if (cut.counts !== undefined) add(\"error\", \"endurance-curve\", at, `The cut \"${at}\" has counts and no curve of its duration.`);\n if (cut.sums !== undefined) add(\"error\", \"endurance-curve\", at, `The cut \"${at}\" has sums and no curve of its duration.`);\n continue;\n }\n const fault = curveFault(cut.duration);\n if (fault !== undefined) add(\"error\", \"endurance-curve\", at, `The duration of the cut \"${at}\": ${fault}`);\n const band = cut.band === undefined || fault !== undefined ? undefined : bandFault(cut.duration, cut.band);\n if (band !== undefined) add(\"error\", \"endurance-curve\", at, `The band of the cut \"${at}\": ${band}`);\n const counts = cut.counts === undefined || fault !== undefined ? undefined : countsFault(cut.duration, cut.counts);\n if (counts !== undefined) add(\"error\", \"endurance-curve\", at, `The counts of the cut \"${at}\": ${counts}`);\n const sums = cut.sums === undefined || fault !== undefined ? undefined : sumsFault(cut.duration, cut.sums);\n if (sums !== undefined) add(\"error\", \"endurance-curve\", at, `The sums of the cut \"${at}\": ${sums}`);\n }\n for (const [need, factor] of Object.entries(item.factors ?? {})) range(`${item.case}/${need}`, \"factor\", factor);\n if (item.leadSeconds !== undefined) range(item.case, \"lead time\", item.leadSeconds);\n }\n for (const cycle of resourceCycles(converters)) {\n const [first = \"\"] = cycle;\n const names = cycle.map((code) => `\"${code}\"`).join(\", \");\n const message = cycle.length === 1 ? `A converter makes the resource ${names} from itself.` : `Converters make the resources ${names} from each other.`;\n add(\"error\", \"endurance-cycle\", first, `${message} A chain of converters cannot end.`);\n }\n for (const prior of priors) {\n const at = `${prior.case}@${prior.place}`;\n if (!caseCodes.has(prior.case)) add(\"error\", \"endurance-prior-case\", at, `The prior \"${at}\" names the case \"${prior.case}\", which the layer does not have.`);\n range(at, \"count of events in one year\", prior.perYear);\n if (!(prior.reach >= 0 && prior.reach <= 1)) add(\"error\", \"endurance-range\", at, `The reach of \"${at}\" is ${String(prior.reach)}. It must be from 0 to 1.`);\n date(at, prior.asOf);\n const fault = prior.interval === undefined ? undefined : intervalFault(prior.interval);\n if (fault !== undefined) add(\"error\", \"endurance-range\", at, `The interval of the count of events in one year of \"${at}\" is not valid. ${fault}`);\n }\n return faults;\n}\n\n/** This function tells if a text is a day `MM-DD` of a leap year. */\nfunction isMonthDay(value: string): boolean {\n return /^\\d{2}-\\d{2}$/.test(value) && dayNumber(`2000-${value}`) !== undefined;\n}\n\n/** This function gives the messages of the faults of the season of a converter. */\nfunction seasonFaults(converter: Converter): string[] {\n const season = converter.season;\n if (season === undefined) return [];\n const out: string[] = [];\n for (const day of [season.from, season.to]) if (!isMonthDay(day)) out.push(`The season of \"${converter.id}\" has the day \"${day}\". It is not a day MM-DD.`);\n if (!(Number.isFinite(season.delayDays) && season.delayDays > 0)) out.push(`The delay of the season of \"${converter.id}\" is ${String(season.delayDays)}. It must be a finite number of days more than 0.`);\n if (season.shelfDays !== undefined && !(Number.isFinite(season.shelfDays) && season.shelfDays > 0)) out.push(`The shelf life of the season of \"${converter.id}\" is ${String(season.shelfDays)}. It must be a finite number of days more than 0.`);\n if (!(Number.isFinite(season.runs) && season.runs >= 0)) out.push(`The runs of the season of \"${converter.id}\" are ${String(season.runs)}. They must be a finite number of 0 or more.`);\n if (giftResource(converter) === undefined) out.push(`The converter \"${converter.id}\" has a season and gives a need. A converter with a season gives a resource.`);\n if (converter.perDay !== undefined || converter.devices !== undefined) out.push(`The converter \"${converter.id}\" has a season and a limit perDay or devices. A converter with a season has no such limit.`);\n return out;\n}\n\n/** This function gives the messages of the faults of the shares `monthly` of a converter (M2-solar). */\nfunction monthlyFaults(converter: Converter): string[] {\n const monthly = converter.monthly;\n if (monthly === undefined) return [];\n const out: string[] = [];\n if (monthly.length !== 12 || !monthly.every((share) => Number.isFinite(share) && share >= 0 && share <= 1))\n out.push(`The shares monthly of \"${converter.id}\" are not 12 numbers from 0 to 1.`);\n if (converter.perDay === undefined) out.push(`The converter \"${converter.id}\" has shares monthly and no limit perDay. The shares are parts of the limit.`);\n if (converter.season !== undefined) out.push(`The converter \"${converter.id}\" has shares monthly and a season. A converter has one or the other.`);\n return out;\n}\n\n/** This function tells if two lists of shares `monthly` are equal. No list is equal to a list of 12 ones. */\nfunction sameShares(a: readonly number[] | undefined, b: readonly number[] | undefined): boolean {\n const full = (shares: readonly number[] | undefined): readonly number[] => shares ?? Array.from({ length: 12 }, () => 1);\n const left = full(a);\n const right = full(b);\n return left.length === right.length && left.every((share, index) => share === right[index]);\n}\n\n/**\n * This function gives each cycle of resources: a resource is made from a resource that a converter makes from it. Each cycle is a list of codes.\n * A converter with a season is not part of a cycle: its harvest comes after its sowing, thus a chain of it ends.\n */\nfunction resourceCycles(converters: readonly Converter[]): string[][] {\n const from = new Map<string, Set<string>>();\n for (const converter of converters) {\n const made = giftResource(converter);\n if (made === undefined || converter.season !== undefined) continue;\n const inputs = from.get(made) ?? new Set<string>();\n for (const input of converter.takes) if (input.amount > 0) inputs.add(input.resource);\n from.set(made, inputs);\n }\n const successors = (code: string): Iterable<string> => from.get(code) ?? [];\n return stronglyConnectedComponents(from.keys(), successors).filter((component) => {\n const [only = \"\"] = component;\n return component.length > 1 || (from.get(only)?.has(only) ?? false);\n });\n}\n\n/** This function tells if a list of faults has an error. */\nexport function hasEnduranceError(faults: readonly EnduranceFault[]): boolean {\n return faults.some((fault) => fault.level === \"error\");\n}\n","import { canonicalJson } from \"@mark1russell7/rigor-generators\";\nimport { joinRecords, joinSetting, type LayerParse, type LayerPiece } from \"@mark1russell7/system-stack\";\nimport { ENDURANCE_SCHEMA, type EnduranceLayer } from \"./layer.ts\";\n\n// The join of the endurance layers of the fragments of a stack, for example one file of stores for each owner.\n\n/**\n * This function joins the endurance layers of the fragments of a stack into one layer.\n *\n * - The levels are one setting: each fragment that has levels gives the same list, else the join has a fault.\n * - The records of each list are in the order of the fragments.\n * - Two resources with one code in two fragments join into one resource when their records are equal. A different field is a fault.\n * Its message gives the canonical JSON of the record of each fragment.\n * - A code that one fragment has two times stays in the joined layer. The gate `checkEndurance` finds it.\n * - One key of each other list in two or more fragments is a fault, also when the records are equal.\n * - The key of a direct use is its resource and its need.\n *\n * The function is pure, and it changes no layer. The gate `checkEndurance` examines the joined layer afterward.\n *\n * @param pieces - The layers, with the name of the fragment of each one, in the order of the fragments.\n * @returns The joined layer, or the faults of the join.\n */\nexport function joinEndurance(pieces: readonly LayerPiece<EnduranceLayer>[]): LayerParse<EnduranceLayer> {\n const levels = joinSetting(pieces, (layer) => (layer.levels.length > 0 ? layer.levels.join(\"\\n\") : undefined), \"levels\");\n // Two fragments can declare one resource, for example `water.stored` in `L`. Canonical JSON (RFC 8785) compares the records,\n // so the order of the keys has no effect. The message of a fault gives the canonical JSON of the record of each fragment.\n const resources = joinRecords(pieces, (layer) => layer.resources, (item) => item.code, \"resource\", {\n equal: (first, other) => canonicalJson(first) === canonicalJson(other),\n text: canonicalJson,\n });\n const stores = joinRecords(pieces, (layer) => layer.stores, (item) => item.id, \"store\");\n const draws = joinRecords(pieces, (layer) => layer.draws, (item) => item.need, \"draw\");\n const direct = joinRecords(pieces, (layer) => layer.direct, (item) => `${item.resource}>${item.need}`, \"direct use\");\n const converters = joinRecords(pieces, (layer) => layer.converters, (item) => item.id, \"converter\");\n const cases = joinRecords(pieces, (layer) => layer.cases, (item) => item.case, \"case\");\n const priors = joinRecords(pieces, (layer) => layer.priors, (item) => `${item.case}@${item.place}`, \"prior\");\n const errors = [levels, resources, stores, draws, direct, converters, cases, priors].flatMap((join) => join.errors);\n if (errors.length > 0) return { ok: false, errors };\n const has = (key: \"direct\" | \"converters\" | \"cases\" | \"priors\"): boolean => pieces.some((piece) => piece.layer[key] !== undefined);\n return {\n ok: true,\n layer: {\n schema: ENDURANCE_SCHEMA,\n levels: levels.value === undefined ? [] : levels.value.split(\"\\n\"),\n resources: resources.items,\n stores: stores.items,\n draws: draws.items,\n ...(has(\"direct\") ? { direct: direct.items } : {}),\n ...(has(\"converters\") ? { converters: converters.items } : {}),\n ...(has(\"cases\") ? { cases: cases.items } : {}),\n ...(has(\"priors\") ? { priors: priors.items } : {}),\n },\n };\n}\n"],"mappings":";;;;;;AAKA,SAAgB,SAAS,WAA2C;CAClE,MAAM,sBAAM,IAAI,IAAoB;CACpC,KAAK,MAAM,SAAS,UAAU,OAAO,IAAI,MAAM,SAAS,GAAG,IAAI,IAAI,MAAM,WAAW,IAAI,IAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,MAAM;CAChI,OAAO;AACT;;;;;AAMA,SAAgB,SAAS,WAA+B;CACtD,IAAI,EAAE,UAAU,WAAW,KAAA,KAAa,UAAU,SAAS,IAAI,OAAO;CAEtE,KAAK,MAAM,SAAS,UAAU,OAAO,IAAI,MAAM,SAAS,GAAG,OAAO;CAClE,OAAO;AACT;;;;;AAMA,SAAgB,OAAO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