DmitrMakeev commited on
Commit
467aacd
·
verified ·
1 Parent(s): a0a11bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -31
app.py CHANGED
@@ -884,42 +884,55 @@ if __name__ == "__main__":
884
  calculator.print_report() # Правильный вызов метода класса
885
  except Exception as e:
886
  print(f"Критическая ошибка: {str(e)}")
887
- @app.route('/calculation', methods=['POST'])
888
- def calculate_nutrients():
889
- try:
890
- data = request.get_json()
891
 
892
- # Входные данные
893
- fertilizer_constants = data.get("fertilizerConstants")
894
- base_profile = data.get("targetProfile")
895
- total_nitrogen = data.get("totalNitrogen", 125.0)
896
- NO3_RATIO = data.get("no3Ratio", 8.25)
897
- volume = data.get("volume", 100)
898
-
899
- calculator = NutrientCalculator(
900
- volume_liters=volume,
901
- base_profile=base_profile,
902
- fertilizer_constants=fertilizer_constants,
903
- total_nitrogen=total_nitrogen,
904
- no3_ratio=no3_ratio,
905
- nh4_ratio=nh4_ratio
906
- )
907
 
908
- calculator.calculate()
909
 
910
- return jsonify({
911
- "profile": calculator.actual_profile,
912
- "ec": calculator.calculate_ec(),
913
- "fertilizers": calculator.results,
914
- "deficit": {
915
- k: round(calculator.target_profile[k] - calculator.actual_profile[k], 1)
916
- for k in calculator.target_profile
917
- if abs(calculator.target_profile[k] - calculator.actual_profile[k]) > 0.1
918
- }
919
- })
920
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
921
  except Exception as e:
922
- return jsonify({"error": str(e)}), 400
923
 
924
 
925
 
 
884
  calculator.print_report() # Правильный вызов метода класса
885
  except Exception as e:
886
  print(f"Критическая ошибка: {str(e)}")
 
 
 
 
887
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
888
 
 
889
 
 
 
 
 
 
 
 
 
 
 
890
 
891
+
892
+
893
+
894
+
895
+
896
+
897
+
898
+
899
+ @app.route('/calculate', methods=['POST'])
900
+ def calculate_nutrients():
901
+ try:
902
+ # Получаем данные из запроса
903
+ data = request.get_json()
904
+
905
+ # Обновляем переменные из запроса (кроме NH4+)
906
+ volume = float(data.get('volume', 100))
907
+ target_profile = {
908
+ 'P': float(data.get('P', 31.000)),
909
+ 'K': float(data.get('K', 210.000)),
910
+ 'Mg': float(data.get('Mg', 24.000)),
911
+ 'Ca': float(data.get('Ca', 84.000)),
912
+ 'S': float(data.get('S', 56.439)),
913
+ 'N (NO3-)': float(data.get('NO3', 0)),
914
+ 'N (NH4+)': 1.00 # По умолчанию как в оригинале
915
+ }
916
+
917
+ # Создаем и настраиваем калькулятор
918
+ calculator = NutrientCalculator(volume_liters=volume)
919
+ calculator.target_profile.update(target_profile)
920
+
921
+ # Выполняем расчет
922
+ results = calculator.calculate()
923
+
924
+ # Формируем ответ
925
+ response = {
926
+ 'profile': {k: round(v, 2) for k, v in calculator.actual_profile.items()},
927
+ 'fertilizers': results,
928
+ 'total_ec': calculator.calculate_ec(),
929
+ 'total_ppm': round(sum(calculator.actual_profile.values()), 1)
930
+ }
931
+
932
+ return jsonify(response)
933
+
934
  except Exception as e:
935
+ return jsonify({'error': str(e)}), 400
936
 
937
 
938