Spaces:
Sleeping
Sleeping
Update nutri_call.html
Browse files- nutri_call.html +34 -31
nutri_call.html
CHANGED
|
@@ -1756,25 +1756,26 @@ populateProfileSelector();
|
|
| 1756 |
|
| 1757 |
<script>
|
| 1758 |
class NutrientCalculator {
|
| 1759 |
-
constructor(
|
| 1760 |
-
this.fertilizers = fertilizerConstants;
|
| 1761 |
-
this.profile = profileSettings;
|
| 1762 |
-
this.volume = liters;
|
| 1763 |
-
this.roundingPrecision =
|
| 1764 |
|
| 1765 |
const totalParts = this.profile.NO3_RAT + 1;
|
| 1766 |
this.target = {
|
| 1767 |
'P': this.profile.P,
|
| 1768 |
'K': this.profile.K,
|
| 1769 |
'Mg': this.profile.Mg,
|
| 1770 |
-
'Ca': this.profile.Ca,
|
| 1771 |
'S': this.profile.S,
|
| 1772 |
'N (NO3-)': this.profile.TOTAL_NITROG * (this.profile.NO3_RAT / totalParts),
|
| 1773 |
'N (NH4+)': this.profile.TOTAL_NITROG * (1 / totalParts)
|
| 1774 |
};
|
| 1775 |
|
| 1776 |
-
this.actual = Object.fromEntries(Object.keys(this.target).map(k => [k, 0.0]));
|
| 1777 |
-
this.results = Object.fromEntries(Object.keys(this.fertilizers).map(fert => [fert, {
|
|
|
|
| 1778 |
}
|
| 1779 |
|
| 1780 |
calculate() {
|
|
@@ -1799,7 +1800,7 @@ class NutrientCalculator {
|
|
| 1799 |
this._applyFertilizer("Калий азотнокислый", "N (NO3-)", no3Needed);
|
| 1800 |
}
|
| 1801 |
|
| 1802 |
-
return this.
|
| 1803 |
}
|
| 1804 |
|
| 1805 |
_applyFertilizer(name, element, targetPPM) {
|
|
@@ -1812,10 +1813,12 @@ class NutrientCalculator {
|
|
| 1812 |
return;
|
| 1813 |
}
|
| 1814 |
const grams = (targetPPM * this.volume) / (content * 1000);
|
| 1815 |
-
this.results[name].граммы
|
| 1816 |
|
|
|
|
| 1817 |
for (const [el, val] of Object.entries(this.fertilizers[name])) {
|
| 1818 |
const addedPPM = (grams * val * 1000) / this.volume;
|
|
|
|
| 1819 |
if (el in this.actual) {
|
| 1820 |
this.actual[el] = parseFloat((this.actual[el] + addedPPM).toFixed(this.roundingPrecision));
|
| 1821 |
}
|
|
@@ -1826,7 +1829,6 @@ class NutrientCalculator {
|
|
| 1826 |
let kNeeded = this.target.K - this.actual.K;
|
| 1827 |
let sNeeded = this.target.S - this.actual.S;
|
| 1828 |
|
| 1829 |
-
// Используем "Калий сернокислый" для баланса K и S
|
| 1830 |
if (kNeeded > 0 && sNeeded > 0) {
|
| 1831 |
const kFraction = this.fertilizers["Калий сернокислый"]["K"] || 0;
|
| 1832 |
const sFraction = this.fertilizers["Калий сернокислый"]["S"] || 0;
|
|
@@ -1838,7 +1840,6 @@ class NutrientCalculator {
|
|
| 1838 |
this._applyFertilizer("Калий сернокислый", "K", kFromK2SO4);
|
| 1839 |
}
|
| 1840 |
|
| 1841 |
-
// Оставшийся калий добавляем через "Калий азотнокислый"
|
| 1842 |
const remainingK = this.target.K - this.actual.K;
|
| 1843 |
if (remainingK > 0) {
|
| 1844 |
this._applyFertilizer("Калий азотнокислый", "K", remainingK);
|
|
@@ -1846,15 +1847,13 @@ class NutrientCalculator {
|
|
| 1846 |
}
|
| 1847 |
|
| 1848 |
_distributeCalcium() {
|
| 1849 |
-
const caTarget = this.target.Ca;
|
| 1850 |
-
|
| 1851 |
-
// Весь кальций добавляется через "Кальциевую селитру"
|
| 1852 |
if (caTarget > 0) {
|
| 1853 |
this._applyFertilizer("Кальциевая селитра", "Ca", caTarget);
|
| 1854 |
}
|
| 1855 |
}
|
| 1856 |
|
| 1857 |
-
|
| 1858 |
const deficits = {};
|
| 1859 |
for (const el in this.target) {
|
| 1860 |
const diff = this.target[el] - this.actual[el];
|
|
@@ -1862,20 +1861,28 @@ class NutrientCalculator {
|
|
| 1862 |
deficits[el] = parseFloat(diff.toFixed(this.roundingPrecision));
|
| 1863 |
}
|
| 1864 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1865 |
return {
|
| 1866 |
-
|
| 1867 |
-
Object.entries(this.results).map(([k, v]) => [k, parseFloat(v.граммы.toFixed(this.roundingPrecision))])
|
| 1868 |
-
),
|
| 1869 |
-
actualProfile: Object.fromEntries(
|
| 1870 |
-
Object.entries(this.actual).map(([k, v]) => [k, parseFloat(v.toFixed(this.roundingPrecision))])
|
| 1871 |
-
),
|
| 1872 |
deficits: deficits,
|
| 1873 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1874 |
};
|
| 1875 |
}
|
| 1876 |
}
|
| 1877 |
|
| 1878 |
|
|
|
|
| 1879 |
const INPUT_DATA = {
|
| 1880 |
fertilizerConstants: {
|
| 1881 |
"Кальциевая селитра": { "N (NO3-)": 0.11863, "Ca": 0.16972 },
|
|
@@ -1887,21 +1894,17 @@ const INPUT_DATA = {
|
|
| 1887 |
},
|
| 1888 |
profileSettings: {
|
| 1889 |
P: 31, K: 210, Mg: 24, Ca: 82, S: 57.5,
|
| 1890 |
-
NO3_RAT: 8.25, TOTAL_NITROG: 125, liters: 100
|
| 1891 |
}
|
| 1892 |
};
|
| 1893 |
|
| 1894 |
// Создаем экземпляр калькулятора
|
| 1895 |
-
const calculator = new NutrientCalculator(
|
| 1896 |
-
INPUT_DATA.fertilizerConstants,
|
| 1897 |
-
INPUT_DATA.profileSettings,
|
| 1898 |
-
INPUT_DATA.profileSettings.liters,
|
| 1899 |
-
3 // Точность округления
|
| 1900 |
-
);
|
| 1901 |
|
| 1902 |
// Запускаем расчет
|
| 1903 |
const results = calculator.calculate();
|
| 1904 |
-
console.log(results);
|
|
|
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
|
|
|
| 1756 |
|
| 1757 |
<script>
|
| 1758 |
class NutrientCalculator {
|
| 1759 |
+
constructor(inputData) {
|
| 1760 |
+
this.fertilizers = inputData.fertilizerConstants;
|
| 1761 |
+
this.profile = inputData.profileSettings;
|
| 1762 |
+
this.volume = this.profile.liters;
|
| 1763 |
+
this.roundingPrecision = this.profile.rounding_precision;
|
| 1764 |
|
| 1765 |
const totalParts = this.profile.NO3_RAT + 1;
|
| 1766 |
this.target = {
|
| 1767 |
'P': this.profile.P,
|
| 1768 |
'K': this.profile.K,
|
| 1769 |
'Mg': this.profile.Mg,
|
| 1770 |
+
'Ca': this.profile.Ca,
|
| 1771 |
'S': this.profile.S,
|
| 1772 |
'N (NO3-)': this.profile.TOTAL_NITROG * (this.profile.NO3_RAT / totalParts),
|
| 1773 |
'N (NH4+)': this.profile.TOTAL_NITROG * (1 / totalParts)
|
| 1774 |
};
|
| 1775 |
|
| 1776 |
+
this.actual = Object.fromEntries(Object.keys(this.target).map(k => [k, 0.0]));
|
| 1777 |
+
this.results = Object.fromEntries(Object.keys(this.fertilizers).map(fert => [fert, {}]));
|
| 1778 |
+
this.elementContributions = {};
|
| 1779 |
}
|
| 1780 |
|
| 1781 |
calculate() {
|
|
|
|
| 1800 |
this._applyFertilizer("Калий азотнокислый", "N (NO3-)", no3Needed);
|
| 1801 |
}
|
| 1802 |
|
| 1803 |
+
return this._generateOutput();
|
| 1804 |
}
|
| 1805 |
|
| 1806 |
_applyFertilizer(name, element, targetPPM) {
|
|
|
|
| 1813 |
return;
|
| 1814 |
}
|
| 1815 |
const grams = (targetPPM * this.volume) / (content * 1000);
|
| 1816 |
+
this.results[name].граммы = parseFloat(grams.toFixed(this.roundingPrecision));
|
| 1817 |
|
| 1818 |
+
this.elementContributions[name] = {};
|
| 1819 |
for (const [el, val] of Object.entries(this.fertilizers[name])) {
|
| 1820 |
const addedPPM = (grams * val * 1000) / this.volume;
|
| 1821 |
+
this.elementContributions[name][el] = parseFloat(addedPPM.toFixed(this.roundingPrecision));
|
| 1822 |
if (el in this.actual) {
|
| 1823 |
this.actual[el] = parseFloat((this.actual[el] + addedPPM).toFixed(this.roundingPrecision));
|
| 1824 |
}
|
|
|
|
| 1829 |
let kNeeded = this.target.K - this.actual.K;
|
| 1830 |
let sNeeded = this.target.S - this.actual.S;
|
| 1831 |
|
|
|
|
| 1832 |
if (kNeeded > 0 && sNeeded > 0) {
|
| 1833 |
const kFraction = this.fertilizers["Калий сернокислый"]["K"] || 0;
|
| 1834 |
const sFraction = this.fertilizers["Калий сернокислый"]["S"] || 0;
|
|
|
|
| 1840 |
this._applyFertilizer("Калий сернокислый", "K", kFromK2SO4);
|
| 1841 |
}
|
| 1842 |
|
|
|
|
| 1843 |
const remainingK = this.target.K - this.actual.K;
|
| 1844 |
if (remainingK > 0) {
|
| 1845 |
this._applyFertilizer("Калий азотнокислый", "K", remainingK);
|
|
|
|
| 1847 |
}
|
| 1848 |
|
| 1849 |
_distributeCalcium() {
|
| 1850 |
+
const caTarget = this.target.Ca;
|
|
|
|
|
|
|
| 1851 |
if (caTarget > 0) {
|
| 1852 |
this._applyFertilizer("Кальциевая селитра", "Ca", caTarget);
|
| 1853 |
}
|
| 1854 |
}
|
| 1855 |
|
| 1856 |
+
_generateOutput() {
|
| 1857 |
const deficits = {};
|
| 1858 |
for (const el in this.target) {
|
| 1859 |
const diff = this.target[el] - this.actual[el];
|
|
|
|
| 1861 |
deficits[el] = parseFloat(diff.toFixed(this.roundingPrecision));
|
| 1862 |
}
|
| 1863 |
}
|
| 1864 |
+
|
| 1865 |
+
const fertilizers = Object.fromEntries(
|
| 1866 |
+
Object.entries(this.results).map(([name, data]) => [name, data.граммы])
|
| 1867 |
+
);
|
| 1868 |
+
|
| 1869 |
return {
|
| 1870 |
+
actual_profile: this.actual,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1871 |
deficits: deficits,
|
| 1872 |
+
element_contributions: this.elementContributions,
|
| 1873 |
+
fertilizers: fertilizers,
|
| 1874 |
+
nitrogen_ratios: {
|
| 1875 |
+
NH4_RATIO: this.profile.NO3_RAT,
|
| 1876 |
+
NO3_RATIO: 1,
|
| 1877 |
+
TOTAL_NITROGEN: this.profile.TOTAL_NITROG
|
| 1878 |
+
},
|
| 1879 |
+
total_ppm: parseFloat(Object.values(this.actual).reduce((sum, val) => sum + val, 0).toFixed(this.roundingPrecision))
|
| 1880 |
};
|
| 1881 |
}
|
| 1882 |
}
|
| 1883 |
|
| 1884 |
|
| 1885 |
+
|
| 1886 |
const INPUT_DATA = {
|
| 1887 |
fertilizerConstants: {
|
| 1888 |
"Кальциевая селитра": { "N (NO3-)": 0.11863, "Ca": 0.16972 },
|
|
|
|
| 1894 |
},
|
| 1895 |
profileSettings: {
|
| 1896 |
P: 31, K: 210, Mg: 24, Ca: 82, S: 57.5,
|
| 1897 |
+
NO3_RAT: 8.25, TOTAL_NITROG: 125, liters: 100, rounding_precision: 3
|
| 1898 |
}
|
| 1899 |
};
|
| 1900 |
|
| 1901 |
// Создаем экземпляр калькулятора
|
| 1902 |
+
const calculator = new NutrientCalculator(INPUT_DATA);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1903 |
|
| 1904 |
// Запускаем расчет
|
| 1905 |
const results = calculator.calculate();
|
| 1906 |
+
console.log(JSON.stringify(results, null, 2));
|
| 1907 |
+
|
| 1908 |
|
| 1909 |
|
| 1910 |
|