DmitrMakeev commited on
Commit
0bc943e
·
verified ·
1 Parent(s): 2235e3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -24
app.py CHANGED
@@ -854,38 +854,67 @@ calculator = NutrientCalculator(INPUT_DATA)
854
  results = calculator.calculate()
855
  print(calculator.generate_report(results))
856
 
 
 
 
 
857
  @app.route('/calculation', methods=['POST'])
858
  def handle_calculation():
859
- # 1. Создаем экземпляр "говнокалькулятора"
860
- calculator = ShittyCalculator()
861
-
862
- # 2. Пытаемся что-то получить из запроса (но не проверяем!)
863
- try:
864
- data = request.get_json() or {}
865
- except:
866
- data = {}
867
-
868
- # 3. Выполняем "расчет" (на самом деле просто возвращаем хардкод)
869
- result = calculator.calculate(data)
870
-
871
- # 4. Формируем ответ с любым мусором
872
  response = {
873
- "actual_profile": result["actual_profile"],
874
- "fertilizers": result["fertilizers"],
 
 
 
875
  "nitrogen_ratios": {
876
- "NH4_RATIO": -1.0 if data else 8.35,
877
- "NO3_RATIO": -666.0 if data else 1.0,
878
- "TOTAL_NITROGEN": -100.0 if data else 125.0
879
  },
880
- "total_ppm": result["total_ppm"],
881
- "deficits": result["deficits"],
882
- "warning": result["warning"],
883
  "error": None
884
  }
885
-
886
- # 5. Возвращаем ОБЯЗАТЕЛЬНО с кодом 200
887
- return jsonify(response), 200
888
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
889
 
890
 
891
 
 
854
  results = calculator.calculate()
855
  print(calculator.generate_report(results))
856
 
857
+ from flask import Flask, request, jsonify
858
+
859
+ app = Flask(__name__)
860
+
861
  @app.route('/calculation', methods=['POST'])
862
  def handle_calculation():
863
+ # Дефолтный ответ с нулями и пустыми значениями
 
 
 
 
 
 
 
 
 
 
 
 
864
  response = {
865
+ "actual_profile": {
866
+ "P": 0, "K": 0, "Mg": 0, "Ca": 0, "S": 0,
867
+ "N (NO3-)": 0, "N (NH4+)": 0
868
+ },
869
+ "fertilizers": {},
870
  "nitrogen_ratios": {
871
+ "NH4_RATIO": 0,
872
+ "NO3_RATIO": 0,
873
+ "TOTAL_NITROGEN": 0
874
  },
875
+ "total_ppm": 0,
876
+ "deficits": {},
 
877
  "error": None
878
  }
 
 
 
879
 
880
+ try:
881
+ # Пытаемся получить данные (без проверок)
882
+ data = request.get_json() or {}
883
+
884
+ # Кривая имитация расчета (в реальности тут ваш калькулятор)
885
+ if data:
886
+ response["actual_profile"] = {
887
+ "P": float(data.get("profileSettings", {}).get("P", 0)) or 0,
888
+ "K": float(data.get("profileSettings", {}).get("K", 0)) or 0,
889
+ "Mg": float(data.get("profileSettings", {}).get("Mg", 0)) or 0,
890
+ "Ca": float(data.get("profileSettings", {}).get("Ca", 0)) or 0,
891
+ "S": float(data.get("profileSettings", {}).get("S", 0)) or 0,
892
+ "N (NO3-)": 0,
893
+ "N (NH4+)": 0
894
+ }
895
+
896
+ # Кривая логика азота
897
+ total_n = float(data.get("profileSettings", {}).get("TOTAL_NITROG", 0)) or 0
898
+ no3_ratio = float(data.get("profileSettings", {}).get("NO3_RAT", 0)) or 0
899
+ nh4_ratio = 1.0
900
+
901
+ response["nitrogen_ratios"] = {
902
+ "NH4_RATIO": nh4_ratio,
903
+ "NO3_RATIO": no3_ratio,
904
+ "TOTAL_NITROGEN": total_n
905
+ }
906
+
907
+ # Заглушка для удобрений
908
+ response["fertilizers"] = {
909
+ "Заглушка": {"граммы": 0}
910
+ }
911
+
912
+ except Exception as e:
913
+ # Логируем ошибку, но все равно возвращаем ответ
914
+ response["error"] = str(e)
915
+
916
+ # ВСЕГДА возвращаем 200 OK
917
+ return jsonify(response), 200
918
 
919
 
920