@mark1russell7/stack-needs 0.8.0 → 0.8.2
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 +83 -3
- package/build/index.d.ts +250 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +473 -3
- package/build/index.js.map +1 -1
- package/package.json +3 -3
package/build/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { quantity, valueIn } from "@mark1russell7/quantity";
|
|
2
2
|
import { checkSources } from "@mark1russell7/guidebook";
|
|
3
|
-
import { buyListEnergy, giftsOf } from "@mark1russell7/market/supplies";
|
|
3
|
+
import { buyListEnergy, cookWater, fuelEnergyPerMass, giftsOf } from "@mark1russell7/market/supplies";
|
|
4
4
|
// src/calorie.ts
|
|
5
5
|
/** The activity levels of the table, as the source names them: sedentary, moderately active and active. */
|
|
6
6
|
const ACTIVITY_LEVELS = [
|
|
@@ -1215,7 +1215,7 @@ function layerResources(catalog, stores, uses) {
|
|
|
1215
1215
|
* `food.no-cook` feeds the food draw, and `food.infant-formula-ready` feeds the formula draw.
|
|
1216
1216
|
* - The resources are the resources of the stores and of the direct uses, with the units of the catalog.
|
|
1217
1217
|
* - The supply part of each draw is `supply`. Its default is the part of `NEED_SUPPLIES` for the need of the draw.
|
|
1218
|
-
* - The fragment has no converter.
|
|
1218
|
+
* - The fragment has no converter. `cookFragment` gives the converters for the dry food, with the water and the fuel of each pot.
|
|
1219
1219
|
*
|
|
1220
1220
|
* A person with no row in the tables gives no layer, because a low rate gives too many days. The default tables give a row for each age.
|
|
1221
1221
|
* The option `noRow: "leave-out"` leaves those persons out of the draw. A draw of 0 kcal gives no layer.
|
|
@@ -1378,6 +1378,476 @@ function makesMilk(tables, person) {
|
|
|
1378
1378
|
if (stage === void 0) return false;
|
|
1379
1379
|
return ("rows" in tables ? [tables] : tables).some((table) => calorieChange(table, person.sex, stage)?.milk === true);
|
|
1380
1380
|
}
|
|
1381
|
-
|
|
1381
|
+
// src/cook.ts
|
|
1382
|
+
/** The source of the specific heat of water: the NIST Guide to the SI (Special Publication 811). It is a work of the United States federal government. */
|
|
1383
|
+
const NIST_SI_GUIDE_SOURCE = {
|
|
1384
|
+
id: "nist-sp-811",
|
|
1385
|
+
title: "NIST Guide to the SI (Special Publication 811), Appendix B.8 and footnotes",
|
|
1386
|
+
url: "https://www.nist.gov/pml/special-publication-811/nist-guide-si-appendix-b-conversion-factors/nist-guide-si-appendix-b8",
|
|
1387
|
+
license: "us-public-domain",
|
|
1388
|
+
checked: "2026-11-24",
|
|
1389
|
+
by: "National Institute of Standards and Technology",
|
|
1390
|
+
terms: "https://www.nist.gov/oism/copyrights",
|
|
1391
|
+
note: "The footnotes are at https://www.nist.gov/pml/special-publication-811/nist-guide-si-footnotes."
|
|
1392
|
+
};
|
|
1393
|
+
/** The source of the density of water: the page Water Density of the USGS Water Science School. It is a work of the United States federal government. */
|
|
1394
|
+
const USGS_WATER_DENSITY_SOURCE = {
|
|
1395
|
+
id: "usgs-water-density",
|
|
1396
|
+
title: "Water Density, USGS Water Science School",
|
|
1397
|
+
url: "https://www.usgs.gov/special-topics/water-science-school/science/water-density",
|
|
1398
|
+
license: "us-public-domain",
|
|
1399
|
+
checked: "2026-11-24",
|
|
1400
|
+
by: "U.S. Geological Survey",
|
|
1401
|
+
terms: "https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits"
|
|
1402
|
+
};
|
|
1403
|
+
/**
|
|
1404
|
+
* The mean specific heat of liquid water from 0 °C to 100 °C: 4.19002 kJ/(kg.K).
|
|
1405
|
+
* The NIST Guide to the SI gives 4.190 02 J for the calorie (mean). The common definition of that calorie is the mean over this range.
|
|
1406
|
+
* SP 811 does not state the range. Its footnote 10 tells that the calorie is the energy to raise 1 g of water
|
|
1407
|
+
* by 1 kelvin. For the default start (0 °C), the value is the mean of the rise. For a warmer start, the mean of the
|
|
1408
|
+
* rise can be a little higher. The model also heats the dry food with this value, above the specific heat of a dry food.
|
|
1409
|
+
* That term holds the heat of the pot above the true value.
|
|
1410
|
+
*/
|
|
1411
|
+
const WATER_SPECIFIC_HEAT = {
|
|
1412
|
+
value: 4.19002,
|
|
1413
|
+
unit: "kJ/(kg.K)",
|
|
1414
|
+
source: NIST_SI_GUIDE_SOURCE,
|
|
1415
|
+
locator: "Appendix B.8, row calorie (mean): 4.190 02 E+00 J. Footnotes, footnote 10: the energy to raise 1 gram of water by 1 °C.",
|
|
1416
|
+
note: "The calorie (mean) in joules, for 1 g of water and 1 K. By its common definition, the mean is over the range from 0 °C to 100 °C. SP 811 does not state the range."
|
|
1417
|
+
};
|
|
1418
|
+
/**
|
|
1419
|
+
* The largest density of liquid water: 1 kg/L. The USGS table gives 1.00000 g/cm3 at 4.0 °C, its largest value.
|
|
1420
|
+
* Thus 1 L of cook water is 1 kg or less.
|
|
1421
|
+
*/
|
|
1422
|
+
const WATER_DENSITY_MAX = {
|
|
1423
|
+
value: 1,
|
|
1424
|
+
unit: "kg/L",
|
|
1425
|
+
source: USGS_WATER_DENSITY_SOURCE,
|
|
1426
|
+
locator: "Table of the density and the weight of water by temperature, row 39.2 °F/4.0 °C: 1.00000 g/cm3",
|
|
1427
|
+
note: "The largest density of the table, from 0 °C to 100 °C. Each other row is less."
|
|
1428
|
+
};
|
|
1429
|
+
/**
|
|
1430
|
+
* The temperature at the end of the heat to boil, in °C.
|
|
1431
|
+
* Water boils at a lower temperature at a high place. Then the heat is less.
|
|
1432
|
+
* But the cook time is longer there, and the model does not give that time. Thus at a high place the fuel is not an upper limit.
|
|
1433
|
+
*/
|
|
1434
|
+
const BOIL_CELSIUS = 100;
|
|
1435
|
+
/**
|
|
1436
|
+
* The default start temperature of the cook water, in °C: 0, the freezing point. Liquid water at the pressure of the sea is
|
|
1437
|
+
* not colder. Thus the default gives the most heat. A caller gives a warmer start with its citation.
|
|
1438
|
+
*/
|
|
1439
|
+
const COLD_START_CELSIUS = 0;
|
|
1440
|
+
/** This function gives the value of an amount in a unit, or `undefined` when the units do not convert. */
|
|
1441
|
+
function inUnit(value, from, to) {
|
|
1442
|
+
try {
|
|
1443
|
+
const out = valueIn({
|
|
1444
|
+
value,
|
|
1445
|
+
unit: from
|
|
1446
|
+
}, to);
|
|
1447
|
+
return Number.isFinite(out) ? out : void 0;
|
|
1448
|
+
} catch {
|
|
1449
|
+
return;
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
/** This function gives the fuel rate of a stove in `kJ/min` or `kg/min`. It gives `undefined` for a rate that is not an energy or a mass in a time. */
|
|
1453
|
+
function stoveRate(rate) {
|
|
1454
|
+
const minutes = inUnit(rate.per.amount, rate.per.unit, "min");
|
|
1455
|
+
if (minutes === void 0 || !(minutes > 0)) return void 0;
|
|
1456
|
+
const energy = inUnit(rate.amount, rate.unit, "kJ");
|
|
1457
|
+
if (energy !== void 0) return {
|
|
1458
|
+
kind: "energy",
|
|
1459
|
+
perMin: energy / minutes
|
|
1460
|
+
};
|
|
1461
|
+
const mass = inUnit(rate.amount, rate.unit, "kg");
|
|
1462
|
+
if (mass !== void 0) return {
|
|
1463
|
+
kind: "mass",
|
|
1464
|
+
perMin: mass / minutes
|
|
1465
|
+
};
|
|
1466
|
+
}
|
|
1467
|
+
const read = (value, unit) => ({
|
|
1468
|
+
read: true,
|
|
1469
|
+
value,
|
|
1470
|
+
unit
|
|
1471
|
+
});
|
|
1472
|
+
const noRead = (why) => ({
|
|
1473
|
+
read: false,
|
|
1474
|
+
why
|
|
1475
|
+
});
|
|
1476
|
+
/**
|
|
1477
|
+
* This function gives the cook line of one dry food. Each missing fact gives a no read with its reason.
|
|
1478
|
+
* The fuel is a safe upper limit: the stove burns at its full rate for the boil time and the cook time.
|
|
1479
|
+
* At a high place the cook time is longer. The model does not give that time, so there the fuel is not an upper limit.
|
|
1480
|
+
*/
|
|
1481
|
+
function cookLine(product, resource, perUnitKg, foodGifts, context) {
|
|
1482
|
+
const { stove, batchKg, share, startC, fuelEnergy } = context;
|
|
1483
|
+
let energy;
|
|
1484
|
+
if (foodGifts > 1) energy = noRead(`The product ${product.id} gives ${String(foodGifts)} foods. The catalog gives one energy for the whole product, not the energy of each food.`);
|
|
1485
|
+
else if (product.energy === void 0) energy = noRead(`The product ${product.id} has no food energy in the catalog.`);
|
|
1486
|
+
else if (!product.energy.read) energy = noRead(`The food energy of the product ${product.id} is a no read: ${product.energy.why}`);
|
|
1487
|
+
else {
|
|
1488
|
+
const kcal = inUnit(product.energy.amount, product.energy.unit, "kcal");
|
|
1489
|
+
if (kcal === void 0) energy = noRead(`The food energy of the product ${product.id} is in ${product.energy.unit}, which does not convert to kcal.`);
|
|
1490
|
+
else if (perUnitKg === void 0 || !(perUnitKg > 0)) energy = noRead(`The gift of ${resource} of the product ${product.id} has no read in kg.`);
|
|
1491
|
+
else energy = read(kcal / perUnitKg, "kcal/kg");
|
|
1492
|
+
}
|
|
1493
|
+
const litres = cookWater(product);
|
|
1494
|
+
const water = litres === void 0 ? noRead(`The catalog cites no cook water for the product ${product.id}, or no bulk mass for its water rate.`) : read(valueIn(litres, "L/kg"), "L/kg");
|
|
1495
|
+
const heat = water.read ? read((water.value * WATER_DENSITY_MAX.value + 1) * batchKg * WATER_SPECIFIC_HEAT.value * (100 - startC), "kJ") : noRead(`The heat to boil is a no read: ${water.why}`);
|
|
1496
|
+
const why = [];
|
|
1497
|
+
if (!heat.read) why.push(heat.why);
|
|
1498
|
+
const time = product.cook?.time;
|
|
1499
|
+
const cookMin = time === void 0 ? void 0 : inUnit(time.high, time.unit, "min");
|
|
1500
|
+
if (time === void 0) why.push(`The catalog cites no cook time for the product ${product.id}.`);
|
|
1501
|
+
else if (cookMin === void 0) why.push(`The cook time of the product ${product.id} is in ${time.unit}, which does not convert to min.`);
|
|
1502
|
+
const rate = stove.rate === void 0 ? void 0 : stoveRate(stove.rate);
|
|
1503
|
+
if (stove.rate === void 0) why.push(`The stove of ${stove.fuel} has no cited fuel rate.`);
|
|
1504
|
+
else if (rate === void 0) why.push(`The fuel rate of the stove is in ${stove.rate.unit} for each ${stove.rate.per.unit}, which is not an energy or a mass in a time.`);
|
|
1505
|
+
let potPerMin;
|
|
1506
|
+
if (share === void 0) why.push("No cited stove share gives the part of the stove heat that goes into the pot. Thus the fuel of the boil is a no read.");
|
|
1507
|
+
else if (rate !== void 0) {
|
|
1508
|
+
if (rate.kind === "energy") {
|
|
1509
|
+
if (stove.heating !== share.heating) why.push(`The stove share is for the ${share.heating} heating value, and the stove rate is for the ${String(stove.heating ?? "unknown")} heating value.`);
|
|
1510
|
+
else potPerMin = rate.perMin * share.value;
|
|
1511
|
+
} else if (fuelEnergy === void 0) why.push(`The fuel ${stove.fuel} has no cited energy, so its mass rate gives no heat for the boil.`);
|
|
1512
|
+
else if (fuelEnergy.heating !== share.heating) why.push(`The stove share is for the ${share.heating} heating value, and the energy of the fuel ${stove.fuel} is the ${fuelEnergy.heating} value.`);
|
|
1513
|
+
else potPerMin = rate.perMin * fuelEnergy.perKg * share.value;
|
|
1514
|
+
}
|
|
1515
|
+
let fuelPerMin;
|
|
1516
|
+
if (rate?.kind === "mass") fuelPerMin = rate.perMin;
|
|
1517
|
+
else if (rate?.kind === "energy") {
|
|
1518
|
+
if (fuelEnergy === void 0) why.push(`The fuel ${stove.fuel} has no cited energy, so the energy rate of the stove gives no fuel mass.`);
|
|
1519
|
+
else if (stove.heating === void 0) why.push("The energy rate of the stove has no heating value.");
|
|
1520
|
+
else if (stove.heating !== fuelEnergy.heating) why.push(`The stove rate is for the ${stove.heating} heating value, and the energy of the fuel ${stove.fuel} is the ${fuelEnergy.heating} value.`);
|
|
1521
|
+
else fuelPerMin = rate.perMin / fuelEnergy.perKg;
|
|
1522
|
+
}
|
|
1523
|
+
if (why.length > 0 || !heat.read || cookMin === void 0 || potPerMin === void 0 || fuelPerMin === void 0 || !(potPerMin > 0)) {
|
|
1524
|
+
const text = why.join(" ");
|
|
1525
|
+
return {
|
|
1526
|
+
product: product.id,
|
|
1527
|
+
resource,
|
|
1528
|
+
energy,
|
|
1529
|
+
water,
|
|
1530
|
+
heat,
|
|
1531
|
+
minutes: noRead(text),
|
|
1532
|
+
fuel: noRead(text)
|
|
1533
|
+
};
|
|
1534
|
+
}
|
|
1535
|
+
const minutes = heat.value / potPerMin + cookMin;
|
|
1536
|
+
return {
|
|
1537
|
+
product: product.id,
|
|
1538
|
+
resource,
|
|
1539
|
+
energy,
|
|
1540
|
+
water,
|
|
1541
|
+
heat,
|
|
1542
|
+
minutes: read(minutes, "min"),
|
|
1543
|
+
fuel: read(minutes * fuelPerMin, "kg")
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
/** This function gives the stove facts of the input: the facts of the caller, or the facts of a product of the catalog. */
|
|
1547
|
+
function stoveOf(catalog, stove) {
|
|
1548
|
+
if (typeof stove !== "string") return stove;
|
|
1549
|
+
const product = catalog.products.find((item) => item.id === stove);
|
|
1550
|
+
if (product === void 0) throw new RangeError(`The catalog has no product "${stove}".`);
|
|
1551
|
+
if (product.stove === void 0) throw new RangeError(`The product "${stove}" has no stove facts.`);
|
|
1552
|
+
return product.stove;
|
|
1553
|
+
}
|
|
1554
|
+
/** This function tells if a resource of the catalog is a food. */
|
|
1555
|
+
function isFood(catalog, code) {
|
|
1556
|
+
return catalog.resources.find((item) => item.code === code)?.kind === "food";
|
|
1557
|
+
}
|
|
1558
|
+
/** This function tells if a resource of the catalog is a dry food: a food resource in a unit of mass. */
|
|
1559
|
+
function isDryFood(catalog, code) {
|
|
1560
|
+
const resource = catalog.resources.find((item) => item.code === code);
|
|
1561
|
+
return resource !== void 0 && resource.kind === "food" && inUnit(1, resource.unit, "kg") !== void 0;
|
|
1562
|
+
}
|
|
1563
|
+
/**
|
|
1564
|
+
* This function gives the converters that cook the dry food of a buy list, with the water and the fuel of each pot.
|
|
1565
|
+
*
|
|
1566
|
+
* - One run of a converter is one pot of `batch`. It takes the dry food, the cook water from `water.stored` and the fuel of the stove.
|
|
1567
|
+
* It gives the food energy of the pot to the need `food.energy`. Thus a dry food with no fuel or no water gives no meal.
|
|
1568
|
+
* - The cook water is `cookWater` of market times the dry mass. It is the resource of the drinking water.
|
|
1569
|
+
* - The heat to boil is the mass of the water and the dry food times `WATER_SPECIFIC_HEAT` times the rise from the start to `BOIL_CELSIUS`.
|
|
1570
|
+
* The water mass takes `WATER_DENSITY_MAX`. The dry food takes the specific heat of water, which is higher than its own.
|
|
1571
|
+
* - The boil time is the heat divided by the stove rate times the share. The time of the stove is the boil time plus the high end of the cook time.
|
|
1572
|
+
* - The fuel is a safe upper limit: the stove burns at its full rate for all of that time. At a high place the cook time is longer.
|
|
1573
|
+
* The model does not give that time, so there the fuel is not an upper limit.
|
|
1574
|
+
* - A rate in a mass gives the fuel directly. A rate in an energy gives a mass only through the cited energy of the fuel, with the same heating value.
|
|
1575
|
+
*
|
|
1576
|
+
* A dry food is a gift of a food resource in a unit of mass. Each missing fact gives a line with no read and its reasons, not a figure.
|
|
1577
|
+
* Two products of the list can give one dry resource, for example rice and oats. The converter then takes the worst case of their lines:
|
|
1578
|
+
* the most water, the most fuel and the least food energy. When a line of the resource has no read, the resource has no converter.
|
|
1579
|
+
* A store of the resource from a different fragment gets the converter of this list.
|
|
1580
|
+
*
|
|
1581
|
+
* The catalog of market gives no soak water. A food that needs a soak, for example dry beans, has a second water draw that this function does not give.
|
|
1582
|
+
* A product that gives more than one food has no energy for each food, so its energy is a no read.
|
|
1583
|
+
*
|
|
1584
|
+
* The cook water is `water.stored`, the store of the drinking water. A drinking draw at a higher level of the same store takes
|
|
1585
|
+
* its water first, by the take order of `enduranceOf`. The drinking draw keeps back its days times its demand, which is all of the store.
|
|
1586
|
+
* Thus, when a case cuts the water supply, the dry food adds 0 days at each amount of stored water.
|
|
1587
|
+
*
|
|
1588
|
+
* The function is pure.
|
|
1589
|
+
*
|
|
1590
|
+
* @param input - The catalog and the buy list, the stove, the dry mass of one pot, the share and the start temperature
|
|
1591
|
+
* @returns The fragment, the line of each dry food and the dry resources with no converter
|
|
1592
|
+
* @throws RangeError when the batch is not a mass above 0, or when the share is not above 0 and up to 1
|
|
1593
|
+
* @throws RangeError when the start is not from 0 up to less than 100 °C
|
|
1594
|
+
* @throws RangeError when the stove is a product with no stove facts
|
|
1595
|
+
* @throws RangeError when the catalog has no product of an `id` of the buy list
|
|
1596
|
+
* @throws RangeError when the catalog has no resource of the fuel in a unit of mass
|
|
1597
|
+
* @throws RangeError when a converter has a read and the catalog has no resource `water.stored` in a unit of volume
|
|
1598
|
+
* @throws RangeError for the errors of `giftsOf`
|
|
1599
|
+
*/
|
|
1600
|
+
function cookFragment(input) {
|
|
1601
|
+
const { catalog, units } = input;
|
|
1602
|
+
const batchKg = inUnit(input.batch.value, input.batch.unit, "kg");
|
|
1603
|
+
if (batchKg === void 0 || !(batchKg > 0)) throw new RangeError(`The batch ${String(input.batch.value)} ${input.batch.unit} is not a mass above 0.`);
|
|
1604
|
+
const { share } = input;
|
|
1605
|
+
if (share !== void 0 && !(share.value > 0 && share.value <= 1)) throw new RangeError(`The stove share is ${String(share.value)}. It must be above 0 and up to 1.`);
|
|
1606
|
+
const startC = input.start?.celsius ?? 0;
|
|
1607
|
+
if (!(startC >= 0 && startC < 100)) throw new RangeError(`The start temperature is ${String(startC)} °C. It must be from 0 up to less than ${String(100)} °C.`);
|
|
1608
|
+
const stove = stoveOf(catalog, input.stove);
|
|
1609
|
+
const fuel = catalog.resources.find((resource) => resource.code === stove.fuel);
|
|
1610
|
+
const fuelUnitPerKg = fuel === void 0 ? void 0 : inUnit(1, "kg", fuel.unit);
|
|
1611
|
+
if (fuel === void 0 || fuelUnitPerKg === void 0) throw new RangeError(`The catalog has no resource "${stove.fuel}" in a unit of mass for the fuel of the stove.`);
|
|
1612
|
+
const perKg = fuelEnergyPerMass(fuel);
|
|
1613
|
+
const context = {
|
|
1614
|
+
stove,
|
|
1615
|
+
batchKg,
|
|
1616
|
+
share,
|
|
1617
|
+
startC,
|
|
1618
|
+
fuelEnergy: perKg === void 0 || fuel.fuelEnergy === void 0 ? void 0 : {
|
|
1619
|
+
perKg: valueIn(perKg, "kJ/kg"),
|
|
1620
|
+
heating: fuel.fuelEnergy.heating
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));
|
|
1624
|
+
const lines = [];
|
|
1625
|
+
for (const [id, count] of Object.entries(units)) {
|
|
1626
|
+
if (!(count > 0)) continue;
|
|
1627
|
+
const product = catalog.products.find((item) => item.id === id);
|
|
1628
|
+
if (product === void 0) throw new RangeError(`The catalog has no product "${id}".`);
|
|
1629
|
+
if (product.kind !== "food") continue;
|
|
1630
|
+
const gifts = giftsOf(catalog, id, 1);
|
|
1631
|
+
const foodGifts = gifts.filter((gift) => isFood(catalog, gift.resource)).length;
|
|
1632
|
+
for (const gift of gifts) {
|
|
1633
|
+
if (!isDryFood(catalog, gift.resource)) continue;
|
|
1634
|
+
const perUnitKg = gift.read ? inUnit(gift.amount, gift.unit, "kg") : void 0;
|
|
1635
|
+
lines.push(cookLine(product, gift.resource, perUnitKg, foodGifts, context));
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
const prefix = input.prefix ?? "cook";
|
|
1639
|
+
const converters = [];
|
|
1640
|
+
const noReads = [];
|
|
1641
|
+
for (const resource of [...new Set(lines.map((line) => line.resource))]) {
|
|
1642
|
+
const own = lines.filter((line) => line.resource === resource);
|
|
1643
|
+
const why = own.flatMap((line) => [
|
|
1644
|
+
line.energy,
|
|
1645
|
+
line.water,
|
|
1646
|
+
line.fuel
|
|
1647
|
+
].flatMap((value) => value.read ? [] : [`${line.product}: ${value.why}`]));
|
|
1648
|
+
if (why.length > 0) {
|
|
1649
|
+
noReads.push({
|
|
1650
|
+
resource,
|
|
1651
|
+
why: [...new Set(why)].join(" ")
|
|
1652
|
+
});
|
|
1653
|
+
continue;
|
|
1654
|
+
}
|
|
1655
|
+
const most = (pick) => Math.max(...own.map((line) => valueOf(pick(line))));
|
|
1656
|
+
const least = (pick) => Math.min(...own.map((line) => valueOf(pick(line))));
|
|
1657
|
+
const dryPerKg = inUnit(1, "kg", unitOf.get(resource) ?? "") ?? 1;
|
|
1658
|
+
const waterPerL = inUnit(1, "L", unitOf.get("water.stored") ?? "");
|
|
1659
|
+
if (waterPerL === void 0) throw new RangeError(`The catalog has no resource "${STORED_WATER}" in a unit of volume for the cook water.`);
|
|
1660
|
+
converters.push({
|
|
1661
|
+
id: `${prefix}:${resource}`,
|
|
1662
|
+
...input.device === void 0 ? {} : { device: input.device },
|
|
1663
|
+
takes: [
|
|
1664
|
+
{
|
|
1665
|
+
resource,
|
|
1666
|
+
amount: batchKg * dryPerKg
|
|
1667
|
+
},
|
|
1668
|
+
{
|
|
1669
|
+
resource: STORED_WATER,
|
|
1670
|
+
amount: most((line) => line.water) * batchKg * waterPerL
|
|
1671
|
+
},
|
|
1672
|
+
{
|
|
1673
|
+
resource: stove.fuel,
|
|
1674
|
+
amount: most((line) => line.fuel) * fuelUnitPerKg
|
|
1675
|
+
}
|
|
1676
|
+
],
|
|
1677
|
+
gives: {
|
|
1678
|
+
need: FOOD_NEED,
|
|
1679
|
+
amount: least((line) => line.energy) * batchKg
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
}
|
|
1683
|
+
return {
|
|
1684
|
+
layer: {
|
|
1685
|
+
schema: "endurance/1",
|
|
1686
|
+
levels: [],
|
|
1687
|
+
resources: [...new Set(converters.flatMap((converter) => converter.takes.map((take) => take.resource)))].map((code) => ({
|
|
1688
|
+
code,
|
|
1689
|
+
unit: unitOf.get(code) ?? ""
|
|
1690
|
+
})),
|
|
1691
|
+
stores: [],
|
|
1692
|
+
draws: [],
|
|
1693
|
+
converters
|
|
1694
|
+
},
|
|
1695
|
+
lines,
|
|
1696
|
+
noReads,
|
|
1697
|
+
read: noReads.length === 0
|
|
1698
|
+
};
|
|
1699
|
+
}
|
|
1700
|
+
/** This function gives the value of a read. The caller tests the read first. */
|
|
1701
|
+
function valueOf(value) {
|
|
1702
|
+
return value.read ? value.value : NaN;
|
|
1703
|
+
}
|
|
1704
|
+
// src/daily.ts
|
|
1705
|
+
/** The code of the need of light to see in the dark in a home, in hours. */
|
|
1706
|
+
const LIGHT_NEED = "light.see";
|
|
1707
|
+
/** The code of the need of an alert receiver that is on, in hours. */
|
|
1708
|
+
const ALERT_WATCH_NEED = "alert.watch";
|
|
1709
|
+
/** The code of the need of the space heat of a home, in `kWh`. The blankets and the sleeping bags of each person are gear, not this need. */
|
|
1710
|
+
const WARMTH_NEED = "warmth.shelter";
|
|
1711
|
+
/** The page of the National Weather Service on the receivers of NOAA Weather Radio. It is a work of the United States federal government. */
|
|
1712
|
+
const NWS_RECEIVERS_SOURCE = {
|
|
1713
|
+
id: "nws-nwr-receivers",
|
|
1714
|
+
title: "NOAA Weather Radio All Hazards: Receiver Information",
|
|
1715
|
+
url: "https://www.weather.gov/nwr/nwr_receivers",
|
|
1716
|
+
license: "us-public-domain",
|
|
1717
|
+
checked: "2026-11-24",
|
|
1718
|
+
by: "National Weather Service",
|
|
1719
|
+
terms: "https://www.weather.gov/disclaimer"
|
|
1720
|
+
};
|
|
1721
|
+
/** The page of the National Weather Service on the alarms of NOAA Weather Radio. It is a work of the United States federal government. */
|
|
1722
|
+
const NWS_ALARMS_SOURCE = {
|
|
1723
|
+
id: "nws-nwr-alarms",
|
|
1724
|
+
title: "NOAA Weather Radio All Hazards: NWR Alarms",
|
|
1725
|
+
url: "https://www.weather.gov/nwr/nwr_warning",
|
|
1726
|
+
license: "us-public-domain",
|
|
1727
|
+
checked: "2026-11-24",
|
|
1728
|
+
by: "National Weather Service",
|
|
1729
|
+
terms: "https://www.weather.gov/disclaimer"
|
|
1730
|
+
};
|
|
1731
|
+
/**
|
|
1732
|
+
* The daily needs of the kit, with a cited rate or a no read.
|
|
1733
|
+
*
|
|
1734
|
+
* - `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.
|
|
1735
|
+
* Thus a receiver stays on at all hours to get a warning. One receiver for each home is a choice of this model.
|
|
1736
|
+
* - `light.see`: no read, for each household. The kit lists of official sources give a flashlight and extra batteries, but no hours of use.
|
|
1737
|
+
* The count of lights of each person is a fact of the plan or the device.
|
|
1738
|
+
* - `warmth.shelter`: no read. The heat of a home changes with the weather, the building and the persons. It is space heat only.
|
|
1739
|
+
*/
|
|
1740
|
+
const DAILY_NEEDS = [
|
|
1741
|
+
{
|
|
1742
|
+
code: ALERT_WATCH_NEED,
|
|
1743
|
+
unit: "h",
|
|
1744
|
+
users: "household",
|
|
1745
|
+
rate: {
|
|
1746
|
+
read: true,
|
|
1747
|
+
perDay: {
|
|
1748
|
+
value: 24,
|
|
1749
|
+
unit: "h/d"
|
|
1750
|
+
},
|
|
1751
|
+
sources: [NWS_RECEIVERS_SOURCE, NWS_ALARMS_SOURCE],
|
|
1752
|
+
note: "The alarms page tells that many receivers can stay in a muted standby mode and turn on when a warning comes. The receivers page tells that the tone alarm is useful for warnings during the night. Thus a receiver stays on and listens at all hours to get a warning, so 24 hours each day. One receiver for each home is a choice of this model, not of the sources."
|
|
1753
|
+
}
|
|
1754
|
+
},
|
|
1755
|
+
{
|
|
1756
|
+
code: LIGHT_NEED,
|
|
1757
|
+
unit: "h",
|
|
1758
|
+
users: "household",
|
|
1759
|
+
rate: {
|
|
1760
|
+
read: false,
|
|
1761
|
+
why: "The kit lists of Ready.gov give a flashlight and extra batteries, but no hours of use each day. No official source that we found gives a daily amount. A user gives the hours as input data."
|
|
1762
|
+
}
|
|
1763
|
+
},
|
|
1764
|
+
{
|
|
1765
|
+
code: WARMTH_NEED,
|
|
1766
|
+
unit: "kWh",
|
|
1767
|
+
users: "household",
|
|
1768
|
+
rate: {
|
|
1769
|
+
read: false,
|
|
1770
|
+
why: "The heat that a home needs changes with the weather, the building and the persons. This need is space heat only. The blankets and the sleeping bags of each person are gear, not this need. No official source that we found gives a daily amount. A user gives the heat as input data."
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
];
|
|
1774
|
+
/**
|
|
1775
|
+
* These are the codes of the gate of the daily needs. Each code is an error. The gate of the sources of `@mark1russell7/guidebook` gives its own codes.
|
|
1776
|
+
*
|
|
1777
|
+
* - `daily-need-id`: a need has an empty code, or a different need has its code.
|
|
1778
|
+
* - `daily-need-unit`: the unit of a need is not a unit of `@mark1russell7/quantity`.
|
|
1779
|
+
* - `daily-need-rate`: a 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.
|
|
1780
|
+
* Or a no read has no reason.
|
|
1781
|
+
*/
|
|
1782
|
+
const DAILY_NEED_CODES = [
|
|
1783
|
+
"daily-need-id",
|
|
1784
|
+
"daily-need-unit",
|
|
1785
|
+
"daily-need-rate"
|
|
1786
|
+
];
|
|
1787
|
+
/** This function tells if a text is a unit that `@mark1russell7/quantity` reads. */
|
|
1788
|
+
function isUnit(unit) {
|
|
1789
|
+
try {
|
|
1790
|
+
return Number.isFinite(valueIn({
|
|
1791
|
+
value: 0,
|
|
1792
|
+
unit
|
|
1793
|
+
}, unit));
|
|
1794
|
+
} catch {
|
|
1795
|
+
return false;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
/** This function gives the amount of a rate in the unit of its need for each day, or `undefined` when the units do not convert. */
|
|
1799
|
+
function amountOf(perDay, unit) {
|
|
1800
|
+
try {
|
|
1801
|
+
return valueIn(perDay, `${unit}/d`);
|
|
1802
|
+
} catch {
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
/**
|
|
1807
|
+
* This function gives each finding of a list of daily needs. `resultOf` of `@mark1russell7/guidebook` tells if the gate passes.
|
|
1808
|
+
*
|
|
1809
|
+
* Each source must have a publisher (`by`) and a page of its terms, with HTTPS addresses. The findings are in the order of the list. The function is pure.
|
|
1810
|
+
*
|
|
1811
|
+
* @param needs - The daily needs, for example `DAILY_NEEDS`
|
|
1812
|
+
* @param options - The options of the gate of the sources, for example the date of the gate
|
|
1813
|
+
*/
|
|
1814
|
+
function checkDailyNeeds(needs, options) {
|
|
1815
|
+
const sources = /* @__PURE__ */ new Map();
|
|
1816
|
+
for (const need of needs) if (need.rate.read) for (const source of need.rate.sources) sources.set(source.id, source);
|
|
1817
|
+
const fields = [.../* @__PURE__ */ new Set([
|
|
1818
|
+
...options?.require ?? [],
|
|
1819
|
+
"by",
|
|
1820
|
+
"terms"
|
|
1821
|
+
])];
|
|
1822
|
+
const findings = [...checkSources([...sources.values()], {
|
|
1823
|
+
...options,
|
|
1824
|
+
require: fields,
|
|
1825
|
+
https: true
|
|
1826
|
+
})];
|
|
1827
|
+
const add = (code, id, message) => {
|
|
1828
|
+
findings.push({
|
|
1829
|
+
level: "error",
|
|
1830
|
+
code,
|
|
1831
|
+
record: "need",
|
|
1832
|
+
id,
|
|
1833
|
+
message
|
|
1834
|
+
});
|
|
1835
|
+
};
|
|
1836
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1837
|
+
needs.forEach((need, index) => {
|
|
1838
|
+
const id = need.code.trim() === "" ? `needs[${String(index)}]` : need.code;
|
|
1839
|
+
if (need.code.trim() === "") add("daily-need-id", id, `The need "${id}" has no code.`);
|
|
1840
|
+
else if (seen.has(need.code)) add("daily-need-id", id, `Two needs have the code "${id}".`);
|
|
1841
|
+
seen.add(need.code);
|
|
1842
|
+
if (!isUnit(need.unit)) add("daily-need-unit", id, `The unit "${need.unit}" of the need "${id}" is not a unit of quantity.`);
|
|
1843
|
+
if (need.rate.read) {
|
|
1844
|
+
const amount = amountOf(need.rate.perDay, need.unit);
|
|
1845
|
+
if (amount === void 0 || !Number.isFinite(amount) || amount < 0) add("daily-need-rate", id, `The rate of the need "${id}" is not a finite number of 0 or more in ${need.unit}/d.`);
|
|
1846
|
+
if (need.rate.sources.length === 0) add("daily-need-rate", id, `The rate of the need "${id}" has no source.`);
|
|
1847
|
+
} else if (need.rate.why.trim() === "") add("daily-need-rate", id, `The no read of the need "${id}" has no reason.`);
|
|
1848
|
+
});
|
|
1849
|
+
return findings;
|
|
1850
|
+
}
|
|
1851
|
+
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, FOOD_NEED, FORMULA_DRAW_MONTHS, FORMULA_NEED, FORMULA_READY, INFANT_FEEDINGS, INFANT_MONTHS, JOIN_CODES, LIGHT_NEED, NASEM_ENERGY_SOURCE, NASEM_INFANT_CALORIES, NEEDS_CODES, NEED_SUPPLIES, NIST_SI_GUIDE_SOURCE, NO_COOK, NWS_ALARMS_SOURCE, NWS_RECEIVERS_SOURCE, STORED_WATER, USGS_WATER_DENSITY_SOURCE, WARMTH_NEED, WATER_DENSITY_MAX, WATER_NEED, WATER_SPECIFIC_HEAT, calorieChange, calorieNeed, calorieRow, calorieRowOf, checkCalorieChain, checkCalorieTable, checkDailyNeeds, checkJoins, cookFragment, hasNeedsError, householdFragment, isActivityLevel };
|
|
1382
1852
|
|
|
1383
1853
|
//# sourceMappingURL=index.js.map
|