DmitrMakeev commited on
Commit
192c3e1
·
verified ·
1 Parent(s): f65f5fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -29
app.py CHANGED
@@ -984,45 +984,30 @@ def handle_calculation():
984
  try:
985
  data = request.json
986
 
987
- # 1. СОЗДАЕМ КАЛЬКУЛЯТОР (без изменений)
988
  calculator = NutrientCalculator(volume_liters=data['profileSettings']['liters'])
989
 
990
- # 2. ПОДГОТАВЛИВАЕМ ДАННЫЕ ДЛЯ РАСЧЕТА
991
- # Получаем значения из запроса
992
- no3_value = float(data['profileSettings']['N (NO3-)'])
993
- nh4_value = float(data['profileSettings']['N (NH4+)'])
994
- total_n = no3_value + nh4_value
995
-
996
- # 3. ПОДМЕНЯЕМ РАСЧЕТ АЗОТА В КАЛЬКУЛЯТОРЕ
997
- # Сохраняем оригинальные значения
998
- original_no3 = calculator.target_profile.get('N (NO3-)', 0)
999
- original_nh4 = calculator.target_profile.get('N (NH4+)', 0)
1000
-
1001
- # Устанавливаем новые значения
1002
- calculator.target_profile.update({
1003
  'P': float(data['profileSettings']['P']),
1004
  'K': float(data['profileSettings']['K']),
1005
  'Mg': float(data['profileSettings']['Mg']),
1006
  'Ca': float(data['profileSettings']['Ca']),
1007
  'S': float(data['profileSettings']['S']),
1008
- 'N (NO3-)': no3_value, # Используем переданное значение
1009
- 'N (NH4+)': nh4_value # Используем переданное значение
1010
- })
1011
 
1012
- # 4. НАСТРАИВАЕМ УДОБРЕНИЯ (без изменений)
1013
  calculator.fertilizers = {
1014
  fert: {el: float(p) for el, p in nutrients.items()}
1015
  for fert, nutrients in data['fertilizerConstants'].items()
1016
  }
1017
-
1018
- # 5. ВЫПОЛНЯЕМ РАСЧЕТ (без изменений)
1019
  calculator.calculate()
1020
 
1021
- # 6. ВОЗВРАЩАЕМ ОРИГИНАЛЬНЫЕ ЗНАЧЕНИЯ (для безопасности)
1022
- calculator.target_profile['N (NO3-)'] = original_no3
1023
- calculator.target_profile['N (NH4+)'] = original_nh4
1024
-
1025
- # 7. ВОЗВРАЩАЕМ РЕЗУЛЬТАТ
1026
  return jsonify(calculator.get_web_results())
1027
 
1028
  except Exception as e:
@@ -1039,9 +1024,5 @@ def handle_calculation():
1039
 
1040
 
1041
 
1042
-
1043
-
1044
-
1045
-
1046
  if __name__ == '__main__':
1047
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
 
984
  try:
985
  data = request.json
986
 
987
+ # 1. СОЗДАЕМ КАЛЬКУЛЯТОР С НУЖНЫМ ОБЪЕМОМ
988
  calculator = NutrientCalculator(volume_liters=data['profileSettings']['liters'])
989
 
990
+ # 2. ПЕРЕЗАПИСЫВАЕМ ВСЕ ЗНАЧЕНИЯ ИЗ ЗАПРОСА (БЕЗ СОХРАНЕНИЯ СТАРЫХ)
991
+ calculator.target_profile = {
 
 
 
 
 
 
 
 
 
 
 
992
  'P': float(data['profileSettings']['P']),
993
  'K': float(data['profileSettings']['K']),
994
  'Mg': float(data['profileSettings']['Mg']),
995
  'Ca': float(data['profileSettings']['Ca']),
996
  'S': float(data['profileSettings']['S']),
997
+ 'N (NO3-)': float(data['profileSettings']['N (NO3-)']), # Берем ТОЛЬКО из запроса
998
+ 'N (NH4+)': float(data['profileSettings']['N (NH4+)']) # Берем ТОЛЬКО из запроса
999
+ }
1000
 
1001
+ # 3. УСТАНАВЛИВАЕМ ПАРАМЕТРЫ УДОБРЕНИЙ ИЗ ЗАПРОСА
1002
  calculator.fertilizers = {
1003
  fert: {el: float(p) for el, p in nutrients.items()}
1004
  for fert, nutrients in data['fertilizerConstants'].items()
1005
  }
1006
+
1007
+ # 4. ВЫПОЛНЯЕМ РАСЧЕТ (ИСПОЛЬЗУЕТ ТОЛЬКО ПЕРЕДАННЫЕ ДАННЫЕ)
1008
  calculator.calculate()
1009
 
1010
+ # 5. ВОЗВРАЩАЕМ РЕЗУЛЬТАТ
 
 
 
 
1011
  return jsonify(calculator.get_web_results())
1012
 
1013
  except Exception as e:
 
1024
 
1025
 
1026
 
 
 
 
 
1027
  if __name__ == '__main__':
1028
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))