@mark1russell7/stack-needs 0.9.4 → 0.9.6
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 +62 -3
- package/build/index.d.ts +169 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +313 -36
- package/build/index.js.map +1 -1
- package/package.json +3 -3
package/build/index.js
CHANGED
|
@@ -689,7 +689,7 @@ const FORMULA_FEEDS = {
|
|
|
689
689
|
source: WIC_INFANT_SOURCE,
|
|
690
690
|
locator: "Table 5.2, Guidelines for Feeding Healthy Infants, Birth to 12 Months Old, page 137"
|
|
691
691
|
};
|
|
692
|
-
/** The source of the energy
|
|
692
|
+
/** The source of the energy and the water of the infant formula items: the SR Legacy file of FoodData Central. */
|
|
693
693
|
const FDC_SR_LEGACY_SOURCE = {
|
|
694
694
|
id: "fdc-sr-legacy-2018-04",
|
|
695
695
|
title: "FoodData Central, SR Legacy (April 2018)",
|
|
@@ -713,6 +713,21 @@ const FORMULA_LATER_LEAST = {
|
|
|
713
713
|
kcalSource: FDC_SR_LEGACY_SOURCE,
|
|
714
714
|
kcalLocator: "FDC ID 172319: 63 kcal in 100 g (food_nutrient.csv), and 30.4 g in 1 fl oz (food_portion.csv)"
|
|
715
715
|
};
|
|
716
|
+
/**
|
|
717
|
+
* The facts of the mix rule: the FDC items 173554 (store brand, powder) and 172319 (store brand, ready-to-feed).
|
|
718
|
+
* The powder gives 524 kcal and 2 g of water in 100 g. The ready-to-feed item gives 63 kcal and 88.1 g of water in 100 g.
|
|
719
|
+
* The WIC guide tells to mix powder one bottle at a time, and to use bottled water after a disaster or in a power cut.
|
|
720
|
+
*/
|
|
721
|
+
const FORMULA_MIX = {
|
|
722
|
+
powderKcal: 524,
|
|
723
|
+
powderWater: 2,
|
|
724
|
+
readyKcal: 63,
|
|
725
|
+
readyWater: 88.1,
|
|
726
|
+
source: FDC_SR_LEGACY_SOURCE,
|
|
727
|
+
locator: "FDC ID 173554: 524 kcal (nutrient 1008) and 2 g of water (nutrient 1051) in 100 g. FDC ID 172319: 63 kcal and 88.1 g of water in 100 g (food_nutrient.csv)",
|
|
728
|
+
waterSource: WIC_INFANT_SOURCE,
|
|
729
|
+
waterLocator: "Page 106, Guidelines for Using Infant Formula When Access to Common Kitchen Appliances Is Limited, and Natural Disaster or Power Outage"
|
|
730
|
+
};
|
|
716
731
|
/** The source of the infant table: the PDF of the report Dietary Reference Intakes for Energy (2023) of the National Academies. */
|
|
717
732
|
const NASEM_ENERGY_SOURCE = {
|
|
718
733
|
id: "nasem-dri-energy-2023",
|
|
@@ -1092,6 +1107,11 @@ const WATER_NEED = "hydration.drink";
|
|
|
1092
1107
|
const NO_COOK = "food.no-cook";
|
|
1093
1108
|
/** The resource of the ready-to-feed infant formula, in `kcal`. It has a direct use for the formula need. It needs no water and no fuel. */
|
|
1094
1109
|
const FORMULA_READY = "food.infant-formula-ready";
|
|
1110
|
+
/**
|
|
1111
|
+
* The resource of the infant formula powder, in `kg`. It has no direct use. `formulaMixFragment` mixes it with
|
|
1112
|
+
* `STORED_WATER` into `FORMULA_READY`. `cookFragment` does not cook it.
|
|
1113
|
+
*/
|
|
1114
|
+
const FORMULA_POWDER = "food.infant-formula-powder";
|
|
1095
1115
|
/** The resource of the stored drinking water, in `L`. It has a direct use for the water need. */
|
|
1096
1116
|
const STORED_WATER = "water.stored";
|
|
1097
1117
|
/**
|
|
@@ -1330,6 +1350,7 @@ function openedStores(input, stores, noReads, feed) {
|
|
|
1330
1350
|
* - The resources are the resources of the stores and of the direct uses, with the units of the catalog.
|
|
1331
1351
|
* - The supply part of each draw is `supply`. Its default is the part of `NEED_SUPPLIES` for the need of the draw.
|
|
1332
1352
|
* - The fragment has no converter. `cookFragment` gives the converters for the dry food, with the water and the fuel of each pot.
|
|
1353
|
+
* `formulaMixFragment` gives the converter of `food.infant-formula-powder`. The powder has a store, and no direct use.
|
|
1333
1354
|
* - With no cold storage (the default), an opened container of formula serves one feed. The store has only the energy of the feeds,
|
|
1334
1355
|
* and `waste` gives the rest. The smallest feed is the smallest need of an infant of the draw, divided by `FORMULA_FEEDS`.
|
|
1335
1356
|
* A container of no read gives no store and a gift with no read, so the stores are a lower limit.
|
|
@@ -1570,6 +1591,17 @@ const WATER_DENSITY_MAX = {
|
|
|
1570
1591
|
note: "The largest density of the table, from 0 °C to 100 °C. Each other row is less."
|
|
1571
1592
|
};
|
|
1572
1593
|
/**
|
|
1594
|
+
* The least density of liquid water from 0 °C to 100 °C: 0.95865 kg/L. The USGS table gives 0.95865 g/cm3 at 100 °C, its least value.
|
|
1595
|
+
* Thus 1 L of the test water of a boil yield is 0.95865 kg or more. The least mass of the test water gives the most fuel for each kg of the pot.
|
|
1596
|
+
*/
|
|
1597
|
+
const WATER_DENSITY_MIN = {
|
|
1598
|
+
value: .95865,
|
|
1599
|
+
unit: "kg/L",
|
|
1600
|
+
source: USGS_WATER_DENSITY_SOURCE,
|
|
1601
|
+
locator: "Table of the density and the weight of water by temperature, row 212 °F/100 °C: 0.95865 g/cm3",
|
|
1602
|
+
note: "The least density of the table, from 0 °C to 100 °C. Each other row is more."
|
|
1603
|
+
};
|
|
1604
|
+
/**
|
|
1573
1605
|
* The temperature at the end of the heat to boil, in °C.
|
|
1574
1606
|
* Water boils at a lower temperature at a high place. Then the heat is less.
|
|
1575
1607
|
* 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.
|
|
@@ -1581,7 +1613,7 @@ const BOIL_CELSIUS = 100;
|
|
|
1581
1613
|
*/
|
|
1582
1614
|
const COLD_START_CELSIUS = 0;
|
|
1583
1615
|
/** This function gives the value of an amount in a unit, or `undefined` when the units do not convert. */
|
|
1584
|
-
function inUnit(value, from, to) {
|
|
1616
|
+
function inUnit$1(value, from, to) {
|
|
1585
1617
|
try {
|
|
1586
1618
|
const out = valueIn({
|
|
1587
1619
|
value,
|
|
@@ -1592,27 +1624,54 @@ function inUnit(value, from, to) {
|
|
|
1592
1624
|
return;
|
|
1593
1625
|
}
|
|
1594
1626
|
}
|
|
1627
|
+
/** This function gives a cited temperature of a boil yield in °C, or `undefined` when the value is not a finite number with a fact. */
|
|
1628
|
+
function citedCelsius(value) {
|
|
1629
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
1630
|
+
const { celsius, fact } = value;
|
|
1631
|
+
return typeof celsius === "number" && Number.isFinite(celsius) && typeof fact === "string" ? celsius : void 0;
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* This function gives the heat that 1 kg of fuel puts into the test water of a boil yield, in `kJ/kg`. Else it gives the reason of a no read.
|
|
1635
|
+
* The test water takes `WATER_DENSITY_MIN`. Thus the heat is not more than the true heat, so the fuel is not less.
|
|
1636
|
+
* The rise goes from the cited start to the cited end of the test, the boil point at the place of the test.
|
|
1637
|
+
* A warmer start or a colder end gives less heat. Thus each one needs its citation, and a yield with no cited start or end gives a no read.
|
|
1638
|
+
* An end of `BOIL_CELSIUS` is not a default: at a high place the test water boils at less, and that default gives too little fuel.
|
|
1639
|
+
* A yield with the bound `most` is a best case, so it gives too little fuel and a no read. A yield with the bound `least` or no bound gives a read.
|
|
1640
|
+
*/
|
|
1641
|
+
function yieldHeat(boil) {
|
|
1642
|
+
const bound = "bound" in boil ? boil.bound : void 0;
|
|
1643
|
+
if (bound !== void 0 && bound !== "least") return { why: `The boil yield of the stove has the bound ${String(bound)}. Only a yield with the bound least or no bound gives the fuel.${bound === "most" ? " A most yield gives too little fuel for the boil." : ""}` };
|
|
1644
|
+
const startC = citedCelsius(boil.start);
|
|
1645
|
+
if (startC === void 0) return { why: "The boil yield of the stove has no cited start temperature. A colder start of the test gives too little fuel." };
|
|
1646
|
+
const endC = citedCelsius(boil.end);
|
|
1647
|
+
if (endC === void 0) return { why: "The boil yield of the stove has no cited end temperature, the boil point of the test. At a high place the test water boils below 100 °C, so 100 °C gives too little fuel." };
|
|
1648
|
+
if (!(startC >= 0 && startC < endC && endC <= 100)) return { why: `The boil yield goes from ${String(startC)} °C to ${String(endC)} °C. The start must be from 0 °C, and less than the end. The end must be up to ${String(100)} °C.` };
|
|
1649
|
+
const litres = inUnit$1(boil.amount, boil.unit, "L");
|
|
1650
|
+
const fuelKg = inUnit$1(boil.per.amount, boil.per.unit, "kg");
|
|
1651
|
+
if (litres === void 0 || fuelKg === void 0 || !(litres > 0) || !(fuelKg > 0)) return { why: `The boil yield of the stove is ${String(boil.amount)} ${boil.unit} for each ${String(boil.per.amount)} ${boil.per.unit}, which is not a volume above 0 for a mass above 0.` };
|
|
1652
|
+
return { perKg: litres * WATER_DENSITY_MIN.value * WATER_SPECIFIC_HEAT.value * (endC - startC) / fuelKg };
|
|
1653
|
+
}
|
|
1595
1654
|
/** 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. */
|
|
1596
1655
|
function stoveRate(rate) {
|
|
1597
|
-
const minutes = inUnit(rate.per.amount, rate.per.unit, "min");
|
|
1656
|
+
const minutes = inUnit$1(rate.per.amount, rate.per.unit, "min");
|
|
1598
1657
|
if (minutes === void 0 || !(minutes > 0)) return void 0;
|
|
1599
|
-
const energy = inUnit(rate.amount, rate.unit, "kJ");
|
|
1658
|
+
const energy = inUnit$1(rate.amount, rate.unit, "kJ");
|
|
1600
1659
|
if (energy !== void 0) return {
|
|
1601
1660
|
kind: "energy",
|
|
1602
1661
|
perMin: energy / minutes
|
|
1603
1662
|
};
|
|
1604
|
-
const mass = inUnit(rate.amount, rate.unit, "kg");
|
|
1663
|
+
const mass = inUnit$1(rate.amount, rate.unit, "kg");
|
|
1605
1664
|
if (mass !== void 0) return {
|
|
1606
1665
|
kind: "mass",
|
|
1607
1666
|
perMin: mass / minutes
|
|
1608
1667
|
};
|
|
1609
1668
|
}
|
|
1610
|
-
const read = (value, unit) => ({
|
|
1669
|
+
const read$1 = (value, unit) => ({
|
|
1611
1670
|
read: true,
|
|
1612
1671
|
value,
|
|
1613
1672
|
unit
|
|
1614
1673
|
});
|
|
1615
|
-
const noRead = (why) => ({
|
|
1674
|
+
const noRead$1 = (why) => ({
|
|
1616
1675
|
read: false,
|
|
1617
1676
|
why
|
|
1618
1677
|
});
|
|
@@ -1625,22 +1684,22 @@ const noRead = (why) => ({
|
|
|
1625
1684
|
function cookLine(product, resource, perUnitKg, foodGifts, context) {
|
|
1626
1685
|
const { stove, batchKg, share, startC, fuelEnergy } = context;
|
|
1627
1686
|
let energy;
|
|
1628
|
-
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.`);
|
|
1629
|
-
else if (product.energy === void 0) energy = noRead(`The product ${product.id} has no food energy in the catalog.`);
|
|
1630
|
-
else if (!product.energy.read) energy = noRead(`The food energy of the product ${product.id} is a no read: ${product.energy.why}`);
|
|
1687
|
+
if (foodGifts > 1) energy = noRead$1(`The product ${product.id} gives ${String(foodGifts)} foods. The catalog gives one energy for the whole product, not the energy of each food.`);
|
|
1688
|
+
else if (product.energy === void 0) energy = noRead$1(`The product ${product.id} has no food energy in the catalog.`);
|
|
1689
|
+
else if (!product.energy.read) energy = noRead$1(`The food energy of the product ${product.id} is a no read: ${product.energy.why}`);
|
|
1631
1690
|
else {
|
|
1632
|
-
const kcal = inUnit(product.energy.amount, product.energy.unit, "kcal");
|
|
1633
|
-
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.`);
|
|
1634
|
-
else if (perUnitKg === void 0 || !(perUnitKg > 0)) energy = noRead(`The gift of ${resource} of the product ${product.id} has no read in kg.`);
|
|
1635
|
-
else energy = read(kcal / perUnitKg, "kcal/kg");
|
|
1691
|
+
const kcal = inUnit$1(product.energy.amount, product.energy.unit, "kcal");
|
|
1692
|
+
if (kcal === void 0) energy = noRead$1(`The food energy of the product ${product.id} is in ${product.energy.unit}, which does not convert to kcal.`);
|
|
1693
|
+
else if (perUnitKg === void 0 || !(perUnitKg > 0)) energy = noRead$1(`The gift of ${resource} of the product ${product.id} has no read in kg.`);
|
|
1694
|
+
else energy = read$1(kcal / perUnitKg, "kcal/kg");
|
|
1636
1695
|
}
|
|
1637
1696
|
const litres = cookWater(product);
|
|
1638
|
-
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");
|
|
1639
|
-
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}`);
|
|
1697
|
+
const water = litres === void 0 ? noRead$1(`The catalog cites no cook water for the product ${product.id}, or no bulk mass for its water rate.`) : read$1(valueIn(litres, "L/kg"), "L/kg");
|
|
1698
|
+
const heat = water.read ? read$1((water.value * WATER_DENSITY_MAX.value + 1) * batchKg * WATER_SPECIFIC_HEAT.value * (100 - startC), "kJ") : noRead$1(`The heat to boil is a no read: ${water.why}`);
|
|
1640
1699
|
const why = [];
|
|
1641
1700
|
if (!heat.read) why.push(heat.why);
|
|
1642
1701
|
const time = product.cook?.time;
|
|
1643
|
-
const cookMin = time === void 0 ? void 0 : inUnit(time.high, time.unit, "min");
|
|
1702
|
+
const cookMin = time === void 0 ? void 0 : inUnit$1(time.high, time.unit, "min");
|
|
1644
1703
|
if (time === void 0) why.push(`The catalog cites no cook time for the product ${product.id}.`);
|
|
1645
1704
|
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.`);
|
|
1646
1705
|
const bound = stove.rate !== void 0 && "bound" in stove.rate ? stove.rate.bound : void 0;
|
|
@@ -1648,16 +1707,20 @@ function cookLine(product, resource, perUnitKg, foodGifts, context) {
|
|
|
1648
1707
|
if (stove.rate === void 0) why.push(`The stove of ${stove.fuel} has no cited fuel rate.`);
|
|
1649
1708
|
else if (bound !== void 0) why.push(`The fuel rate of the stove has the bound ${String(bound)}. Only a rate with no bound is the value.${bound === "least" ? " A least rate gives too little fuel for the cook time." : ""}`);
|
|
1650
1709
|
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.`);
|
|
1710
|
+
const boilWhy = [];
|
|
1651
1711
|
let potPerMin;
|
|
1652
|
-
if (share === void 0)
|
|
1712
|
+
if (share === void 0) boilWhy.push("No cited stove share gives the part of the stove heat that goes into the pot.");
|
|
1653
1713
|
else if (rate !== void 0) {
|
|
1654
1714
|
if (rate.kind === "energy") {
|
|
1655
|
-
if (stove.heating !== share.heating)
|
|
1715
|
+
if (stove.heating !== share.heating) boilWhy.push(`The stove share is for the ${share.heating} heating value, and the stove rate is for the ${String(stove.heating ?? "unknown")} heating value.`);
|
|
1656
1716
|
else potPerMin = rate.perMin * share.value;
|
|
1657
|
-
} else if (fuelEnergy === void 0)
|
|
1658
|
-
else if (fuelEnergy.heating !== share.heating)
|
|
1717
|
+
} else if (fuelEnergy === void 0) boilWhy.push(`The fuel ${stove.fuel} has no cited energy, so its mass rate gives no heat for the boil.`);
|
|
1718
|
+
else if (fuelEnergy.heating !== share.heating) boilWhy.push(`The stove share is for the ${share.heating} heating value, and the energy of the fuel ${stove.fuel} is the ${fuelEnergy.heating} value.`);
|
|
1659
1719
|
else potPerMin = rate.perMin * fuelEnergy.perKg * share.value;
|
|
1660
1720
|
}
|
|
1721
|
+
const fromYield = stove.boil === void 0 ? { why: "The stove has no cited boil yield." } : yieldHeat(stove.boil);
|
|
1722
|
+
if ("why" in fromYield) boilWhy.push(fromYield.why);
|
|
1723
|
+
if (potPerMin === void 0 && "why" in fromYield) why.push(`The fuel of the boil is a no read. ${boilWhy.join(" ")}`);
|
|
1661
1724
|
let fuelPerMin;
|
|
1662
1725
|
if (rate?.kind === "mass") fuelPerMin = rate.perMin;
|
|
1663
1726
|
else if (rate?.kind === "energy") {
|
|
@@ -1666,7 +1729,7 @@ function cookLine(product, resource, perUnitKg, foodGifts, context) {
|
|
|
1666
1729
|
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.`);
|
|
1667
1730
|
else fuelPerMin = rate.perMin / fuelEnergy.perKg;
|
|
1668
1731
|
}
|
|
1669
|
-
if (why.length > 0 || !heat.read || cookMin === void 0 ||
|
|
1732
|
+
if (why.length > 0 || !heat.read || cookMin === void 0 || fuelPerMin === void 0 || !(fuelPerMin > 0)) {
|
|
1670
1733
|
const text = why.join(" ");
|
|
1671
1734
|
return {
|
|
1672
1735
|
product: product.id,
|
|
@@ -1674,19 +1737,33 @@ function cookLine(product, resource, perUnitKg, foodGifts, context) {
|
|
|
1674
1737
|
energy,
|
|
1675
1738
|
water,
|
|
1676
1739
|
heat,
|
|
1677
|
-
minutes: noRead(text),
|
|
1678
|
-
fuel: noRead(text)
|
|
1740
|
+
minutes: noRead$1(text),
|
|
1741
|
+
fuel: noRead$1(text)
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
const boilFuels = [...potPerMin !== void 0 && potPerMin > 0 ? [heat.value / potPerMin * fuelPerMin] : [], ..."perKg" in fromYield ? [heat.value / fromYield.perKg] : []];
|
|
1745
|
+
if (boilFuels.length === 0) {
|
|
1746
|
+
const text = `The fuel of the boil is a no read. ${boilWhy.join(" ")}`;
|
|
1747
|
+
return {
|
|
1748
|
+
product: product.id,
|
|
1749
|
+
resource,
|
|
1750
|
+
energy,
|
|
1751
|
+
water,
|
|
1752
|
+
heat,
|
|
1753
|
+
minutes: noRead$1(text),
|
|
1754
|
+
fuel: noRead$1(text)
|
|
1679
1755
|
};
|
|
1680
1756
|
}
|
|
1681
|
-
const
|
|
1757
|
+
const boilFuel = Math.max(...boilFuels);
|
|
1758
|
+
const minutes = boilFuel / fuelPerMin + cookMin;
|
|
1682
1759
|
return {
|
|
1683
1760
|
product: product.id,
|
|
1684
1761
|
resource,
|
|
1685
1762
|
energy,
|
|
1686
1763
|
water,
|
|
1687
1764
|
heat,
|
|
1688
|
-
minutes: read(minutes, "min"),
|
|
1689
|
-
fuel: read(
|
|
1765
|
+
minutes: read$1(minutes, "min"),
|
|
1766
|
+
fuel: read$1(boilFuel + cookMin * fuelPerMin, "kg")
|
|
1690
1767
|
};
|
|
1691
1768
|
}
|
|
1692
1769
|
/** This function gives the stove facts of the input: the facts of the caller, or the facts of a product of the catalog. */
|
|
@@ -1701,10 +1778,14 @@ function stoveOf(catalog, stove) {
|
|
|
1701
1778
|
function isFood(catalog, code) {
|
|
1702
1779
|
return catalog.resources.find((item) => item.code === code)?.kind === "food";
|
|
1703
1780
|
}
|
|
1704
|
-
/**
|
|
1781
|
+
/**
|
|
1782
|
+
* This function tells if a resource of the catalog is a dry food to cook: a food resource in a unit of mass.
|
|
1783
|
+
* `FORMULA_POWDER` is not a food to cook: `formulaMixFragment` mixes it with water, with no fuel.
|
|
1784
|
+
*/
|
|
1705
1785
|
function isDryFood(catalog, code) {
|
|
1786
|
+
if (code === "food.infant-formula-powder") return false;
|
|
1706
1787
|
const resource = catalog.resources.find((item) => item.code === code);
|
|
1707
|
-
return resource !== void 0 && resource.kind === "food" && inUnit(1, resource.unit, "kg") !== void 0;
|
|
1788
|
+
return resource !== void 0 && resource.kind === "food" && inUnit$1(1, resource.unit, "kg") !== void 0;
|
|
1708
1789
|
}
|
|
1709
1790
|
/**
|
|
1710
1791
|
* This function gives the converters that cook the dry food of a buy list, with the water and the fuel of each pot.
|
|
@@ -1715,12 +1796,18 @@ function isDryFood(catalog, code) {
|
|
|
1715
1796
|
* - 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`.
|
|
1716
1797
|
* The water mass takes `WATER_DENSITY_MAX`. The dry food takes the specific heat of water, which is higher than its own.
|
|
1717
1798
|
* - 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.
|
|
1799
|
+
* - A boil yield of the stove (`boil` of market) gives the boil fuel with no share and no fuel energy.
|
|
1800
|
+
* The boil fuel is the heat of the pot over the heat of 1 kg of fuel in the test.
|
|
1801
|
+
* The test water takes `WATER_DENSITY_MIN`, and the rise goes from the cited start to the cited end of the test. The boil time is then the boil fuel over the mass rate.
|
|
1802
|
+
* A yield with the bound `most`, or with no cited start or end, gives a no read. When the share and the yield both have a read, the line takes the most boil fuel.
|
|
1718
1803
|
* - 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.
|
|
1719
1804
|
* The model does not give that time, so there the fuel is not an upper limit.
|
|
1720
1805
|
* - Only a stove rate with no bound gives the fuel. A rate with a bound, for example `bound: "least"`, gives a no read. The fuel of the cook time is the rate times the time, so a least rate gives too little fuel.
|
|
1721
1806
|
* - 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.
|
|
1722
1807
|
*
|
|
1723
|
-
* A dry food is a gift of a food resource in a unit of mass
|
|
1808
|
+
* A dry food is a gift of a food resource in a unit of mass, except `FORMULA_POWDER`. `formulaMixFragment` gives its converter.
|
|
1809
|
+
* Each missing fact gives a line with no read and its reasons, not a figure.
|
|
1810
|
+
*
|
|
1724
1811
|
* 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:
|
|
1725
1812
|
* 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.
|
|
1726
1813
|
* A store of the resource from a different fragment gets the converter of this list.
|
|
@@ -1746,7 +1833,7 @@ function isDryFood(catalog, code) {
|
|
|
1746
1833
|
*/
|
|
1747
1834
|
function cookFragment(input) {
|
|
1748
1835
|
const { catalog, units } = input;
|
|
1749
|
-
const batchKg = inUnit(input.batch.value, input.batch.unit, "kg");
|
|
1836
|
+
const batchKg = inUnit$1(input.batch.value, input.batch.unit, "kg");
|
|
1750
1837
|
if (batchKg === void 0 || !(batchKg > 0)) throw new RangeError(`The batch ${String(input.batch.value)} ${input.batch.unit} is not a mass above 0.`);
|
|
1751
1838
|
const { share } = input;
|
|
1752
1839
|
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.`);
|
|
@@ -1754,7 +1841,7 @@ function cookFragment(input) {
|
|
|
1754
1841
|
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.`);
|
|
1755
1842
|
const stove = stoveOf(catalog, input.stove);
|
|
1756
1843
|
const fuel = catalog.resources.find((resource) => resource.code === stove.fuel);
|
|
1757
|
-
const fuelUnitPerKg = fuel === void 0 ? void 0 : inUnit(1, "kg", fuel.unit);
|
|
1844
|
+
const fuelUnitPerKg = fuel === void 0 ? void 0 : inUnit$1(1, "kg", fuel.unit);
|
|
1758
1845
|
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.`);
|
|
1759
1846
|
const perKg = fuelEnergyPerMass(fuel);
|
|
1760
1847
|
const context = {
|
|
@@ -1778,7 +1865,7 @@ function cookFragment(input) {
|
|
|
1778
1865
|
const foodGifts = gifts.filter((gift) => isFood(catalog, gift.resource)).length;
|
|
1779
1866
|
for (const gift of gifts) {
|
|
1780
1867
|
if (!isDryFood(catalog, gift.resource)) continue;
|
|
1781
|
-
const perUnitKg = gift.read ? inUnit(gift.amount, gift.unit, "kg") : void 0;
|
|
1868
|
+
const perUnitKg = gift.read ? inUnit$1(gift.amount, gift.unit, "kg") : void 0;
|
|
1782
1869
|
lines.push(cookLine(product, gift.resource, perUnitKg, foodGifts, context));
|
|
1783
1870
|
}
|
|
1784
1871
|
}
|
|
@@ -1801,8 +1888,8 @@ function cookFragment(input) {
|
|
|
1801
1888
|
}
|
|
1802
1889
|
const most = (pick) => Math.max(...own.map((line) => valueOf(pick(line))));
|
|
1803
1890
|
const least = (pick) => Math.min(...own.map((line) => valueOf(pick(line))));
|
|
1804
|
-
const dryPerKg = inUnit(1, "kg", unitOf.get(resource) ?? "") ?? 1;
|
|
1805
|
-
const waterPerL = inUnit(1, "L", unitOf.get("water.stored") ?? "");
|
|
1891
|
+
const dryPerKg = inUnit$1(1, "kg", unitOf.get(resource) ?? "") ?? 1;
|
|
1892
|
+
const waterPerL = inUnit$1(1, "L", unitOf.get("water.stored") ?? "");
|
|
1806
1893
|
if (waterPerL === void 0) throw new RangeError(`The catalog has no resource "${STORED_WATER}" in a unit of volume for the cook water.`);
|
|
1807
1894
|
converters.push({
|
|
1808
1895
|
id: `${prefix}:${resource}`,
|
|
@@ -1848,6 +1935,196 @@ function cookFragment(input) {
|
|
|
1848
1935
|
function valueOf(value) {
|
|
1849
1936
|
return value.read ? value.value : NaN;
|
|
1850
1937
|
}
|
|
1938
|
+
// src/mix.ts
|
|
1939
|
+
/**
|
|
1940
|
+
* This function gives the mix water of infant formula powder, in `kg` for each `kg` of powder.
|
|
1941
|
+
*
|
|
1942
|
+
* The rule is a mass balance. It assumes that the prepared powder has the energy in 100 g of the ready-to-feed item of the
|
|
1943
|
+
* same store brand. The reason: the FDC file gives these two items of one brand, and the catalog cites no mix ratio of a label.
|
|
1944
|
+
* The assumption ends when a label-cited mix ratio replaces it.
|
|
1945
|
+
*
|
|
1946
|
+
* Thus 1 kg of powder gives `powder / ready` kg of prepared formula, and the water is that mass minus 1 kg.
|
|
1947
|
+
* For `FORMULA_MIX`, 5240 kcal/kg divided by 630 kcal/kg gives 8.3175 kg, so the water is 7.3175 kg. That is 1.39646 g for each kcal.
|
|
1948
|
+
* `formulaMixCheck` compares the water of the prepared formula with the cited water of the ready-to-feed item.
|
|
1949
|
+
*
|
|
1950
|
+
* @param powderKcalPerKg - The energy of the powder, in `kcal/kg`, for example 5240
|
|
1951
|
+
* @param mix - The facts of the rule. The default is `FORMULA_MIX`. Only its energy of the ready-to-feed item applies.
|
|
1952
|
+
* @returns The mass of the mix water, in kg for each kg of powder
|
|
1953
|
+
* @throws RangeError when the energy of the powder is not above the energy of the ready-to-feed item
|
|
1954
|
+
*/
|
|
1955
|
+
function formulaMixWater(powderKcalPerKg, mix = FORMULA_MIX) {
|
|
1956
|
+
const readyKcalPerKg = mix.readyKcal * 10;
|
|
1957
|
+
if (!(powderKcalPerKg > readyKcalPerKg) || !Number.isFinite(powderKcalPerKg)) throw new RangeError(`The powder gives ${String(powderKcalPerKg)} kcal/kg. The mix rule needs a finite energy above the ${String(readyKcalPerKg)} kcal/kg of the ready-to-feed item.`);
|
|
1958
|
+
return powderKcalPerKg / readyKcalPerKg - 1;
|
|
1959
|
+
}
|
|
1960
|
+
/**
|
|
1961
|
+
* This function gives the check of the mix rule with the water of the two items. The rule does not use their water, so the
|
|
1962
|
+
* check is independent of it. For `FORMULA_MIX`, 100 g of prepared formula has 12.023 g of powder and 87.977 g of mix water.
|
|
1963
|
+
* The powder holds 0.240 g of water, so the prediction is 88.218 g. The FDC item gives 88.1 g, 0.13% less.
|
|
1964
|
+
*
|
|
1965
|
+
* @param mix - The facts of the rule. The default is `FORMULA_MIX`.
|
|
1966
|
+
* @returns The predicted water, the cited water and their relative difference
|
|
1967
|
+
* @throws RangeError for the errors of `formulaMixWater`
|
|
1968
|
+
*/
|
|
1969
|
+
function formulaMixCheck(mix = FORMULA_MIX) {
|
|
1970
|
+
const powder = 100 / (1 + formulaMixWater(mix.powderKcal * 10, mix));
|
|
1971
|
+
const added = 100 - powder;
|
|
1972
|
+
const predicted = added + powder * mix.powderWater / 100;
|
|
1973
|
+
return {
|
|
1974
|
+
powder,
|
|
1975
|
+
added,
|
|
1976
|
+
predicted,
|
|
1977
|
+
cited: mix.readyWater,
|
|
1978
|
+
relative: (predicted - mix.readyWater) / mix.readyWater
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
/** This function gives the value of an amount in a unit, or `undefined` when the units do not convert. */
|
|
1982
|
+
function inUnit(value, from, to) {
|
|
1983
|
+
try {
|
|
1984
|
+
const out = valueIn({
|
|
1985
|
+
value,
|
|
1986
|
+
unit: from
|
|
1987
|
+
}, to);
|
|
1988
|
+
return Number.isFinite(out) ? out : void 0;
|
|
1989
|
+
} catch {
|
|
1990
|
+
return;
|
|
1991
|
+
}
|
|
1992
|
+
}
|
|
1993
|
+
const read = (value, unit) => ({
|
|
1994
|
+
read: true,
|
|
1995
|
+
value,
|
|
1996
|
+
unit
|
|
1997
|
+
});
|
|
1998
|
+
const noRead = (why) => ({
|
|
1999
|
+
read: false,
|
|
2000
|
+
why
|
|
2001
|
+
});
|
|
2002
|
+
/** This function gives the mix line of one product. Each missing fact gives a no read with its reason. */
|
|
2003
|
+
function mixLine(product, perUnitKg, foodGifts, mix) {
|
|
2004
|
+
let energy;
|
|
2005
|
+
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.`);
|
|
2006
|
+
else if (product.energy === void 0) energy = noRead(`The product ${product.id} has no food energy in the catalog.`);
|
|
2007
|
+
else if (!product.energy.read) energy = noRead(`The food energy of the product ${product.id} is a no read: ${product.energy.why}`);
|
|
2008
|
+
else {
|
|
2009
|
+
const kcal = inUnit(product.energy.amount, product.energy.unit, "kcal");
|
|
2010
|
+
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.`);
|
|
2011
|
+
else if (perUnitKg === void 0 || !(perUnitKg > 0)) energy = noRead(`The gift of ${FORMULA_POWDER} of the product ${product.id} has no read in kg.`);
|
|
2012
|
+
else energy = read(kcal / perUnitKg, "kcal/kg");
|
|
2013
|
+
}
|
|
2014
|
+
let water;
|
|
2015
|
+
if (!energy.read) water = noRead(`The mix water is a no read: ${energy.why}`);
|
|
2016
|
+
else if (!(energy.value > mix.readyKcal * 10)) water = noRead(`The powder of the product ${product.id} gives ${String(energy.value)} kcal/kg, not more than the ${String(mix.readyKcal * 10)} kcal/kg of the ready-to-feed item.`);
|
|
2017
|
+
else water = read(formulaMixWater(energy.value, mix) / WATER_DENSITY_MAX.value, "L/kg");
|
|
2018
|
+
return {
|
|
2019
|
+
product: product.id,
|
|
2020
|
+
energy,
|
|
2021
|
+
water
|
|
2022
|
+
};
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* This function gives the converter that mixes the infant formula powder of a buy list with water, with no fuel.
|
|
2026
|
+
*
|
|
2027
|
+
* - One run of the converter is 1 kg of powder. It takes the powder and the mix water from `water.stored`.
|
|
2028
|
+
* It gives the energy of the powder as `food.infant-formula-ready`. The direct use of that resource feeds the formula need.
|
|
2029
|
+
* - The mix water is `formulaMixWater`: a mass balance with the energy of the ready-to-feed item of the same store brand.
|
|
2030
|
+
* This is an assumption. A label-cited mix ratio replaces it.
|
|
2031
|
+
* - The mass of the water converts to a volume at `WATER_DENSITY_MAX`, 1 kg/L. Water above 4 °C is less dense, so the true volume is a little more.
|
|
2032
|
+
* - The water is `water.stored`, the store of the drinking water. The WIC guide tells to use bottled water after a disaster
|
|
2033
|
+
* or in a power cut. A store of water from the tap is safe water only when its source is safe.
|
|
2034
|
+
* - The WIC guide tells to prepare powder one bottle at a time, for one feed. Thus the mix has no waste of an opened container.
|
|
2035
|
+
* - The powder of each product comes from its food energy in the catalog. Two products of the list can give powder.
|
|
2036
|
+
* The converter then takes the worst case of their lines: the most water and the least energy. A line with no read gives no converter.
|
|
2037
|
+
* - A drinking draw at a higher level of the same store takes its water first, by the take order of `enduranceOf`.
|
|
2038
|
+
* Thus, when a case cuts the water supply, the powder can add 0 days.
|
|
2039
|
+
*
|
|
2040
|
+
* The function is pure.
|
|
2041
|
+
*
|
|
2042
|
+
* @param input - The catalog and the buy list, and the facts of the mix rule
|
|
2043
|
+
* @returns The fragment, the line of each powder product and the reasons for no converter
|
|
2044
|
+
* @throws RangeError when the catalog has no product of an `id` of the buy list
|
|
2045
|
+
* @throws RangeError when the powder has a converter and the catalog has no `food.infant-formula-powder` in a unit of mass
|
|
2046
|
+
* @throws RangeError when the powder has a converter and the catalog has no `food.infant-formula-ready` in a unit of energy
|
|
2047
|
+
* @throws RangeError when the powder has a converter and the catalog has no `water.stored` in a unit of volume
|
|
2048
|
+
* @throws RangeError for the errors of `giftsOf`
|
|
2049
|
+
*/
|
|
2050
|
+
function formulaMixFragment(input) {
|
|
2051
|
+
const { catalog, units } = input;
|
|
2052
|
+
const mix = input.mix ?? FORMULA_MIX;
|
|
2053
|
+
const isFood = (code) => catalog.resources.find((item) => item.code === code)?.kind === "food";
|
|
2054
|
+
const lines = [];
|
|
2055
|
+
for (const [id, count] of Object.entries(units)) {
|
|
2056
|
+
if (!(count > 0)) continue;
|
|
2057
|
+
const product = catalog.products.find((item) => item.id === id);
|
|
2058
|
+
if (product === void 0) throw new RangeError(`The catalog has no product "${id}".`);
|
|
2059
|
+
const gifts = giftsOf(catalog, id, 1);
|
|
2060
|
+
const foodGifts = gifts.filter((gift) => isFood(gift.resource)).length;
|
|
2061
|
+
for (const gift of gifts) {
|
|
2062
|
+
if (gift.resource !== "food.infant-formula-powder") continue;
|
|
2063
|
+
lines.push(mixLine(product, gift.read ? inUnit(gift.amount, gift.unit, "kg") : void 0, foodGifts, mix));
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
const empty = (why) => ({
|
|
2067
|
+
layer: {
|
|
2068
|
+
schema: "endurance/1",
|
|
2069
|
+
levels: [],
|
|
2070
|
+
resources: [],
|
|
2071
|
+
stores: [],
|
|
2072
|
+
draws: [],
|
|
2073
|
+
converters: []
|
|
2074
|
+
},
|
|
2075
|
+
lines,
|
|
2076
|
+
why,
|
|
2077
|
+
read: why === void 0
|
|
2078
|
+
});
|
|
2079
|
+
if (lines.length === 0) return empty(void 0);
|
|
2080
|
+
const why = lines.flatMap((line) => [line.energy, line.water].flatMap((value) => value.read ? [] : [`${line.product}: ${value.why}`]));
|
|
2081
|
+
if (why.length > 0) return empty([...new Set(why)].join(" "));
|
|
2082
|
+
const unitOf = new Map(catalog.resources.map((resource) => [resource.code, resource.unit]));
|
|
2083
|
+
const powderPerKg = inUnit(1, "kg", unitOf.get("food.infant-formula-powder") ?? "");
|
|
2084
|
+
if (powderPerKg === void 0) throw new RangeError(`The catalog has no resource "${FORMULA_POWDER}" in a unit of mass for the powder.`);
|
|
2085
|
+
const readyPerKcal = inUnit(1, "kcal", unitOf.get("food.infant-formula-ready") ?? "");
|
|
2086
|
+
if (readyPerKcal === void 0) throw new RangeError(`The catalog has no resource "${FORMULA_READY}" in a unit of energy for the prepared formula.`);
|
|
2087
|
+
const waterPerL = inUnit(1, "L", unitOf.get("water.stored") ?? "");
|
|
2088
|
+
if (waterPerL === void 0) throw new RangeError(`The catalog has no resource "${STORED_WATER}" in a unit of volume for the mix water.`);
|
|
2089
|
+
const values = (pick) => lines.map((line) => {
|
|
2090
|
+
const value = pick(line);
|
|
2091
|
+
return value.read ? value.value : NaN;
|
|
2092
|
+
});
|
|
2093
|
+
const converter = {
|
|
2094
|
+
id: `${input.prefix ?? "mix"}:${FORMULA_POWDER}`,
|
|
2095
|
+
takes: [{
|
|
2096
|
+
resource: FORMULA_POWDER,
|
|
2097
|
+
amount: powderPerKg
|
|
2098
|
+
}, {
|
|
2099
|
+
resource: STORED_WATER,
|
|
2100
|
+
amount: Math.max(...values((line) => line.water)) * waterPerL
|
|
2101
|
+
}],
|
|
2102
|
+
gives: {
|
|
2103
|
+
resource: FORMULA_READY,
|
|
2104
|
+
amount: Math.min(...values((line) => line.energy)) * readyPerKcal
|
|
2105
|
+
}
|
|
2106
|
+
};
|
|
2107
|
+
return {
|
|
2108
|
+
layer: {
|
|
2109
|
+
schema: "endurance/1",
|
|
2110
|
+
levels: [],
|
|
2111
|
+
resources: [
|
|
2112
|
+
FORMULA_POWDER,
|
|
2113
|
+
STORED_WATER,
|
|
2114
|
+
FORMULA_READY
|
|
2115
|
+
].map((code) => ({
|
|
2116
|
+
code,
|
|
2117
|
+
unit: unitOf.get(code) ?? ""
|
|
2118
|
+
})),
|
|
2119
|
+
stores: [],
|
|
2120
|
+
draws: [],
|
|
2121
|
+
converters: [converter]
|
|
2122
|
+
},
|
|
2123
|
+
lines,
|
|
2124
|
+
why: void 0,
|
|
2125
|
+
read: true
|
|
2126
|
+
};
|
|
2127
|
+
}
|
|
1851
2128
|
// src/daily.ts
|
|
1852
2129
|
/** The code of the need of light to see in the dark in a home, in hours. */
|
|
1853
2130
|
const LIGHT_NEED = "light.see";
|
|
@@ -1995,6 +2272,6 @@ function checkDailyNeeds(needs, options) {
|
|
|
1995
2272
|
});
|
|
1996
2273
|
return findings;
|
|
1997
2274
|
}
|
|
1998
|
-
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_NEED, FORMULA_READY, INFANT_FEEDINGS, INFANT_MONTHS, JOIN_CODES, LIGHT_NEED, 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, USGS_WATER_DENSITY_SOURCE, WARMTH_NEED, WATER_DENSITY_MAX, WATER_NEED, WATER_SPECIFIC_HEAT, WIC_INFANT_SOURCE, calorieChange, calorieNeed, calorieRow, calorieRowOf, checkCalorieChain, checkCalorieTable, checkDailyNeeds, checkJoins, cookFragment, hasNeedsError, householdFragment, isActivityLevel };
|
|
2275
|
+
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, INFANT_FEEDINGS, INFANT_MONTHS, JOIN_CODES, LIGHT_NEED, 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, 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, formulaMixCheck, formulaMixFragment, formulaMixWater, hasNeedsError, householdFragment, isActivityLevel };
|
|
1999
2276
|
|
|
2000
2277
|
//# sourceMappingURL=index.js.map
|