Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -849,45 +849,6 @@ class NutrientCalculator:
|
|
849 |
}
|
850 |
}
|
851 |
|
852 |
-
@app.route('/calculation', methods=['POST'])
|
853 |
-
def handle_calculation():
|
854 |
-
try:
|
855 |
-
data = request.json
|
856 |
-
|
857 |
-
# Валидация
|
858 |
-
required_fields = ['P', 'K', 'Mg', 'Ca', 'S', 'N (NO3-)', 'N (NH4+)', 'liters']
|
859 |
-
if not all(field in data['profileSettings'] for field in required_fields):
|
860 |
-
return jsonify({'status': 'error', 'message': 'Missing required profile fields'}), 400
|
861 |
-
|
862 |
-
required_fertilizers = [
|
863 |
-
"Кальциевая селитра", "Калий азотнокислый", "Аммоний азотнокислый",
|
864 |
-
"Сульфат магния", "Монофосфат калия", "Калий сернокислый"
|
865 |
-
]
|
866 |
-
if not all(fert in data['fertilizerConstants'] for fert in required_fertilizers):
|
867 |
-
return jsonify({'status': 'error', 'message': 'Missing required fertilizers'}), 400
|
868 |
-
|
869 |
-
# Инициализация калькулятора
|
870 |
-
calculator = NutrientCalculator(volume_liters=data['profileSettings']['liters'])
|
871 |
-
calculator.set_target_profile(data['profileSettings'])
|
872 |
-
calculator.set_fertilizers(data['fertilizerConstants'])
|
873 |
-
|
874 |
-
# Расчёт
|
875 |
-
if calculator.calculate():
|
876 |
-
return jsonify({
|
877 |
-
'status': 'success',
|
878 |
-
'data': calculator.get_results()
|
879 |
-
})
|
880 |
-
else:
|
881 |
-
return jsonify({
|
882 |
-
'status': 'error',
|
883 |
-
'message': 'Calculation failed'
|
884 |
-
}), 500
|
885 |
-
|
886 |
-
except Exception as e:
|
887 |
-
return jsonify({
|
888 |
-
'status': 'error',
|
889 |
-
'message': f"Server error: {str(e)}"
|
890 |
-
}), 500
|
891 |
|
892 |
|
893 |
|
|
|
849 |
}
|
850 |
}
|
851 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
852 |
|
853 |
|
854 |
|