Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -816,37 +816,42 @@ class NutrientCalculator:
|
|
816 |
}
|
817 |
|
818 |
@app.route('/calculation', methods=['POST'])
|
819 |
-
def
|
820 |
try:
|
821 |
-
data = request.
|
822 |
-
|
823 |
-
#
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
|
|
|
|
|
|
828 |
calculator = NutrientCalculator(
|
829 |
-
|
830 |
-
|
|
|
|
|
|
|
|
|
831 |
)
|
832 |
-
|
833 |
-
|
834 |
-
|
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 |
-
|
847 |
-
|
848 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|