Spaces:
Sleeping
Sleeping
Update nutri_call.html
Browse files- nutri_call.html +149 -1
nutri_call.html
CHANGED
@@ -1754,11 +1754,159 @@ populateProfileSelector();
|
|
1754 |
</script>
|
1755 |
|
1756 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1757 |
|
|
|
|
|
|
|
1758 |
|
|
|
|
|
1759 |
|
|
|
|
|
1760 |
|
1761 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1762 |
|
1763 |
</body>
|
1764 |
</html>
|
|
|
1754 |
</script>
|
1755 |
|
1756 |
|
1757 |
+
<script>
|
1758 |
+
class NutrientCalculator {
|
1759 |
+
constructor(fertilizerConstants, profileSettings, liters, roundingPrecision) {
|
1760 |
+
this.fertilizers = fertilizerConstants;
|
1761 |
+
this.profile = profileSettings;
|
1762 |
+
this.volume = liters;
|
1763 |
+
this.roundingPrecision = 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])); // CaCl не учитываем в фактическом балансе
|
1777 |
+
this.results = Object.fromEntries(Object.keys(this.fertilizers).map(fert => [fert, { граммы: 0.0 }]));
|
1778 |
+
}
|
1779 |
|
1780 |
+
calculate() {
|
1781 |
+
// Добавляем аммонийный азот
|
1782 |
+
this._applyFertilizer("Аммоний азотнокислый", "N (NH4+)", this.target["N (NH4+)"]);
|
1783 |
|
1784 |
+
// Добавляем фосфор
|
1785 |
+
this._applyFertilizer("Монофосфат калия", "P", this.target.P);
|
1786 |
|
1787 |
+
// Добавляем магний
|
1788 |
+
this._applyFertilizer("Сульфат магния", "Mg", this.target.Mg);
|
1789 |
|
1790 |
+
// Балансируем калий и серу
|
1791 |
+
this._balanceKS();
|
1792 |
+
|
1793 |
+
// Распределяем кальций
|
1794 |
+
this._distributeCalcium();
|
1795 |
+
|
1796 |
+
// Балансируем нитратный азот
|
1797 |
+
const no3Needed = this.target["N (NO3-)"] - this.actual["N (NO3-)"];
|
1798 |
+
if (no3Needed > 0) {
|
1799 |
+
this._applyFertilizer("Калий азотнокислый", "N (NO3-)", no3Needed);
|
1800 |
+
}
|
1801 |
+
|
1802 |
+
return this._verifyResults();
|
1803 |
+
}
|
1804 |
+
|
1805 |
+
_applyFertilizer(name, element, targetPPM) {
|
1806 |
+
if (!this.fertilizers[name]) {
|
1807 |
+
throw new Error(`Удобрение '${name}' не найдено!`);
|
1808 |
+
}
|
1809 |
+
const content = this.fertilizers[name][element] || 0;
|
1810 |
+
if (content === 0) {
|
1811 |
+
console.warn(`ПРЕДУПРЕЖДЕНИЕ: Удобрение '${name}' не содержит элемент '${element}'`);
|
1812 |
+
return;
|
1813 |
+
}
|
1814 |
+
const grams = (targetPPM * this.volume) / (content * 1000);
|
1815 |
+
this.results[name].граммы += parseFloat(grams.toFixed(this.roundingPrecision));
|
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 |
+
}
|
1822 |
+
}
|
1823 |
+
}
|
1824 |
+
|
1825 |
+
_balanceKS() {
|
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;
|
1833 |
+
if (kFraction === 0 || sFraction === 0) {
|
1834 |
+
console.warn("ПРЕДУПРЕЖДЕНИЕ: Удобрение 'Калий сернокислый' содержит нулевые значения!");
|
1835 |
+
return;
|
1836 |
+
}
|
1837 |
+
const kFromK2SO4 = Math.min(kNeeded, sNeeded * kFraction / sFraction);
|
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);
|
1845 |
+
}
|
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 |
+
_verifyResults() {
|
1858 |
+
const deficits = {};
|
1859 |
+
for (const el in this.target) {
|
1860 |
+
const diff = this.target[el] - this.actual[el];
|
1861 |
+
if (Math.abs(diff) > 0.1) {
|
1862 |
+
deficits[el] = parseFloat(diff.toFixed(this.roundingPrecision));
|
1863 |
+
}
|
1864 |
+
}
|
1865 |
+
return {
|
1866 |
+
fertilizers: Object.fromEntries(
|
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 |
+
totalPPM: parseFloat(Object.values(this.actual).reduce((sum, val) => sum + val, 0).toFixed(this.roundingPrecision))
|
1874 |
+
};
|
1875 |
+
}
|
1876 |
+
}
|
1877 |
+
|
1878 |
+
|
1879 |
+
const INPUT_DATA = {
|
1880 |
+
fertilizerConstants: {
|
1881 |
+
"Кальциевая селитра": { "N (NO3-)": 0.11863, "Ca": 0.16972 },
|
1882 |
+
"Калий азотнокислый": { "N (NO3-)": 0.13854, "K": 0.36672 },
|
1883 |
+
"Аммоний азотнокислый": { "N (NO3-)": 0.17499, "N (NH4+)": 0.17499 },
|
1884 |
+
"Сульфат магния": { "Mg": 0.10220, "S": 0.13483 },
|
1885 |
+
"Монофосфат калия": { "P": 0.22761, "K": 0.28731 },
|
1886 |
+
"Калий сернокислый": { "K": 0.44874, "S": 0.18401 }
|
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 |
+
|
1908 |
+
|
1909 |
+
</script>
|
1910 |
|
1911 |
</body>
|
1912 |
</html>
|