DmitrMakeev commited on
Commit
2660d54
·
verified ·
1 Parent(s): 8fe5ebf

Update nutri_call.html

Browse files
Files changed (1) hide show
  1. nutri_call.html +107 -108
nutri_call.html CHANGED
@@ -993,114 +993,7 @@ const ecConstants = {
993
 
994
 
995
 
996
- document.getElementById('calculate-btn').addEventListener('click', function () {
997
- console.log("=== НАЧАЛО ОБРАБОТКИ ===");
998
- // 1. Получаем значение точности округления
999
- const roundingInput = document.getElementById('rounding-precision');
1000
- const initialRounding = parseInt(roundingInput.value);
1001
- const roundingPrecision = Math.min(Math.max(initialRounding || 3, 0), 6);
1002
 
1003
- // 2. Функция для безопасного получения числового значения
1004
- const getValue = (id) => {
1005
- const element = document.getElementById(id);
1006
- if (!element) {
1007
- console.error(`Элемент с ID ${id} не найден!`);
1008
- return 0;
1009
- }
1010
- const value = parseFloat(element.value);
1011
- return isNaN(value) ? 0 : value;
1012
- };
1013
-
1014
- // 3. Формируем данные для сервера
1015
- const fertilizerConstants = {
1016
- "Кальциевая селитра": {
1017
- "N (NO3-)": getValue('fert_ca_no3') / 100,
1018
- "Ca": getValue('fert_ca_ca') / 100
1019
- },
1020
- "Калий азотнокислый": {
1021
- "N (NO3-)": getValue('fert_kno3_no3') / 100,
1022
- "K": getValue('fert_kno3_k') / 100
1023
- },
1024
- "Аммоний азотнокислый": {
1025
- "N (NO3-)": getValue('fert_nh4no3_no3') / 100,
1026
- "N (NH4+)": getValue('fert_nh4no3_nh4') / 100
1027
- },
1028
- "Сульфат магния": {
1029
- "Mg": getValue('fert_mgso4_mg') / 100,
1030
- "S": getValue('fert_mgso4_s') / 100
1031
- },
1032
- "Монофосфат калия": {
1033
- "P": getValue('fert_kh2po4_p') / 100,
1034
- "K": getValue('fert_kh2po4_k') / 100
1035
- },
1036
- "Калий сернокислый": {
1037
- "K": getValue('fert_k2so4_k') / 100,
1038
- "S": getValue('fert_k2so4_s') / 100
1039
- }
1040
- };
1041
-
1042
- const profileSettings = {
1043
- 'P': getValue('profile_p'),
1044
- 'K': getValue('profile_k'),
1045
- 'Mg': getValue('profile_mg'),
1046
- 'Ca': getValue('profile_ca'),
1047
- 'S': getValue('profile_s'),
1048
- 'NO3_RAT': getValue('profile_no3'),
1049
- 'TOTAL_NITROG': getValue('profile_n'),
1050
- 'liters': parseInt(document.getElementById('liters-input').value) || 1,
1051
- 'rounding_precision': roundingPrecision
1052
- };
1053
-
1054
- const requestData = {
1055
- fertilizerConstants: fertilizerConstants,
1056
- profileSettings: profileSettings
1057
- };
1058
-
1059
- console.log("=== ПОЛНЫЙ ОБЪЕКТ ДЛЯ ОТПРАВКИ ===", JSON.stringify(requestData, null, 2));
1060
-
1061
- // 4. Отправка данных на сервер
1062
- fetch('/calculation', {
1063
- method: 'POST',
1064
- headers: {
1065
- 'Content-Type': 'application/json',
1066
- },
1067
- body: JSON.stringify(requestData),
1068
- })
1069
- .then(response => {
1070
- console.log("Получен ответ от сервера. Статус:", response.status);
1071
- if (!response.ok) {
1072
- throw new Error(`HTTP error! status: ${response.status}`);
1073
- }
1074
- return response.json();
1075
- })
1076
- .then(data => {
1077
- call_data = data;
1078
- console.log("=== УСПЕШНЫЙ ОТВЕТ ОТ СЕРВЕРА ===", call_data);
1079
- // Обновляем только поля вывода
1080
- data_out(call_data);
1081
- // Обновляем поля NH4 и NO3
1082
- updateNitrogenFields(call_data);
1083
- // Показываем статус расчёта
1084
- showCalculationStatus(call_data);
1085
- // Вызываем функцию для расчета катионов и анионов
1086
- calculateCationsAndAnions(data);
1087
- calculateAndUpdate(call_data);
1088
- calculateMicroElements();
1089
- calculateN1Ratio(call_data);
1090
- // Рассчитываем EC
1091
- const temperature = parseFloat(document.getElementById('profile_temp').value) || 25;
1092
- const ecValue = calculateEC(call_data, temperature);
1093
- const ecInput = document.getElementById('profile_ec');
1094
- if (ecInput) {
1095
- ecInput.value = ecValue.toFixed(2);
1096
- console.log(`Установлено значение EC: ${ecValue.toFixed(2)}`);
1097
- }
1098
- })
1099
- .catch(error => {
1100
- console.error("=== ОШИБКА ПРИ ОБРАБОТКЕ ===", error);
1101
- alert("Ошибка при расчете: " + error.message);
1102
- });
1103
- });
1104
 
1105
  function data_out(data) {
1106
  console.log("=== ЗАПИСЬ ДАННЫХ В ФОРМУ ===");
@@ -1909,7 +1802,113 @@ console.log(JSON.stringify(results, null, 2));
1909
 
1910
 
1911
 
1912
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1913
 
1914
  </body>
1915
  </html>
 
993
 
994
 
995
 
 
 
 
 
 
 
996
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
997
 
998
  function data_out(data) {
999
  console.log("=== ЗАПИСЬ ДАННЫХ В ФОРМУ ===");
 
1802
 
1803
 
1804
 
1805
+ </script>
1806
+
1807
+
1808
+
1809
+
1810
+
1811
+
1812
+ <script>
1813
+ document.getElementById('calculate-btn').addEventListener('click', function () {
1814
+ console.log("=== НАЧАЛО ОБРАБОТКИ ===");
1815
+
1816
+ // 1. Получаем значение точности округления
1817
+ const roundingInput = document.getElementById('rounding-precision');
1818
+ const initialRounding = parseInt(roundingInput.value);
1819
+ const roundingPrecision = Math.min(Math.max(initialRounding || 3, 0), 6);
1820
+
1821
+ // 2. Функция для безопасного получения числового значения
1822
+ const getValue = (id) => {
1823
+ const element = document.getElementById(id);
1824
+ if (!element) {
1825
+ console.error(`Элемент с ID ${id} не найден!`);
1826
+ return 0;
1827
+ }
1828
+ const value = parseFloat(element.value);
1829
+ return isNaN(value) ? 0 : value;
1830
+ };
1831
+
1832
+ // 3. Формируем данные для расчёта
1833
+ const fertilizerConstants = {
1834
+ "Кальциевая селитра": {
1835
+ "N (NO3-)": getValue('fert_ca_no3') / 100,
1836
+ "Ca": getValue('fert_ca_ca') / 100
1837
+ },
1838
+ "Калий азотнокислый": {
1839
+ "N (NO3-)": getValue('fert_kno3_no3') / 100,
1840
+ "K": getValue('fert_kno3_k') / 100
1841
+ },
1842
+ "Аммоний азотнокислый": {
1843
+ "N (NO3-)": getValue('fert_nh4no3_no3') / 100,
1844
+ "N (NH4+)": getValue('fert_nh4no3_nh4') / 100
1845
+ },
1846
+ "Сульфат магния": {
1847
+ "Mg": getValue('fert_mgso4_mg') / 100,
1848
+ "S": getValue('fert_mgso4_s') / 100
1849
+ },
1850
+ "Монофосфат калия": {
1851
+ "P": getValue('fert_kh2po4_p') / 100,
1852
+ "K": getValue('fert_kh2po4_k') / 100
1853
+ },
1854
+ "Калий сернокислый": {
1855
+ "K": getValue('fert_k2so4_k') / 100,
1856
+ "S": getValue('fert_k2so4_s') / 100
1857
+ }
1858
+ };
1859
+
1860
+ const profileSettings = {
1861
+ 'P': getValue('profile_p'),
1862
+ 'K': getValue('profile_k'),
1863
+ 'Mg': getValue('profile_mg'),
1864
+ 'Ca': getValue('profile_ca'),
1865
+ 'S': getValue('profile_s'),
1866
+ 'NO3_RAT': getValue('profile_no3'),
1867
+ 'TOTAL_NITROG': getValue('profile_n'),
1868
+ 'liters': parseInt(document.getElementById('liters-input').value) || 1,
1869
+ 'rounding_precision': roundingPrecision
1870
+ };
1871
+
1872
+ const requestData = {
1873
+ fertilizerConstants: fertilizerConstants,
1874
+ profileSettings: profileSettings
1875
+ };
1876
+
1877
+ console.log("=== ПОЛНЫЙ ОБЪЕКТ ДЛЯ РАСЧЁТА ===", JSON.stringify(requestData, null, 2));
1878
+
1879
+ // 4. Локальный расчёт с использованием NutrientCalculator
1880
+ try {
1881
+ const calculator = new NutrientCalculator(requestData);
1882
+ const results = calculator.calculate();
1883
+
1884
+ console.log("=== УСПЕШНЫЙ РАСЧЁТ ===", results);
1885
+
1886
+ // Обновляем интерфейс
1887
+ data_out(results); // Выводим результаты
1888
+ updateNitrogenFields(results); // Обновляем поля NH4 и NO3
1889
+ showCalculationStatus(results); // Показываем статус расчёта
1890
+ calculateCationsAndAnions(results); // Рассчитываем катионы и анионы
1891
+ calculateAndUpdate(results); // Обновляем дополнительные данные
1892
+ calculateMicroElements(); // Рассчитываем микроэлементы
1893
+ calculateN1Ratio(results); // Рассчитываем соотношение N1
1894
+
1895
+ // Рассчитываем EC
1896
+ const temperature = parseFloat(document.getElementById('profile_temp').value) || 25;
1897
+ const ecValue = calculateEC(results, temperature);
1898
+ const ecInput = document.getElementById('profile_ec');
1899
+ if (ecInput) {
1900
+ ecInput.value = ecValue.toFixed(2);
1901
+ console.log(`Установлено значение EC: ${ecValue.toFixed(2)}`);
1902
+ }
1903
+ } catch (error) {
1904
+ console.error("=== ОШИБКА ПРИ РАСЧЁТЕ ===", error);
1905
+ alert("Ошибка при расчете: " + error.message);
1906
+ }
1907
+ });
1908
+
1909
+ </script>
1910
+
1911
+
1912
 
1913
  </body>
1914
  </html>