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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -984,33 +984,37 @@ 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': data['profileSettings']['P'],
993
- 'K': data['profileSettings']['K'],
994
- 'Mg': data['profileSettings']['Mg'],
995
- 'Ca': data['profileSettings']['Ca'],
996
- 'S': data['profileSettings']['S'],
997
- 'N (NO3-)': data['profileSettings']['N (NO3-)'],
998
- 'N (NH4+)': data['profileSettings']['N (NH4+)']
999
  }
1000
 
1001
- calculator.fertilizers = data['fertilizerConstants']
1002
-
 
 
 
 
1003
  # Выполняем расчет
1004
  calculator.calculate()
 
 
1005
  return jsonify(calculator.get_web_results())
1006
 
1007
  except Exception as e:
1008
- return jsonify({"error": str(e)}), 500
1009
-
1010
-
1011
-
1012
-
1013
-
1014
 
1015
 
1016
 
 
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:
1014
+ return jsonify({
1015
+ "error": str(e),
1016
+ "message": "Ошибка расчета"
1017
+ }), 500
 
 
1018
 
1019
 
1020