DmitrMakeev commited on
Commit
2235e3a
·
verified ·
1 Parent(s): 497313b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -79
app.py CHANGED
@@ -856,89 +856,35 @@ print(calculator.generate_report(results))
856
 
857
  @app.route('/calculation', methods=['POST'])
858
  def handle_calculation():
859
- # Создаем базовый ответ с дефолтными значениями
 
 
 
 
 
 
 
 
 
 
 
 
860
  response = {
861
- "actual_profile": {},
862
- "fertilizers": {},
863
  "nitrogen_ratios": {
864
- "NH4_RATIO": 1.0,
865
- "NO3_RATIO": 8.35,
866
- "TOTAL_NITROGEN": 125.0
867
  },
868
- "total_ppm": 0,
869
- "deficits": {},
870
- "warnings": [],
871
- "errors": None
872
  }
873
-
874
- try:
875
- data = request.get_json()
876
-
877
- # Проверка данных
878
- if not data:
879
- response['errors'] = "Отсутствуют данные в запросе"
880
- return jsonify(response), 200 # Все равно возвращаем 200 OK
881
-
882
- # Инициализация калькулятора
883
- calculator = PrecisionNutrientCalculator()
884
-
885
- # Устанавливаем объем
886
- calculator.volume = float(data.get('profileSettings', {}).get('liters', 100))
887
-
888
- # Базовый профиль с защитой от отсутствия значений
889
- base_profile = {
890
- "P": float(data.get('profileSettings', {}).get('P', 50)),
891
- "K": float(data.get('profileSettings', {}).get('K', 210)),
892
- "Mg": float(data.get('profileSettings', {}).get('Mg', 120)),
893
- "Ca": float(data.get('profileSettings', {}).get('Ca', 150)),
894
- "S": float(data.get('profileSettings', {}).get('S', 100)),
895
- "N (NO3-)": 0,
896
- "N (NH4+)": 0
897
- }
898
-
899
- # Расчет азота
900
- total_n = float(data.get('profileSettings', {}).get('TOTAL_NITROG', 125.0))
901
- no3_ratio = float(data.get('profileSettings', {}).get('NO3_RAT', 8.35))
902
- nh4_ratio = 1.0
903
-
904
- total_parts = no3_ratio + nh4_ratio
905
- base_profile['N (NO3-)'] = total_n * (no3_ratio / total_parts)
906
- base_profile['N (NH4+)'] = total_n * (nh4_ratio / total_parts)
907
-
908
- calculator.target = base_profile
909
- calculator.fertilizers = data.get('fertilizerConstants', NUTRIENT_CONTENT_IN_FERTILIZERS)
910
-
911
- # Защищенный расчет
912
- try:
913
- results = calculator.calculate()
914
- except Exception as calc_error:
915
- response['warnings'].append(f"Ошибка расчета: {str(calc_error)}")
916
- results = {'deficits': {}}
917
-
918
- # Формируем ответ
919
- response.update({
920
- "actual_profile": {k: round(v, 3) for k, v in calculator.actual.items()},
921
- "fertilizers": {k: round(v['граммы'], 3) for k, v in calculator.results.items()},
922
- "nitrogen_ratios": {
923
- "NH4_RATIO": nh4_ratio,
924
- "NO3_RATIO": no3_ratio,
925
- "TOTAL_NITROGEN": total_n
926
- },
927
- "total_ppm": round(sum(calculator.actual.values()), 3),
928
- "deficits": results.get('deficits', {})
929
- })
930
-
931
- # Проверка на отрицательные значения
932
- if any(v < 0 for v in calculator.actual.values()):
933
- response['warnings'].append("Обнаружены отрицательные значения в профиле")
934
-
935
- return jsonify(response), 200
936
-
937
- except Exception as e:
938
- # Логируем ошибку, но все равно возвращаем ответ
939
- print(f"Критическая ошибка: {str(e)}")
940
- response['errors'] = str(e)
941
- return jsonify(response), 200 # Все равно 200 OK
942
 
943
 
944
 
 
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