DmitrMakeev commited on
Commit
c5b5633
·
verified ·
1 Parent(s): 93b6d7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -13
app.py CHANGED
@@ -886,24 +886,45 @@ def handle_calculation():
886
  print("\n=== ВХОДНЫЕ ДАННЫЕ ===")
887
  print(json.dumps(data, indent=2, ensure_ascii=False))
888
 
889
- # 2. Добавляем "Кальций хлористый", если его нет
890
- if "Кальций хлорид" not in data["fertilizerConstants"]:
891
- data["fertilizerConstants"]["Кальций хлорид"] = {"Ca": 0.18294, "Cl": 0.32366}
892
-
893
- # 3. Создаем и запускаем калькулятор
894
- calculator = NutrientCalculator(data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
895
  results = calculator.calculate()
896
 
897
- # 4. Формируем дополнительные данные
898
  element_contributions = {}
899
  for fert_name in calculator.fertilizers.keys():
900
  grams = calculator.results[fert_name]['граммы']
901
  element_contributions[fert_name] = {}
902
  for element, percent in calculator.fertilizers[fert_name].items():
903
  added_ppm = (grams * percent * 1000) / calculator.volume
904
- element_contributions[fert_name][element] = round(added_ppm, 3)
905
 
906
- # 5. Формируем полный ответ
907
  response = {
908
  "fertilizers": results['fertilizers'],
909
  "actual_profile": results['actual_profile'],
@@ -912,8 +933,8 @@ def handle_calculation():
912
  "element_contributions": element_contributions,
913
  "nitrogen_ratios": {
914
  "NH4_RATIO": 1,
915
- "NO3_RATIO": data.get("profileSettings", {}).get("NO3_RAT", 0),
916
- "TOTAL_NITROGEN": data.get("profileSettings", {}).get("TOTAL_NITROG", 0)
917
  }
918
  }
919
 
@@ -936,8 +957,6 @@ def handle_calculation():
936
 
937
 
938
 
939
-
940
-
941
 
942
 
943
  if __name__ == '__main__':
 
886
  print("\n=== ВХОДНЫЕ ДАННЫЕ ===")
887
  print(json.dumps(data, indent=2, ensure_ascii=False))
888
 
889
+ # 2. Извлекаем основные параметры
890
+ fertilizer_constants = data.get("fertilizerConstants", {})
891
+ profile_settings = data.get("profileSettings", {})
892
+
893
+ # Проверяем наличие необходимых полей
894
+ if not fertilizer_constants or not profile_settings:
895
+ return jsonify({"error": "Missing fertilizerConstants or profileSettings"}), 400
896
+
897
+ # 3. Извлекаем дополнительные параметры
898
+ liters = profile_settings.get("liters", 100) # Объем раствора (литры)
899
+ rounding_precision = profile_settings.get("rounding_precision", 3) # Точность округления
900
+ activation_cacl = profile_settings.get("activation_cacl", 0) # Активация CaCl
901
+ enhancement_cacl = profile_settings.get("enhancement_cacl", 0) # Усиление CaCl
902
+
903
+ # 4. Добавляем "Кальций хлористый", если его нет
904
+ if "Кальций хлорид" not in fertilizer_constants:
905
+ fertilizer_constants["Кальций хлорид"] = {"Ca": 0.18294, "Cl": 0.32366}
906
+
907
+ # 5. Создаем и запускаем калькулятор
908
+ calculator = NutrientCalculator(
909
+ fertilizer_constants=fertilizer_constants,
910
+ profile_settings=profile_settings,
911
+ liters=liters,
912
+ rounding_precision=rounding_precision,
913
+ activation_cacl=activation_cacl,
914
+ enhancement_cacl=enhancement_cacl
915
+ )
916
  results = calculator.calculate()
917
 
918
+ # 6. Формируем дополнительные данные
919
  element_contributions = {}
920
  for fert_name in calculator.fertilizers.keys():
921
  grams = calculator.results[fert_name]['граммы']
922
  element_contributions[fert_name] = {}
923
  for element, percent in calculator.fertilizers[fert_name].items():
924
  added_ppm = (grams * percent * 1000) / calculator.volume
925
+ element_contributions[fert_name][element] = round(added_ppm, rounding_precision)
926
 
927
+ # 7. Формируем полный ответ
928
  response = {
929
  "fertilizers": results['fertilizers'],
930
  "actual_profile": results['actual_profile'],
 
933
  "element_contributions": element_contributions,
934
  "nitrogen_ratios": {
935
  "NH4_RATIO": 1,
936
+ "NO3_RATIO": profile_settings.get("NO3_RAT", 0),
937
+ "TOTAL_NITROGEN": profile_settings.get("TOTAL_NITROG", 0)
938
  }
939
  }
940
 
 
957
 
958
 
959
 
 
 
960
 
961
 
962
  if __name__ == '__main__':