DmitrMakeev commited on
Commit
3039654
·
verified ·
1 Parent(s): 58d908b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -981,13 +981,31 @@ if __name__ == "__main__":
981
 
982
  @app.route('/calculation', methods=['POST'])
983
  def handle_calculation():
984
- data = request.json
985
- calculator = NutrientCalculator(
986
- fertilizer_constants=data['fertilizerConstants'],
987
- profile_settings=data['profileSettings']
988
- )
989
- calculator.calculate()
990
- return jsonify(calculator.get_web_results())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
991
 
992
 
993
 
 
981
 
982
  @app.route('/calculation', methods=['POST'])
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
1009
 
1010
 
1011