@mark1russell7/stack-needs 0.9.8 → 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 +16 -2
- package/build/index.d.ts +51 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +132 -2
- package/build/index.js.map +1 -1
- package/package.json +3 -1
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.
|
|
@@ -372,8 +372,22 @@ The gate refuses an empty code and two needs with one code (`daily-need-id`). It
|
|
|
372
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
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
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
|
+
|
|
375
389
|
## The entries
|
|
376
390
|
|
|
377
391
|
| Entry | What it has |
|
|
378
392
|
| --- | --- |
|
|
379
|
-
| `@mark1russell7/stack-needs` | The records, the calorie tables and `CALORIE_CHAIN`, the gates, `calorieNeed`, `householdFragment`, `cookFragment` and its constants, `formulaMixFragment` and `FORMULA_MIX`, `deviceFragment`, the daily needs, 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[];
|
|
@@ -1104,4 +1106,52 @@ export interface DeviceFragmentResult {
|
|
|
1104
1106
|
* @throws RangeError for a device whose cells are not a resource of the catalog
|
|
1105
1107
|
*/
|
|
1106
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;
|
|
1107
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","../src/device.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;;YAGD,wBAAwB;;qBAGvB;;YAGD,qBAAqB;;;;;YAMrB;WAAyB,QAAQ,SAAS,OAAO,eAAe;WAAqB;;WAA4B,MAAM;WAAmB;;;iBAGrI;WACN,KAAK;;WAEL;;WAEA;;WAEA;WACA,MAAM;;;;;;iBAOA;;WAEN;;WAEA;;WAEA,KAAK;;WAEL,QAAQ;;WAER;;WAEA;;;iBAIM;;WAEN;WACA;WACA,QAAQ;;WAER;;WAEA,eAAe;;WAEf,mBAAmB;;;;;;YAOlB,gBAAgB,wBAAwB;;;;;;;;qBASvC;;YAGD,wBAAwB;;iBAGnB;WACN,KAAK;;WAEL;WACA;;WAEA,QAAQ;;WAER;;;;;WAKA,UAAU;;;YAIT;WACG,QAAQ;WAAiB;WAAqB,OAAO;WAAwB;WAAwB;WAAsB;WAAqC,MAAM;;WACtK,QAAQ;WAAiB;WAAsB;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sBAAsB;;;;;;;;;qBAiDtB;;YAGD,wBAAwB;;YAGxB,mBAAmB,QAAQ,gBAAgB;;;;;;;;;wBA4BvC,gBAAgB,gBAAgB,aAAa,UAAU,cAAc;;qBCjJxE;;iBAGI;WACN;WACA;WACA;aAAgB;aAAyB;;;WAEzC;;;iBAIM;WACN;WACA;;;iBAIM;;WAEN,SAAS;;WAET,OAAO,SAAS;;;;;WAKhB,OAAO,SAAS,eAAe;;WAE/B,QAAQ,SAAS;;WAEjB,QAAQ;;WAER,iBAAiB;;WAEjB;;;YAIC;WAAwB;WAAqB;WAAwB;;WAA4B;WAAsB;;;iBAGlH;WACN;;WAEA;;WAEA;;WAEA;;WAEA,OAAO;;;iBAID,wBAAwB;WAC9B;WACA;;;iBAIM;;WAEN;WACA;WACA,oBAAoB;WACpB;WACA,gBAAgB;WAChB,qBAAqB;;;YAIpB;WAA0B;WAA0B;WAAuB;;WAA2B;WAAuB;WAA0B;;;iBAGlJ;WACN,OAAO;;WAEP,gBAAgB;;WAEhB,kBAAkB;;WAElB;;;;;;;;;;;;;;wBA4CK,eAAe,OAAO,sBAAsB;;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 = [
|
|
@@ -2447,6 +2449,134 @@ function deviceFragment(input) {
|
|
|
2447
2449
|
read: noReads.length === 0
|
|
2448
2450
|
};
|
|
2449
2451
|
}
|
|
2450
|
-
|
|
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 };
|
|
2451
2581
|
|
|
2452
2582
|
//# sourceMappingURL=index.js.map
|