DmitrMakeev commited on
Commit
c84537e
·
verified ·
1 Parent(s): 17562c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -26
app.py CHANGED
@@ -816,37 +816,42 @@ class NutrientCalculator:
816
  }
817
 
818
  @app.route('/calculation', methods=['POST'])
819
- def handle_calculation():
820
  try:
821
- data = request.json
822
-
823
- # Валидация входных данных
824
- if 'profileSettings' not in data or 'fertilizerConstants' not in data:
825
- return jsonify({'status': 'error', 'message': 'Invalid request format'}), 400
826
-
827
- # Инициализация и расчет
 
 
 
828
  calculator = NutrientCalculator(
829
- profile_settings=data['profileSettings'],
830
- fertilizer_constants=data['fertilizerConstants']
 
 
 
 
831
  )
832
-
833
- if calculator.calculate():
834
- return jsonify({
835
- 'status': 'success',
836
- 'data': calculator.get_results()
837
- })
838
- else:
839
- return jsonify({
840
- 'status': 'error',
841
- 'message': 'Calculation failed'
842
- }), 500
843
-
844
- except Exception as e:
845
  return jsonify({
846
- 'status': 'error',
847
- 'message': f"Server error: {str(e)}"
848
- }), 500
 
 
 
 
 
 
849
 
 
 
850
 
851
 
852
 
 
816
  }
817
 
818
  @app.route('/calculation', methods=['POST'])
819
+ def calculate_nutrients():
820
  try:
821
+ data = request.get_json()
822
+
823
+ # Входные данные
824
+ fertilizer_constants = data.get("fertilizerConstants")
825
+ base_profile = data.get("targetProfile")
826
+ total_nitrogen = data.get("totalNitrogen", 125.0)
827
+ no3_ratio = data.get("no3Ratio", 8.25)
828
+ nh4_ratio = data.get("nh4Ratio", 1.0)
829
+ volume = data.get("volume", 100)
830
+
831
  calculator = NutrientCalculator(
832
+ volume_liters=volume,
833
+ base_profile=base_profile,
834
+ fertilizer_constants=fertilizer_constants,
835
+ total_nitrogen=total_nitrogen,
836
+ no3_ratio=no3_ratio,
837
+ nh4_ratio=nh4_ratio
838
  )
839
+
840
+ calculator.calculate()
841
+
 
 
 
 
 
 
 
 
 
 
842
  return jsonify({
843
+ "profile": calculator.actual_profile,
844
+ "ec": calculator.calculate_ec(),
845
+ "fertilizers": calculator.results,
846
+ "deficit": {
847
+ k: round(calculator.target_profile[k] - calculator.actual_profile[k], 1)
848
+ for k in calculator.target_profile
849
+ if abs(calculator.target_profile[k] - calculator.actual_profile[k]) > 0.1
850
+ }
851
+ })
852
 
853
+ except Exception as e:
854
+ return jsonify({"error": str(e)}), 400
855
 
856
 
857