DmitrMakeev commited on
Commit
f65f5fc
·
verified ·
1 Parent(s): 5a69312

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -14
app.py CHANGED
@@ -984,30 +984,45 @@ def handle_calculation():
984
  try:
985
  data = request.json
986
 
987
- # Создаем калькулятор с указанным объемом
988
  calculator = NutrientCalculator(volume_liters=data['profileSettings']['liters'])
989
 
990
- # Полностью переопределяем целевой профиль из полученных данных
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
- # Устанавливаем параметры удобрений из запроса
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
- # Выполняем расчет
1008
  calculator.calculate()
1009
 
1010
- # Возвращаем результаты
 
 
 
 
1011
  return jsonify(calculator.get_web_results())
1012
 
1013
  except Exception as e:
@@ -1028,9 +1043,5 @@ def handle_calculation():
1028
 
1029
 
1030
 
1031
-
1032
-
1033
-
1034
-
1035
  if __name__ == '__main__':
1036
  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
+ # Получаем значения из запроса
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:
 
1043
 
1044
 
1045
 
 
 
 
 
1046
  if __name__ == '__main__':
1047
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))