@mark1russell7/stack-needs 0.9.7 → 0.9.9
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 +28 -2
- package/build/index.d.ts +158 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +307 -2
- package/build/index.js.map +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -351,7 +351,7 @@ The 2025-2030 edition of the guidelines was read on 2026-11-24. It has no table
|
|
|
351
351
|
| `warmth.shelter` | `kWh` | household | no read |
|
|
352
352
|
|
|
353
353
|
- `alert.watch` comes from two pages of the National Weather Service (read on 2026-11-24). Many receivers have a muted standby mode that turns on when a warning comes. Warnings also come at night. Thus a receiver stays on and listens at all hours, so 24 hours each day. One receiver for each home is a choice of this model, not of the pages. The pages are in the public domain (the license `us-public-domain`).
|
|
354
|
-
- `light.see` is a no read. The kit lists of Ready.gov give a flashlight and extra batteries, but no hours of use each day. The hours of dark are the same for all the persons of a home, so the users are the household. The count of lights of each person is a fact of the plan or the device.
|
|
354
|
+
- `light.see` is a no read. The kit lists of Ready.gov give a flashlight and extra batteries, but no hours of use each day. The hours of dark are the same for all the persons of a home, so the users are the household. The count of lights of each person is a fact of the plan or the device. `lightNeed` gives a read from the point of the home and its awake window.
|
|
355
355
|
- `warmth.shelter` is a no read. The heat that a home needs changes with the weather, the building and the persons. It is space heat only. The blankets and the sleeping bags of each person are gear, not this need.
|
|
356
356
|
- A user gives each no read as input data.
|
|
357
357
|
- The rate of a device is a fact of the device, not of the need. An example is the watts of a radio in standby.
|
|
@@ -360,8 +360,34 @@ The 2025-2030 edition of the guidelines was read on 2026-11-24. It has no table
|
|
|
360
360
|
|
|
361
361
|
The gate refuses an empty code and two needs with one code (`daily-need-id`). It refuses a unit that `@mark1russell7/quantity` does not read (`daily-need-unit`). It also refuses a bad read or a no read with no reason (`daily-need-rate`). A bad read has no source. Or its amount is not a finite number of 0 or more in the unit of the need for each day.
|
|
362
362
|
|
|
363
|
+
## The devices of the kit
|
|
364
|
+
|
|
365
|
+
`deviceFragment` gives the devices of a buy list that run on cells, as converters of an endurance layer. Examples are a radio and a flashlight.
|
|
366
|
+
|
|
367
|
+
- Each device of the catalog of market with a cited run time gives one converter. The field `device` of a product gives its need, its cells and its run time.
|
|
368
|
+
- One run takes one cell, and gives the hours of the need for each cell. For example, 48 h on 3 cells gives 16 h for each cell.
|
|
369
|
+
- One device gives its need for 24 hours in a day or less. Thus the limit `perDay` is `HOURS_IN_DAY` divided by the hours for each cell. The count of devices is the count of whole units.
|
|
370
|
+
- The input `runs` gives the run time of a device of the caller, with its citation. It replaces the run time of the catalog.
|
|
371
|
+
- A device with no run time gives no converter, and a no read. The radio and the flashlight of the catalog are no one model, so their run time is a no read.
|
|
372
|
+
- With the input `draws`, each need of a device gives one draw at the daily rate of the need. A need with no read of its rate gives no draw, and a no read.
|
|
373
|
+
- The fragment has no store. The cells come from the stores of the buy list, for example the product `power.aa-alkaline` of the catalog.
|
|
374
|
+
|
|
375
|
+
## The hours of light
|
|
376
|
+
|
|
377
|
+
`lightHours` gives the dark hours of the awake window of a household on each date of a plan. `lightNeed` changes them into a read of the need `light.see`.
|
|
378
|
+
|
|
379
|
+
- The input is the point of the home, the awake window in local time, the first date and the count of days. The point and the window are input data of the household.
|
|
380
|
+
- The light is the time from the sunrise to the sunset of `sunDay` of `@mark1russell7/geo`. A polar day is light, and a polar night is dark.
|
|
381
|
+
- The awake window is a `TimeWindow` of `@mark1russell7/algebra/clock`. It follows the wall clock, also at a change of the clock.
|
|
382
|
+
- A local date is the time from its local midnight to the next local midnight. A window across midnight gives its hours to each date by the clock.
|
|
383
|
+
- The result gives each day, the most of the worst day and the mean.
|
|
384
|
+
- The rate of `lightNeed` is the most. One light that is on in those hours is a choice of this model, not of the sources.
|
|
385
|
+
- The sources are the pages "Position of the Sun" and "Sunrise equation" of Wikipedia (license `cc-by-sa-4.0`). The code uses their formulas, not their text.
|
|
386
|
+
|
|
387
|
+
The read goes into `deviceFragment` through the input `needs`. Then the need of light gets a draw.
|
|
388
|
+
|
|
363
389
|
## The entries
|
|
364
390
|
|
|
365
391
|
| Entry | What it has |
|
|
366
392
|
| --- | --- |
|
|
367
|
-
| `@mark1russell7/stack-needs` | The records, the calorie tables and `CALORIE_CHAIN`, the gates, `calorieNeed`, `householdFragment`, `cookFragment` and its constants, `formulaMixFragment` and `FORMULA_MIX`, the uses, the supply parts and `checkJoins`. |
|
|
393
|
+
| `@mark1russell7/stack-needs` | The records, the calorie tables and `CALORIE_CHAIN`, the gates, `calorieNeed`, `householdFragment`, `cookFragment` and its constants, `formulaMixFragment` and `FORMULA_MIX`, `deviceFragment`, `lightHours`, `lightNeed`, the daily needs, the uses, the supply parts and `checkJoins`. |
|
package/build/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Quantity } from "@mark1russell7/quantity";
|
|
2
2
|
import { Finding, FindingCode, GateOptions, Source } from "@mark1russell7/guidebook";
|
|
3
3
|
import { BuyListEnergy, HeatingValue, StoveFacts, SupplyCatalog } from "@mark1russell7/market/supplies";
|
|
4
|
+
import { CivilDate, TimeWindow } from "@mark1russell7/algebra/clock";
|
|
5
|
+
import { LatLon } from "@mark1russell7/geo";
|
|
4
6
|
/** The activity levels of the table, as the source names them: sedentary, moderately active and active. */
|
|
5
7
|
export declare const ACTIVITY_LEVELS: readonly ["sedentary", "moderately-active", "active"];
|
|
6
8
|
/** An activity level of the table. */
|
|
@@ -971,7 +973,7 @@ export declare const NWS_ALARMS_SOURCE: Source;
|
|
|
971
973
|
* - `alert.watch`: 24 hours each day for each household. The sources give a standby mode that turns on at an alert, and warnings at night.
|
|
972
974
|
* Thus a receiver stays on at all hours to get a warning. One receiver for each home is a choice of this model.
|
|
973
975
|
* - `light.see`: no read, for each household. The kit lists of official sources give a flashlight and extra batteries, but no hours of use.
|
|
974
|
-
* The count of lights of each person is a fact of the plan or the device.
|
|
976
|
+
* The count of lights of each person is a fact of the plan or the device. `lightNeed` gives a read from the point and the awake window.
|
|
975
977
|
* - `warmth.shelter`: no read. The heat of a home changes with the weather, the building and the persons. It is space heat only.
|
|
976
978
|
*/
|
|
977
979
|
export declare const DAILY_NEEDS: readonly DailyNeed[];
|
|
@@ -997,4 +999,159 @@ export type DailyNeedFinding = Finding<DailyNeedCode | FindingCode, "source" | "
|
|
|
997
999
|
* @param options - The options of the gate of the sources, for example the date of the gate
|
|
998
1000
|
*/
|
|
999
1001
|
export declare function checkDailyNeeds(needs: readonly DailyNeed[], options?: GateOptions): DailyNeedFinding[];
|
|
1002
|
+
/** The hours in one day, from the definition of the day in `@mark1russell7/quantity`. */
|
|
1003
|
+
export declare const HOURS_IN_DAY: number;
|
|
1004
|
+
/** The run time of a device of the caller: `amount` of `unit` on `per` cells, with its citation. */
|
|
1005
|
+
export interface DeviceRun {
|
|
1006
|
+
readonly amount: number;
|
|
1007
|
+
readonly unit: string;
|
|
1008
|
+
readonly per: {
|
|
1009
|
+
readonly amount: number;
|
|
1010
|
+
readonly unit: string;
|
|
1011
|
+
};
|
|
1012
|
+
/** The citation of the value: the `id` of a fact or a source of the caller. */
|
|
1013
|
+
readonly cite: string;
|
|
1014
|
+
}
|
|
1015
|
+
/** The part of the stack that supplies the needs of the devices, and the level of their draws. */
|
|
1016
|
+
export interface DeviceDraws {
|
|
1017
|
+
readonly level: string;
|
|
1018
|
+
readonly supply: string;
|
|
1019
|
+
}
|
|
1020
|
+
/** The inputs of the device fragment. */
|
|
1021
|
+
export interface DeviceFragmentInput {
|
|
1022
|
+
/** The catalog of supplies of `@mark1russell7/market`. */
|
|
1023
|
+
readonly catalog: SupplyCatalog;
|
|
1024
|
+
/** The count of units of each product of the buy list or the kit, by the `id` of the product. */
|
|
1025
|
+
readonly units: Readonly<Record<string, number>>;
|
|
1026
|
+
/**
|
|
1027
|
+
* The run time of each device of the caller, by the `id` of the product. It replaces the run time of the catalog, for
|
|
1028
|
+
* example for a model that the catalog does not cite. It has no default.
|
|
1029
|
+
*/
|
|
1030
|
+
readonly runs?: Readonly<Record<string, DeviceRun>> | undefined;
|
|
1031
|
+
/** The `id` of each device in the stack, by the `id` of the product. The converter stops when the device stops. */
|
|
1032
|
+
readonly parts?: Readonly<Record<string, string>> | undefined;
|
|
1033
|
+
/** The level and the supply of the draws. Without it, the fragment has no draw. */
|
|
1034
|
+
readonly draws?: DeviceDraws | undefined;
|
|
1035
|
+
/** The daily needs. The default is `DAILY_NEEDS`. */
|
|
1036
|
+
readonly needs?: readonly DailyNeed[] | undefined;
|
|
1037
|
+
/** The start of the `id` of each converter. The default is `device`. */
|
|
1038
|
+
readonly prefix?: string | undefined;
|
|
1039
|
+
}
|
|
1040
|
+
/** A value of the device model with a read, in its unit, or no read with the reasons. A no read is not 0. */
|
|
1041
|
+
export type DeviceRead = {
|
|
1042
|
+
readonly read: true;
|
|
1043
|
+
readonly value: number;
|
|
1044
|
+
readonly unit: string;
|
|
1045
|
+
} | {
|
|
1046
|
+
readonly read: false;
|
|
1047
|
+
readonly why: string;
|
|
1048
|
+
};
|
|
1049
|
+
/** The values of one device of the buy list. */
|
|
1050
|
+
export interface DeviceLine {
|
|
1051
|
+
readonly product: string;
|
|
1052
|
+
/** The code of the need that the device gives, for example `alert.watch`. */
|
|
1053
|
+
readonly need: string;
|
|
1054
|
+
/** The resource of its cells, for example `battery.aa`. */
|
|
1055
|
+
readonly battery: string;
|
|
1056
|
+
/** The count of whole devices. */
|
|
1057
|
+
readonly devices: number;
|
|
1058
|
+
/** The hours of the need for each cell, in `h`. */
|
|
1059
|
+
readonly hours: DeviceRead;
|
|
1060
|
+
}
|
|
1061
|
+
/** A converter of the device fragment: a converter with its limit of runs for each day and its count of devices. */
|
|
1062
|
+
export interface DeviceConverter extends FragmentConverter {
|
|
1063
|
+
readonly perDay: number;
|
|
1064
|
+
readonly devices: number;
|
|
1065
|
+
}
|
|
1066
|
+
/** The device fragment of an endurance layer: the resources, one converter for each device with a read, and the draws. It has no store. */
|
|
1067
|
+
export interface DeviceFragment {
|
|
1068
|
+
/** The format of an endurance layer, `endurance/1`. */
|
|
1069
|
+
readonly schema: "endurance/1";
|
|
1070
|
+
readonly levels: readonly string[];
|
|
1071
|
+
readonly resources: readonly FragmentResource[];
|
|
1072
|
+
readonly stores: readonly never[];
|
|
1073
|
+
readonly draws: readonly FragmentDraw[];
|
|
1074
|
+
readonly converters: readonly DeviceConverter[];
|
|
1075
|
+
}
|
|
1076
|
+
/** A device or a need with no record in the layer, and the reasons. `product` names a device, and `need` names a draw. */
|
|
1077
|
+
export type DeviceNoRead = {
|
|
1078
|
+
readonly product: string;
|
|
1079
|
+
readonly need?: never;
|
|
1080
|
+
readonly why: string;
|
|
1081
|
+
} | {
|
|
1082
|
+
readonly need: string;
|
|
1083
|
+
readonly product?: never;
|
|
1084
|
+
readonly why: string;
|
|
1085
|
+
};
|
|
1086
|
+
/** The device fragment, the line of each device and the records with no read. */
|
|
1087
|
+
export interface DeviceFragmentResult {
|
|
1088
|
+
readonly layer: DeviceFragment;
|
|
1089
|
+
/** The line of each device of the buy list, in the order of the list. */
|
|
1090
|
+
readonly lines: readonly DeviceLine[];
|
|
1091
|
+
/** The devices with no converter, and the needs with no draw. */
|
|
1092
|
+
readonly noReads: readonly DeviceNoRead[];
|
|
1093
|
+
/** True when each device has a converter and each need has a draw. When it is false, the days of a need are a lower limit or a no read. */
|
|
1094
|
+
readonly read: boolean;
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* This function gives the device fragment of an endurance layer. Each device of the buy list with a cited run time gives
|
|
1098
|
+
* one converter. One run takes one cell and gives the hours of the need for each cell. The limit of runs for each day is
|
|
1099
|
+
* `HOURS_IN_DAY` divided by those hours. Thus one device gives 24 hours of its need in a day or less. The count of
|
|
1100
|
+
* devices is the count of whole units of the product. A device with no cited run time gives no converter, and a no read.
|
|
1101
|
+
*
|
|
1102
|
+
* With `draws`, each need of a device gives one draw. Its rate is the daily rate of the need in its unit for each day. The users are 1
|
|
1103
|
+
* for a need of the household. A need with no read of its rate gives no draw, and a no read.
|
|
1104
|
+
*
|
|
1105
|
+
* @param input - The catalog, the counts of the buy list, the run times of the caller and the parts and draws
|
|
1106
|
+
* @throws RangeError for a device whose cells are not a resource of the catalog
|
|
1107
|
+
*/
|
|
1108
|
+
export declare function deviceFragment(input: DeviceFragmentInput): DeviceFragmentResult;
|
|
1109
|
+
/** The page "Position of the Sun" of Wikipedia: the formulas of the place of the sun that `sunDay` of `@mark1russell7/geo` uses. */
|
|
1110
|
+
export declare const SUN_POSITION_SOURCE: Source;
|
|
1111
|
+
/** The page "Sunrise equation" of Wikipedia: the hour angle of the sunrise and the sunset that `sunDay` of `@mark1russell7/geo` uses. */
|
|
1112
|
+
export declare const SUNRISE_EQUATION_SOURCE: Source;
|
|
1113
|
+
/** The most days of one calculation of the light hours: three years. */
|
|
1114
|
+
export declare const MAX_LIGHT_DAYS = 1096;
|
|
1115
|
+
/** The input of `lightHours`. */
|
|
1116
|
+
export interface LightHoursInput {
|
|
1117
|
+
/** The point of the home. It is input data of the household. */
|
|
1118
|
+
readonly point: LatLon;
|
|
1119
|
+
/** The awake window of the household in its local time, for example 07:00 to 23:00 in its time zone. */
|
|
1120
|
+
readonly awake: TimeWindow;
|
|
1121
|
+
/** The first date of the plan, `YYYY-MM-DD`, in the local time of the window. */
|
|
1122
|
+
readonly from: CivilDate;
|
|
1123
|
+
/** The count of the days of the plan, a whole number from 1 to `MAX_LIGHT_DAYS`. */
|
|
1124
|
+
readonly days: number;
|
|
1125
|
+
/** The altitude of the sun at which the dark starts, in degrees. The default is the sunrise altitude of `@mark1russell7/geo`. */
|
|
1126
|
+
readonly altitudeDeg?: number | undefined;
|
|
1127
|
+
}
|
|
1128
|
+
/** The hours of one local date: the awake hours, and the awake hours in the dark. */
|
|
1129
|
+
export interface LightDay {
|
|
1130
|
+
readonly date: CivilDate;
|
|
1131
|
+
readonly awakeHours: number;
|
|
1132
|
+
readonly darkHours: number;
|
|
1133
|
+
}
|
|
1134
|
+
/** The result of `lightHours`: each day, and the most and the mean of the dark awake hours. */
|
|
1135
|
+
export interface LightHours {
|
|
1136
|
+
readonly days: readonly LightDay[];
|
|
1137
|
+
/** The dark awake hours of the worst day. */
|
|
1138
|
+
readonly most: number;
|
|
1139
|
+
/** The mean of the dark awake hours of the days. */
|
|
1140
|
+
readonly mean: number;
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* This function gives the dark hours of the awake window of a household on each local date of a plan.
|
|
1144
|
+
*
|
|
1145
|
+
* - A local date is the time from its local midnight to the next local midnight. The hours of a window across midnight go to each date by the clock.
|
|
1146
|
+
* - The light is the time from the sunrise to the sunset of `sunDay` of `@mark1russell7/geo`. A polar day is light, and a polar night is dark.
|
|
1147
|
+
* - The dark awake hours of a date are its awake hours minus its awake hours in the light.
|
|
1148
|
+
*
|
|
1149
|
+
* @throws RangeError - The window has a problem, or the date is not a date. Or the count of days is not a whole number from 1 to `MAX_LIGHT_DAYS`.
|
|
1150
|
+
*/
|
|
1151
|
+
export declare function lightHours(input: LightHoursInput): LightHours;
|
|
1152
|
+
/**
|
|
1153
|
+
* This function gives the need of light of a household from its light hours: the dark awake hours of its worst day.
|
|
1154
|
+
* One light that is on in the dark awake hours is a choice of this model. A household with more lights gives more draws.
|
|
1155
|
+
*/
|
|
1156
|
+
export declare function lightNeed(hours: LightHours): DailyNeed;
|
|
1000
1157
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts","../src/cook.ts","../src/mix.ts","../src/daily.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/calorie.ts","../src/data.ts","../src/check.ts","../src/uses.ts","../src/household.ts","../src/cook.ts","../src/mix.ts","../src/daily.ts","../src/device.ts","../src/light.ts"],"mappings":";;;;;;qBAQa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sB;;qBChI/C,qBAAqB;;qBAWrB,yBAAyB;;qBAWzB;;iBAMI;;WAEN,OAAO;;WAEP,OAAO;;WAEP,MAAM;;WAEN;;WAEA;;;iBAIM;WACN,MAAM;WACN;WACA;;;iBAIM;WACN,eAAe;;WAEf;;WAEA;;;;;;;;;;;wBAiEK,WAAW,OAAO,kBAAkB;;;;;wBAiCpC,UAAU,OAAO,aAAa"}
|
package/build/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { canonicalUnit, quantity, valueIn } from "@mark1russell7/quantity";
|
|
2
2
|
import { checkSources } from "@mark1russell7/guidebook";
|
|
3
3
|
import { buyListEnergy, cookWater, fuelEnergyPerMass, giftsOf } from "@mark1russell7/market/supplies";
|
|
4
|
+
import { addDays, firstInstantOf, inWindow, nextBoundary, windowProblems } from "@mark1russell7/algebra/clock";
|
|
5
|
+
import { sunDay } from "@mark1russell7/geo";
|
|
4
6
|
// src/calorie.ts
|
|
5
7
|
/** The activity levels of the table, as the source names them: sedentary, moderately active and active. */
|
|
6
8
|
const ACTIVITY_LEVELS = [
|
|
@@ -2158,7 +2160,7 @@ const NWS_ALARMS_SOURCE = {
|
|
|
2158
2160
|
* - `alert.watch`: 24 hours each day for each household. The sources give a standby mode that turns on at an alert, and warnings at night.
|
|
2159
2161
|
* Thus a receiver stays on at all hours to get a warning. One receiver for each home is a choice of this model.
|
|
2160
2162
|
* - `light.see`: no read, for each household. The kit lists of official sources give a flashlight and extra batteries, but no hours of use.
|
|
2161
|
-
* The count of lights of each person is a fact of the plan or the device.
|
|
2163
|
+
* The count of lights of each person is a fact of the plan or the device. `lightNeed` gives a read from the point and the awake window.
|
|
2162
2164
|
* - `warmth.shelter`: no read. The heat of a home changes with the weather, the building and the persons. It is space heat only.
|
|
2163
2165
|
*/
|
|
2164
2166
|
const DAILY_NEEDS = [
|
|
@@ -2272,6 +2274,309 @@ function checkDailyNeeds(needs, options) {
|
|
|
2272
2274
|
});
|
|
2273
2275
|
return findings;
|
|
2274
2276
|
}
|
|
2275
|
-
|
|
2277
|
+
// src/device.ts
|
|
2278
|
+
/** The hours in one day, from the definition of the day in `@mark1russell7/quantity`. */
|
|
2279
|
+
const HOURS_IN_DAY = valueIn({
|
|
2280
|
+
value: 1,
|
|
2281
|
+
unit: "d"
|
|
2282
|
+
}, "h");
|
|
2283
|
+
/** This function gives the value of an amount in a unit, or `undefined` when the units do not convert. */
|
|
2284
|
+
function amountIn(value, unit, to) {
|
|
2285
|
+
try {
|
|
2286
|
+
const out = valueIn({
|
|
2287
|
+
value,
|
|
2288
|
+
unit
|
|
2289
|
+
}, to);
|
|
2290
|
+
return Number.isFinite(out) ? out : void 0;
|
|
2291
|
+
} catch {
|
|
2292
|
+
return;
|
|
2293
|
+
}
|
|
2294
|
+
}
|
|
2295
|
+
/** This function gives the hours for each cell of a run time, or a no read with its reason. */
|
|
2296
|
+
function hoursOf(run, cell, where) {
|
|
2297
|
+
const hours = amountIn(run.amount, run.unit, "h");
|
|
2298
|
+
const cells = amountIn(run.per.amount, run.per.unit, cell);
|
|
2299
|
+
if (hours === void 0 || !(hours > 0)) return {
|
|
2300
|
+
read: false,
|
|
2301
|
+
why: `The run time ${run.amount} ${run.unit} of ${where} is not a time above 0.`
|
|
2302
|
+
};
|
|
2303
|
+
if (cells === void 0 || !(cells > 0)) return {
|
|
2304
|
+
read: false,
|
|
2305
|
+
why: `The run time of ${where} is on ${run.per.amount} ${run.per.unit}, and that is not a count of cells above 0 in ${cell}.`
|
|
2306
|
+
};
|
|
2307
|
+
return {
|
|
2308
|
+
read: true,
|
|
2309
|
+
value: hours / cells,
|
|
2310
|
+
unit: "h"
|
|
2311
|
+
};
|
|
2312
|
+
}
|
|
2313
|
+
/** This function gives the hours for each cell of a device: the input of the caller first, then the catalog. */
|
|
2314
|
+
function deviceHours(facts, run, cell, product) {
|
|
2315
|
+
if (run !== void 0) {
|
|
2316
|
+
if (run.cite.trim() === "") return {
|
|
2317
|
+
read: false,
|
|
2318
|
+
why: `The run time of the caller for ${product} has no citation.`
|
|
2319
|
+
};
|
|
2320
|
+
return hoursOf(run, cell, `the caller for ${product}`);
|
|
2321
|
+
}
|
|
2322
|
+
if (!("amount" in facts.run)) return {
|
|
2323
|
+
read: false,
|
|
2324
|
+
why: `The catalog gives no run time for ${product}: ${facts.run.why}`
|
|
2325
|
+
};
|
|
2326
|
+
return hoursOf(facts.run, cell, `the catalog for ${product}`);
|
|
2327
|
+
}
|
|
2328
|
+
/**
|
|
2329
|
+
* This function gives the device fragment of an endurance layer. Each device of the buy list with a cited run time gives
|
|
2330
|
+
* one converter. One run takes one cell and gives the hours of the need for each cell. The limit of runs for each day is
|
|
2331
|
+
* `HOURS_IN_DAY` divided by those hours. Thus one device gives 24 hours of its need in a day or less. The count of
|
|
2332
|
+
* devices is the count of whole units of the product. A device with no cited run time gives no converter, and a no read.
|
|
2333
|
+
*
|
|
2334
|
+
* With `draws`, each need of a device gives one draw. Its rate is the daily rate of the need in its unit for each day. The users are 1
|
|
2335
|
+
* for a need of the household. A need with no read of its rate gives no draw, and a no read.
|
|
2336
|
+
*
|
|
2337
|
+
* @param input - The catalog, the counts of the buy list, the run times of the caller and the parts and draws
|
|
2338
|
+
* @throws RangeError for a device whose cells are not a resource of the catalog
|
|
2339
|
+
*/
|
|
2340
|
+
function deviceFragment(input) {
|
|
2341
|
+
const { catalog, units } = input;
|
|
2342
|
+
const prefix = input.prefix ?? "device";
|
|
2343
|
+
const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));
|
|
2344
|
+
const lines = [];
|
|
2345
|
+
const noReads = [];
|
|
2346
|
+
const converters = [];
|
|
2347
|
+
const resources = [];
|
|
2348
|
+
const needs = [];
|
|
2349
|
+
const needList = input.needs ?? DAILY_NEEDS;
|
|
2350
|
+
for (const [id, count] of Object.entries(units)) {
|
|
2351
|
+
const facts = catalog.products.find((each) => each.id === id)?.device;
|
|
2352
|
+
if (facts === void 0 || !(count > 0)) continue;
|
|
2353
|
+
const cell = unitOf.get(facts.battery);
|
|
2354
|
+
if (cell === void 0) throw new RangeError(`The device ${id} runs on "${facts.battery}", and the catalog has no such resource.`);
|
|
2355
|
+
const devices = Math.floor(count);
|
|
2356
|
+
const hours = deviceHours(facts, input.runs?.[id], cell, id);
|
|
2357
|
+
lines.push({
|
|
2358
|
+
product: id,
|
|
2359
|
+
need: facts.need,
|
|
2360
|
+
battery: facts.battery,
|
|
2361
|
+
devices,
|
|
2362
|
+
hours
|
|
2363
|
+
});
|
|
2364
|
+
if (devices < 1) noReads.push({
|
|
2365
|
+
product: id,
|
|
2366
|
+
why: `The buy list has ${count} of ${id}, less than one whole device.`
|
|
2367
|
+
});
|
|
2368
|
+
else if (!hours.read) noReads.push({
|
|
2369
|
+
product: id,
|
|
2370
|
+
why: hours.why
|
|
2371
|
+
});
|
|
2372
|
+
else {
|
|
2373
|
+
const unit = needList.find((each) => each.code === facts.need)?.unit ?? "h";
|
|
2374
|
+
const gift = amountIn(hours.value, "h", unit);
|
|
2375
|
+
if (gift === void 0) {
|
|
2376
|
+
noReads.push({
|
|
2377
|
+
product: id,
|
|
2378
|
+
why: `The need ${facts.need} is in ${unit}, and that is not a time.`
|
|
2379
|
+
});
|
|
2380
|
+
if (!needs.includes(facts.need)) needs.push(facts.need);
|
|
2381
|
+
continue;
|
|
2382
|
+
}
|
|
2383
|
+
const part = input.parts?.[id];
|
|
2384
|
+
converters.push({
|
|
2385
|
+
id: `${prefix}:${id}`,
|
|
2386
|
+
...part === void 0 ? {} : { device: part },
|
|
2387
|
+
takes: [{
|
|
2388
|
+
resource: facts.battery,
|
|
2389
|
+
amount: 1
|
|
2390
|
+
}],
|
|
2391
|
+
gives: {
|
|
2392
|
+
need: facts.need,
|
|
2393
|
+
amount: gift
|
|
2394
|
+
},
|
|
2395
|
+
perDay: HOURS_IN_DAY / hours.value,
|
|
2396
|
+
devices
|
|
2397
|
+
});
|
|
2398
|
+
if (!resources.some((each) => each.code === facts.battery)) resources.push({
|
|
2399
|
+
code: facts.battery,
|
|
2400
|
+
unit: cell
|
|
2401
|
+
});
|
|
2402
|
+
}
|
|
2403
|
+
if (!needs.includes(facts.need)) needs.push(facts.need);
|
|
2404
|
+
}
|
|
2405
|
+
const draws = [];
|
|
2406
|
+
if (input.draws !== void 0) {
|
|
2407
|
+
const { level, supply } = input.draws;
|
|
2408
|
+
for (const code of needs) {
|
|
2409
|
+
const need = needList.find((each) => each.code === code);
|
|
2410
|
+
if (need === void 0) noReads.push({
|
|
2411
|
+
need: code,
|
|
2412
|
+
why: `The daily needs have no need ${code}.`
|
|
2413
|
+
});
|
|
2414
|
+
else if (!need.rate.read) noReads.push({
|
|
2415
|
+
need: code,
|
|
2416
|
+
why: need.rate.why
|
|
2417
|
+
});
|
|
2418
|
+
else {
|
|
2419
|
+
const perDay = amountIn(need.rate.perDay.value, need.rate.perDay.unit, `${need.unit}/d`);
|
|
2420
|
+
if (perDay === void 0 || !(perDay > 0)) noReads.push({
|
|
2421
|
+
need: code,
|
|
2422
|
+
why: `The daily rate of ${code} is not an amount in ${need.unit} for each day above 0.`
|
|
2423
|
+
});
|
|
2424
|
+
else if (need.users !== "household") noReads.push({
|
|
2425
|
+
need: code,
|
|
2426
|
+
why: `The need ${code} is for each person. The device fragment has no count of persons.`
|
|
2427
|
+
});
|
|
2428
|
+
else draws.push({
|
|
2429
|
+
need: code,
|
|
2430
|
+
level,
|
|
2431
|
+
perDay,
|
|
2432
|
+
users: 1,
|
|
2433
|
+
supply
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
return {
|
|
2439
|
+
layer: {
|
|
2440
|
+
schema: "endurance/1",
|
|
2441
|
+
levels: input.draws === void 0 ? [] : [input.draws.level],
|
|
2442
|
+
resources,
|
|
2443
|
+
stores: [],
|
|
2444
|
+
draws,
|
|
2445
|
+
converters
|
|
2446
|
+
},
|
|
2447
|
+
lines,
|
|
2448
|
+
noReads,
|
|
2449
|
+
read: noReads.length === 0
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
// src/light.ts
|
|
2453
|
+
/** The page "Position of the Sun" of Wikipedia: the formulas of the place of the sun that `sunDay` of `@mark1russell7/geo` uses. */
|
|
2454
|
+
const SUN_POSITION_SOURCE = {
|
|
2455
|
+
id: "wikipedia-position-of-the-sun",
|
|
2456
|
+
title: "Position of the Sun",
|
|
2457
|
+
url: "https://en.wikipedia.org/w/index.php?title=Position_of_the_Sun&oldid=1386341289",
|
|
2458
|
+
license: "cc-by-sa-4.0",
|
|
2459
|
+
checked: "2026-11-24",
|
|
2460
|
+
by: "Wikipedia contributors",
|
|
2461
|
+
terms: "https://foundation.wikimedia.org/wiki/Policy:Terms_of_Use"
|
|
2462
|
+
};
|
|
2463
|
+
/** The page "Sunrise equation" of Wikipedia: the hour angle of the sunrise and the sunset that `sunDay` of `@mark1russell7/geo` uses. */
|
|
2464
|
+
const SUNRISE_EQUATION_SOURCE = {
|
|
2465
|
+
id: "wikipedia-sunrise-equation",
|
|
2466
|
+
title: "Sunrise equation",
|
|
2467
|
+
url: "https://en.wikipedia.org/w/index.php?title=Sunrise_equation&oldid=1379585755",
|
|
2468
|
+
license: "cc-by-sa-4.0",
|
|
2469
|
+
checked: "2026-11-24",
|
|
2470
|
+
by: "Wikipedia contributors",
|
|
2471
|
+
terms: "https://foundation.wikimedia.org/wiki/Policy:Terms_of_Use"
|
|
2472
|
+
};
|
|
2473
|
+
/** The most days of one calculation of the light hours: three years. */
|
|
2474
|
+
const MAX_LIGHT_DAYS = 1096;
|
|
2475
|
+
const HOUR_MS = 36e5;
|
|
2476
|
+
const DAY_MS = 864e5;
|
|
2477
|
+
/** This function gives the instant of the start of a local date, or throws a RangeError. */
|
|
2478
|
+
function startOf(date, zone) {
|
|
2479
|
+
const [year, month, day] = date.split("-").map(Number);
|
|
2480
|
+
const at = firstInstantOf(Date.UTC(year, month - 1, day), zone);
|
|
2481
|
+
if (at === void 0) throw new RangeError(`The date ${date} has no start in the time zone "${zone}".`);
|
|
2482
|
+
return at;
|
|
2483
|
+
}
|
|
2484
|
+
/** This function gives the awake spans of the window in one local day. */
|
|
2485
|
+
function awakeSpans(dayStart, dayEnd, window) {
|
|
2486
|
+
const spans = [];
|
|
2487
|
+
let at = dayStart;
|
|
2488
|
+
let open = inWindow(at, window);
|
|
2489
|
+
while (at < dayEnd) {
|
|
2490
|
+
const next = nextBoundary(at, window);
|
|
2491
|
+
const end = next === void 0 ? dayEnd : Math.min(next.at, dayEnd);
|
|
2492
|
+
if (open) spans.push([at, end]);
|
|
2493
|
+
if (next === void 0) break;
|
|
2494
|
+
at = next.at;
|
|
2495
|
+
open = next.opens;
|
|
2496
|
+
}
|
|
2497
|
+
return spans;
|
|
2498
|
+
}
|
|
2499
|
+
/** This function gives the span of light of a sun day. A polar day is light for 24 hours about its solar noon. */
|
|
2500
|
+
function lightSpan(day) {
|
|
2501
|
+
if (day.kind === "rise-set") return [day.rise, day.set];
|
|
2502
|
+
if (day.kind === "polar-day") return [day.noon - DAY_MS / 2, day.noon + DAY_MS / 2];
|
|
2503
|
+
}
|
|
2504
|
+
/** This function joins spans that touch or overlap, in order. */
|
|
2505
|
+
function union(spans) {
|
|
2506
|
+
const sorted = [...spans].sort((a, b) => a[0] - b[0]);
|
|
2507
|
+
const out = [];
|
|
2508
|
+
for (const [start, end] of sorted) {
|
|
2509
|
+
const last = out[out.length - 1];
|
|
2510
|
+
if (last !== void 0 && start <= last[1]) last[1] = Math.max(last[1], end);
|
|
2511
|
+
else out.push([start, end]);
|
|
2512
|
+
}
|
|
2513
|
+
return out;
|
|
2514
|
+
}
|
|
2515
|
+
/** This function gives the length of the common part of two lists of spans, in milliseconds. */
|
|
2516
|
+
function overlap(a, b) {
|
|
2517
|
+
let total = 0;
|
|
2518
|
+
for (const [aStart, aEnd] of a) for (const [bStart, bEnd] of b) total += Math.max(0, Math.min(aEnd, bEnd) - Math.max(aStart, bStart));
|
|
2519
|
+
return total;
|
|
2520
|
+
}
|
|
2521
|
+
/**
|
|
2522
|
+
* This function gives the dark hours of the awake window of a household on each local date of a plan.
|
|
2523
|
+
*
|
|
2524
|
+
* - A local date is the time from its local midnight to the next local midnight. The hours of a window across midnight go to each date by the clock.
|
|
2525
|
+
* - The light is the time from the sunrise to the sunset of `sunDay` of `@mark1russell7/geo`. A polar day is light, and a polar night is dark.
|
|
2526
|
+
* - The dark awake hours of a date are its awake hours minus its awake hours in the light.
|
|
2527
|
+
*
|
|
2528
|
+
* @throws RangeError - The window has a problem, or the date is not a date. Or the count of days is not a whole number from 1 to `MAX_LIGHT_DAYS`.
|
|
2529
|
+
*/
|
|
2530
|
+
function lightHours(input) {
|
|
2531
|
+
const problems = windowProblems(input.awake);
|
|
2532
|
+
if (problems.length > 0) throw new RangeError(problems.join(" "));
|
|
2533
|
+
if (!Number.isInteger(input.days) || input.days < 1 || input.days > 1096) throw new RangeError(`The count of days ${input.days} is not a whole number from 1 to ${MAX_LIGHT_DAYS}.`);
|
|
2534
|
+
if (addDays(input.from, 0) !== input.from) throw new RangeError(`The date ${input.from} is not a date YYYY-MM-DD.`);
|
|
2535
|
+
const options = input.altitudeDeg === void 0 ? {} : { altitudeDeg: input.altitudeDeg };
|
|
2536
|
+
const zone = input.awake.zone;
|
|
2537
|
+
const days = [];
|
|
2538
|
+
for (let index = 0; index < input.days; index++) {
|
|
2539
|
+
const date = addDays(input.from, index);
|
|
2540
|
+
const awake = awakeSpans(startOf(date, zone), startOf(addDays(date, 1), zone), input.awake);
|
|
2541
|
+
const light = [];
|
|
2542
|
+
for (let near = -2; near <= 2; near++) {
|
|
2543
|
+
const span = lightSpan(sunDay(input.point, addDays(date, near), options));
|
|
2544
|
+
if (span !== void 0) light.push(span);
|
|
2545
|
+
}
|
|
2546
|
+
const awakeMs = awake.reduce((sum, [start, end]) => sum + end - start, 0);
|
|
2547
|
+
const darkMs = awakeMs - overlap(awake, union(light));
|
|
2548
|
+
days.push({
|
|
2549
|
+
date,
|
|
2550
|
+
awakeHours: awakeMs / HOUR_MS,
|
|
2551
|
+
darkHours: Math.max(0, darkMs) / HOUR_MS
|
|
2552
|
+
});
|
|
2553
|
+
}
|
|
2554
|
+
return {
|
|
2555
|
+
days,
|
|
2556
|
+
most: Math.max(...days.map((day) => day.darkHours)),
|
|
2557
|
+
mean: days.reduce((sum, day) => sum + day.darkHours, 0) / days.length
|
|
2558
|
+
};
|
|
2559
|
+
}
|
|
2560
|
+
/**
|
|
2561
|
+
* This function gives the need of light of a household from its light hours: the dark awake hours of its worst day.
|
|
2562
|
+
* One light that is on in the dark awake hours is a choice of this model. A household with more lights gives more draws.
|
|
2563
|
+
*/
|
|
2564
|
+
function lightNeed(hours) {
|
|
2565
|
+
return {
|
|
2566
|
+
code: LIGHT_NEED,
|
|
2567
|
+
unit: "h",
|
|
2568
|
+
users: "household",
|
|
2569
|
+
rate: {
|
|
2570
|
+
read: true,
|
|
2571
|
+
perDay: {
|
|
2572
|
+
value: hours.most,
|
|
2573
|
+
unit: "h/d"
|
|
2574
|
+
},
|
|
2575
|
+
sources: [SUN_POSITION_SOURCE, SUNRISE_EQUATION_SOURCE],
|
|
2576
|
+
note: "The sources give the sunrise and the sunset at the point of the home on each date. The awake window of the household is input data. The rate is the dark awake hours of the worst day of the plan. One light that is on in those hours is a choice of this model, not of the sources."
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
export { ACTIVITY_LEVELS, ALERT_WATCH_NEED, BOIL_CELSIUS, BREAST_MILK_MONTHS, CALORIE_CHAIN, CALORIE_SEXES, CALORIE_TABLES, COLD_START_CELSIUS, DAILY_NEEDS, DAILY_NEED_CODES, DGA_CALORIES, DGA_SOURCE, DIRECT_USES, FDC_SR_LEGACY_SOURCE, FOOD_NEED, FORMULA_DRAW_MONTHS, FORMULA_FEEDS, FORMULA_LATER_LEAST, FORMULA_MIX, FORMULA_NEED, FORMULA_POWDER, FORMULA_READY, HOURS_IN_DAY, INFANT_FEEDINGS, INFANT_MONTHS, JOIN_CODES, LIGHT_NEED, MAX_LIGHT_DAYS, MILK_LATER, NASEM_ENERGY_SOURCE, NASEM_INFANT_CALORIES, NEEDS_CODES, NEED_SUPPLIES, NIST_SI_GUIDE_SOURCE, NO_COOK, NWS_ALARMS_SOURCE, NWS_RECEIVERS_SOURCE, STORED_WATER, SUNRISE_EQUATION_SOURCE, SUN_POSITION_SOURCE, USGS_WATER_DENSITY_SOURCE, WARMTH_NEED, WATER_DENSITY_MAX, WATER_DENSITY_MIN, WATER_NEED, WATER_SPECIFIC_HEAT, WIC_INFANT_SOURCE, calorieChange, calorieNeed, calorieRow, calorieRowOf, checkCalorieChain, checkCalorieTable, checkDailyNeeds, checkJoins, cookFragment, deviceFragment, formulaMixCheck, formulaMixFragment, formulaMixWater, hasNeedsError, householdFragment, isActivityLevel, lightHours, lightNeed };
|
|
2276
2581
|
|
|
2277
2582
|
//# sourceMappingURL=index.js.map
|