Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -856,9 +856,24 @@ print(calculator.generate_report(results))
|
|
856 |
|
857 |
|
858 |
|
|
|
|
|
|
|
|
|
|
|
859 |
@app.route('/calculation', methods=['POST'])
|
860 |
def handle_calculation():
|
861 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
862 |
response = {
|
863 |
"actual_profile": {
|
864 |
"P": 0, "K": 0, "Mg": 0, "Ca": 0, "S": 0,
|
@@ -872,48 +887,46 @@ def handle_calculation():
|
|
872 |
},
|
873 |
"total_ppm": 0,
|
874 |
"deficits": {},
|
875 |
-
"error": None
|
|
|
876 |
}
|
877 |
|
|
|
878 |
try:
|
879 |
-
# Пытаемся получить данные (без проверок)
|
880 |
-
data = request.get_json() or {}
|
881 |
-
|
882 |
-
# Кривая имитация расчета (в реальности тут ваш калькулятор)
|
883 |
if data:
|
884 |
-
|
885 |
-
|
886 |
-
"
|
887 |
-
"
|
888 |
-
"
|
889 |
-
"
|
890 |
-
"
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
no3_ratio = float(data.get("profileSettings", {}).get("NO3_RAT", 0)) or 0
|
897 |
-
nh4_ratio = 1.0
|
898 |
-
|
899 |
response["nitrogen_ratios"] = {
|
900 |
-
"NH4_RATIO":
|
901 |
"NO3_RATIO": no3_ratio,
|
902 |
"TOTAL_NITROGEN": total_n
|
903 |
}
|
904 |
-
|
905 |
-
#
|
906 |
-
|
907 |
-
"
|
908 |
-
|
|
|
|
|
909 |
|
910 |
except Exception as e:
|
911 |
-
|
912 |
-
response["error"] = str(e)
|
913 |
|
914 |
-
#
|
915 |
return jsonify(response), 200
|
916 |
|
|
|
|
|
917 |
|
918 |
|
919 |
|
|
|
856 |
|
857 |
|
858 |
|
859 |
+
from flask import Flask, request, jsonify
|
860 |
+
import json
|
861 |
+
|
862 |
+
app = Flask(__name__)
|
863 |
+
|
864 |
@app.route('/calculation', methods=['POST'])
|
865 |
def handle_calculation():
|
866 |
+
# 1. Выводим в консоль ВСЕ полученные данные
|
867 |
+
print("\n=== ВХОДЯЩИЕ ДАННЫЕ ===")
|
868 |
+
try:
|
869 |
+
raw_data = request.get_data(as_text=True)
|
870 |
+
print(raw_data)
|
871 |
+
data = json.loads(raw_data)
|
872 |
+
except Exception as e:
|
873 |
+
print(f"Ошибка парсинга JSON: {str(e)}")
|
874 |
+
data = {}
|
875 |
+
|
876 |
+
# 2. Дефолтный ответ
|
877 |
response = {
|
878 |
"actual_profile": {
|
879 |
"P": 0, "K": 0, "Mg": 0, "Ca": 0, "S": 0,
|
|
|
887 |
},
|
888 |
"total_ppm": 0,
|
889 |
"deficits": {},
|
890 |
+
"error": None,
|
891 |
+
"received_data": data # Возвращаем обратно полученные данные
|
892 |
}
|
893 |
|
894 |
+
# 3. Примитивный "расчет" без проверок
|
895 |
try:
|
|
|
|
|
|
|
|
|
896 |
if data:
|
897 |
+
# Просто копируем часть данных в ответ
|
898 |
+
response["actual_profile"].update({
|
899 |
+
"P": data.get("profileSettings", {}).get("P", 0),
|
900 |
+
"K": data.get("profileSettings", {}).get("K", 0),
|
901 |
+
"Mg": data.get("profileSettings", {}).get("Mg", 0),
|
902 |
+
"Ca": data.get("profileSettings", {}).get("Ca", 0),
|
903 |
+
"S": data.get("profileSettings", {}).get("S", 0)
|
904 |
+
})
|
905 |
+
|
906 |
+
# Фиктивные расчеты азота
|
907 |
+
total_n = data.get("profileSettings", {}).get("TOTAL_NITROG", 0) or 0
|
908 |
+
no3_ratio = data.get("profileSettings", {}).get("NO3_RAT", 0) or 0
|
|
|
|
|
|
|
909 |
response["nitrogen_ratios"] = {
|
910 |
+
"NH4_RATIO": 1,
|
911 |
"NO3_RATIO": no3_ratio,
|
912 |
"TOTAL_NITROGEN": total_n
|
913 |
}
|
914 |
+
|
915 |
+
# Фиктивные удобрения
|
916 |
+
if "fertilizerConstants" in data:
|
917 |
+
response["fertilizers"] = {
|
918 |
+
name: {"граммы": 0}
|
919 |
+
for name in data["fertilizerConstants"]
|
920 |
+
}
|
921 |
|
922 |
except Exception as e:
|
923 |
+
response["error"] = f"Calculation error: {str(e)}"
|
|
|
924 |
|
925 |
+
# 4. Всегда возвращаем 200 OK
|
926 |
return jsonify(response), 200
|
927 |
|
928 |
+
if __name__ == "__main__":
|
929 |
+
app.run(host="0.0.0.0", port=5000, debug=True)
|
930 |
|
931 |
|
932 |
|