DmitrMakeev commited on
Commit
c791de8
·
verified ·
1 Parent(s): 5196de1

Update nutri_call.html

Browse files
Files changed (1) hide show
  1. nutri_call.html +47 -37
nutri_call.html CHANGED
@@ -336,59 +336,69 @@ const NUTRIENT_CONTENT_IN_FERTILIZERS = {
336
  };
337
 
338
  // Функция для пересчета процентов в константы
339
- function calculateNutrientConstants() {
340
- // Получаем все элементы удобрений
341
- const fertilizers = {
342
  "CaN2O6": {
343
- NO3: parseFloat(document.getElementById('fert_ca_no3').value) || 0,
344
- Ca: parseFloat(document.getElementById('fert_ca_ca').value) || 0
345
  },
346
  "KNO3": {
347
- NO3: parseFloat(document.getElementById('fert_kno3_no3').value) || 0,
348
- K: parseFloat(document.getElementById('fert_kno3_k').value) || 0
349
  },
350
  "NH4NO3": {
351
- NH4: parseFloat(document.getElementById('fert_nh4no3_nh4').value) || 0,
352
- NO3: parseFloat(document.getElementById('fert_nh4no3_no3').value) || 0
353
  },
354
  "MgSO4": {
355
- Mg: parseFloat(document.getElementById('fert_mgso4_mg').value) || 0,
356
- S: parseFloat(document.getElementById('fert_mgso4_s').value) || 0
357
  },
358
  "KH2PO4": {
359
- P: parseFloat(document.getElementById('fert_kh2po4_p').value) || 0,
360
- K: parseFloat(document.getElementById('fert_kh2po4_k').value) || 0
361
  },
362
  "K2SO4": {
363
- K: parseFloat(document.getElementById('fert_k2so4_k').value) || 0,
364
- S: parseFloat(document.getElementById('fert_k2so4_s').value) || 0
365
  }
366
  };
367
 
368
- // Пересчитываем проценты в константы (делим на 100)
369
- const calculatedConstants = {};
370
-
371
- for (const [fert, nutrients] of Object.entries(fertilizers)) {
372
- calculatedConstants[fert] = {};
373
- for (const [nutrient, value] of Object.entries(nutrients)) {
374
- calculatedConstants[fert][nutrient] = value / 100;
375
- }
376
- }
 
 
 
 
377
 
378
- // Выводим результат в консоль
379
- console.log("Calculated Nutrient Constants:", calculatedConstants);
380
-
381
- // Можно также сравнить с эталонными значениями
382
- console.log("Reference Constants:", NUTRIENT_CONTENT_IN_FERTILIZERS);
383
-
384
- return calculatedConstants;
385
- }
386
 
387
- // Назначаем обработчик на кнопку "Запуск"
388
- document.getElementById('calculate-btn').addEventListener('click', function() {
389
- const result = calculateNutrientConstants();
390
- // Здесь можно добавить отправку данных на сервер
391
- // fetch('/api/calculate', { method: 'POST', body: JSON.stringify(result) })
 
 
 
 
 
 
 
 
 
392
  });
393
  </script>
394
 
 
336
  };
337
 
338
  // Функция для пересчета процентов в константы
339
+ document.getElementById('calculate-btn').addEventListener('click', function() {
340
+ // 1. Собираем константы удобрений
341
+ const fertilizerConstants = {
342
  "CaN2O6": {
343
+ NO3: parseFloat(document.getElementById('fert_ca_no3').value) / 100 || 0,
344
+ Ca: parseFloat(document.getElementById('fert_ca_ca').value) / 100 || 0
345
  },
346
  "KNO3": {
347
+ NO3: parseFloat(document.getElementById('fert_kno3_no3').value) / 100 || 0,
348
+ K: parseFloat(document.getElementById('fert_kno3_k').value) / 100 || 0
349
  },
350
  "NH4NO3": {
351
+ NH4: parseFloat(document.getElementById('fert_nh4no3_nh4').value) / 100 || 0,
352
+ NO3: parseFloat(document.getElementById('fert_nh4no3_no3').value) / 100 || 0
353
  },
354
  "MgSO4": {
355
+ Mg: parseFloat(document.getElementById('fert_mgso4_mg').value) / 100 || 0,
356
+ S: parseFloat(document.getElementById('fert_mgso4_s').value) / 100 || 0
357
  },
358
  "KH2PO4": {
359
+ P: parseFloat(document.getElementById('fert_kh2po4_p').value) / 100 || 0,
360
+ K: parseFloat(document.getElementById('fert_kh2po4_k').value) / 100 || 0
361
  },
362
  "K2SO4": {
363
+ K: parseFloat(document.getElementById('fert_k2so4_k').value) / 100 || 0,
364
+ S: parseFloat(document.getElementById('fert_k2so4_s').value) / 100 || 0
365
  }
366
  };
367
 
368
+ // 2. Собираем настройки профиля и литры
369
+ const profileSettings = {
370
+ N: parseFloat(document.getElementById('profile_p').value) || 0,
371
+ P: parseFloat(document.getElementById('profile_k').value) || 0,
372
+ K: parseFloat(document.getElementById('profile_ca').value) || 0,
373
+ Ca: parseFloat(document.getElementById('profile_mg').value) || 0,
374
+ Mg: parseFloat(document.getElementById('profile_s').value) || 0,
375
+ S: parseFloat(document.getElementById('profile_cl').value) || 0,
376
+ NH4: parseFloat(document.getElementById('profile_nh4').value) || 0,
377
+ NO3: parseFloat(document.getElementById('profile_no3').value) || 0,
378
+ EC: parseFloat(document.getElementById('profile_ec').value) || 0,
379
+ liters: parseInt(document.getElementById('liters-input').value) || 1
380
+ };
381
 
382
+ // 3. Формируем итоговый объект с двумя разделами
383
+ const calculationData = {
384
+ fertilizerConstants: fertilizerConstants,
385
+ profileSettings: profileSettings
386
+ };
 
 
 
387
 
388
+ // 4. Выводим в консоль для проверки
389
+ console.log("Calculation Data:", calculationData);
390
+
391
+ // 5. Здесь можно добавить отправку данны�� на сервер
392
+ // fetch('/api/calculate', {
393
+ // method: 'POST',
394
+ // headers: {
395
+ // 'Content-Type': 'application/json',
396
+ // },
397
+ // body: JSON.stringify(calculationData)
398
+ // })
399
+ // .then(response => response.json())
400
+ // .then(data => console.log('Success:', data))
401
+ // .catch(error => console.error('Error:', error));
402
  });
403
  </script>
404