DmitrMakeev commited on
Commit
e436956
·
verified ·
1 Parent(s): 7bd1608

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -30
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
- response["actual_profile"] = {
885
- "P": float(data.get("profileSettings", {}).get("P", 0)) or 0,
886
- "K": float(data.get("profileSettings", {}).get("K", 0)) or 0,
887
- "Mg": float(data.get("profileSettings", {}).get("Mg", 0)) or 0,
888
- "Ca": float(data.get("profileSettings", {}).get("Ca", 0)) or 0,
889
- "S": float(data.get("profileSettings", {}).get("S", 0)) or 0,
890
- "N (NO3-)": 0,
891
- "N (NH4+)": 0
892
- }
893
-
894
- # Кривая логика азота
895
- total_n = float(data.get("profileSettings", {}).get("TOTAL_NITROG", 0)) or 0
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": nh4_ratio,
901
  "NO3_RATIO": no3_ratio,
902
  "TOTAL_NITROGEN": total_n
903
  }
904
-
905
- # Заглушка для удобрений
906
- response["fertilizers"] = {
907
- "Заглушка": {"граммы": 0}
908
- }
 
 
909
 
910
  except Exception as e:
911
- # Логируем ошибку, но все равно возвращаем ответ
912
- response["error"] = str(e)
913
 
914
- # ВСЕГДА возвращаем 200 OK
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