Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -859,67 +859,51 @@ print(calculator.generate_report(results))
|
|
859 |
|
860 |
@app.route('/calculation', methods=['POST'])
|
861 |
def handle_calculation():
|
862 |
-
# 1. Выводим в консоль ВСЕ полученные данные
|
863 |
-
print("\n=== ВХОДЯЩИЕ ДАННЫЕ ===")
|
864 |
try:
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
"
|
881 |
-
"
|
882 |
-
"
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
"error": None,
|
887 |
-
"received_data": data # Возвращаем обратно полученные данные
|
888 |
-
}
|
889 |
-
|
890 |
-
# 3. Примитивный "расчет" без проверок
|
891 |
-
try:
|
892 |
-
if data:
|
893 |
-
# Просто копируем часть данных в ответ
|
894 |
-
response["actual_profile"].update({
|
895 |
-
"P": data.get("profileSettings", {}).get("P", 0),
|
896 |
-
"K": data.get("profileSettings", {}).get("K", 0),
|
897 |
-
"Mg": data.get("profileSettings", {}).get("Mg", 0),
|
898 |
-
"Ca": data.get("profileSettings", {}).get("Ca", 0),
|
899 |
-
"S": data.get("profileSettings", {}).get("S", 0)
|
900 |
-
})
|
901 |
-
|
902 |
-
# Фиктивные расчеты азота
|
903 |
-
total_n = data.get("profileSettings", {}).get("TOTAL_NITROG", 0) or 0
|
904 |
-
no3_ratio = data.get("profileSettings", {}).get("NO3_RAT", 0) or 0
|
905 |
-
response["nitrogen_ratios"] = {
|
906 |
"NH4_RATIO": 1,
|
907 |
-
"NO3_RATIO":
|
908 |
-
"TOTAL_NITROGEN":
|
909 |
}
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
except Exception as e:
|
919 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
920 |
|
921 |
-
# 4. Всегда возвращаем 200 OK
|
922 |
-
return jsonify(response), 200
|
923 |
|
924 |
|
925 |
|
|
|
859 |
|
860 |
@app.route('/calculation', methods=['POST'])
|
861 |
def handle_calculation():
|
|
|
|
|
862 |
try:
|
863 |
+
# 1. Получаем и парсим данные
|
864 |
+
data = request.get_json()
|
865 |
+
if not data:
|
866 |
+
return jsonify({"error": "No JSON data received"}), 400
|
867 |
+
|
868 |
+
# 2. Логируем входящие данные (для отладки)
|
869 |
+
print("\n=== ВХОДЯЩИЕ ДАННЫЕ ===")
|
870 |
+
print(json.dumps(data, indent=2, ensure_ascii=False))
|
871 |
+
|
872 |
+
# 3. Создаем и запускаем калькулятор
|
873 |
+
calculator = NutrientCalculator(data)
|
874 |
+
results = calculator.calculate()
|
875 |
+
|
876 |
+
# 4. Формируем полный ответ
|
877 |
+
response = {
|
878 |
+
"fertilizers": results['fertilizers'],
|
879 |
+
"actual_profile": results['actual_profile'],
|
880 |
+
"deficits": results['deficits'],
|
881 |
+
"total_ppm": results['total_ppm'],
|
882 |
+
"error": None,
|
883 |
+
"nitrogen_ratios": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
884 |
"NH4_RATIO": 1,
|
885 |
+
"NO3_RATIO": data.get("profileSettings", {}).get("NO3_RAT", 0),
|
886 |
+
"TOTAL_NITROGEN": data.get("profileSettings", {}).get("TOTAL_NITROG", 0)
|
887 |
}
|
888 |
+
}
|
889 |
+
|
890 |
+
# 5. Логируем результаты (для отладки)
|
891 |
+
print("\n=== РЕЗУЛЬТАТЫ ===")
|
892 |
+
print(calculator.generate_report(results))
|
893 |
+
|
894 |
+
return jsonify(response), 200
|
895 |
+
|
896 |
except Exception as e:
|
897 |
+
error_msg = f"Server error: {str(e)}"
|
898 |
+
print(error_msg)
|
899 |
+
return jsonify({
|
900 |
+
"error": error_msg,
|
901 |
+
"fertilizers": {},
|
902 |
+
"actual_profile": {},
|
903 |
+
"deficits": {},
|
904 |
+
"total_ppm": 0
|
905 |
+
}), 500
|
906 |
|
|
|
|
|
907 |
|
908 |
|
909 |
|