DmitrMakeev commited on
Commit
994e0b6
·
verified ·
1 Parent(s): 24e7588

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -33
app.py CHANGED
@@ -983,43 +983,26 @@ if __name__ == "__main__":
983
  def handle_calculation():
984
  try:
985
  data = request.json
986
-
987
- # Проверка обязательных полей
988
- required_fertilizers = [
989
- "Кальциевая селитра", "Калий азотнокислый",
990
- "Аммоний азотнокислый", "Сульфат магния",
991
- "Монофосфат калия", "Калий сернокислый"
992
- ]
993
 
994
- for fert in required_fertilizers:
995
- if fert not in data.get('fertilizerConstants', {}):
996
- return jsonify({"error": f"Не хватает удобрения: {fert}"}), 400
997
-
998
- # Создаем калькулятор
999
  calculator = NutrientCalculator(volume_liters=data['profileSettings']['liters'])
1000
 
1001
- # Устанавливаем профиль
1002
  calculator.target_profile = {
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-)': float(data['profileSettings']['N (NO3-)']),
1009
- 'N (NH4+)': float(data['profileSettings']['N (NH4+)'])
1010
  }
1011
 
1012
- # Устанавливаем удобрения (проверяем проценты)
1013
- calculator.fertilizers = {
1014
- fert: {el: max(float(p), 0) for el, p in nutrients.items()}
1015
- for fert, nutrients in data['fertilizerConstants'].items()
1016
- }
1017
-
1018
- # Расчет
1019
- calculator.calculate()
1020
- result = calculator.get_web_results()
1021
 
1022
- return jsonify(result)
 
 
1023
 
1024
  except Exception as e:
1025
  return jsonify({"error": str(e)}), 500
@@ -1041,9 +1024,6 @@ def handle_calculation():
1041
 
1042
 
1043
 
1044
-
1045
-
1046
-
1047
 
1048
 
1049
 
 
983
  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
 
1024
 
1025
 
1026
 
 
 
 
1027
 
1028
 
1029