DmitrMakeev commited on
Commit
9b8498a
·
verified ·
1 Parent(s): e73da3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -8
app.py CHANGED
@@ -866,7 +866,66 @@ class NutrientCalculator:
866
  print(f"Ошибка при расчёте: {str(e)}")
867
  raise
868
 
869
- # ... остальные методы класса NutrientCalculator ...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
870
 
871
  def round_floats(obj: Union[float, Dict, List], ndigits: int = 3) -> Union[float, Dict, List]:
872
  """Рекурсивно округляет все float значения в структуре данных"""
@@ -877,13 +936,8 @@ def round_floats(obj: Union[float, Dict, List], ndigits: int = 3) -> Union[float
877
  elif isinstance(obj, (list, tuple)):
878
  return [round_floats(x, ndigits) for x in obj]
879
  return obj
880
- if __name__ == "__main__":
881
- try:
882
- calculator = NutrientCalculator(volume_liters=VOLUME_LITERS)
883
- calculator.calculate()
884
- calculator.print_report()
885
- except Exception as e:
886
- print(f"Критическая ошибка: {str(e)}")
887
  @app.route('/calculation', methods=['POST'])
888
  def handle_calculation():
889
  try:
 
866
  print(f"Ошибка при расчёте: {str(e)}")
867
  raise
868
 
869
+
870
+ def calculate_ec(self):
871
+ return round(self.total_ec, 2)
872
+
873
+ def print_report(self):
874
+ try:
875
+ print("\n" + "="*60)
876
+ print("ПРОФИЛЬ ПИТАТЕЛЬНОГО РАСТВОРА (ИТОГО):")
877
+ print("="*60)
878
+ table = [[el, round(self.actual_profile[el], 1)] for el in self.actual_profile]
879
+ print(tabulate(table, headers=["Элемент", "ppm"]))
880
+
881
+ print("\nИсходный расчёт азота:")
882
+ for form, val in self.initial_n_profile.items():
883
+ print(f" {form}: {round(val, 1)} ppm")
884
+
885
+ print("\n" + "="*60)
886
+ print(f"РАСЧЕТ ДЛЯ {self.volume} ЛИТРОВ РАСТВОРА")
887
+ print("="*60)
888
+ print(f"Общая концентрация: {round(sum(self.actual_profile.values()), 1)} ppm")
889
+ print(f"EC: {self.calculate_ec()} mS/cm")
890
+
891
+ print("\nРЕКОМЕНДУЕМЫЕ УДОБРЕНИЯ:")
892
+ fert_table = []
893
+ for fert, data in self.results.items():
894
+ adds = [f"+{k}: {v:.1f} ppm" for k, v in data.items() if k.startswith('внесет')]
895
+ fert_table.append([
896
+ fert,
897
+ round(data['граммы'], 3),
898
+ data['миллиграммы'],
899
+ round(data['вклад в EC'], 3),
900
+ "\n".join(adds)
901
+ ])
902
+ print(tabulate(fert_table,
903
+ headers=["Удобрение", "Граммы", "Миллиграммы", "EC (мСм/см)", "Добавит"]))
904
+
905
+ print("\nОСТАТОЧНЫЙ ДЕФИЦИТ:")
906
+ deficit = {
907
+ k: round(self.target_profile[k] - self.actual_profile[k], 1)
908
+ for k in self.target_profile
909
+ if abs(self.target_profile[k] - self.actual_profile[k]) > 0.1
910
+ }
911
+ if deficit:
912
+ for el, val in deficit.items():
913
+ print(f" {el}: {val} ppm")
914
+ else:
915
+ print(" Все элементы покрыты полностью")
916
+ except Exception as e:
917
+ print(f"Ошибка при выводе отчёта: {str(e)}")
918
+ raise
919
+
920
+ if __name__ == "__main__":
921
+ try:
922
+ calculator = NutrientCalculator(volume_liters=VOLUME_LITERS)
923
+ calculator.calculate()
924
+ calculator.print_report() # Правильный вызов метода класса
925
+ except Exception as e:
926
+ print(f"Критическая ошибка: {str(e)}")
927
+
928
+
929
 
930
  def round_floats(obj: Union[float, Dict, List], ndigits: int = 3) -> Union[float, Dict, List]:
931
  """Рекурсивно округляет все float значения в структуре данных"""
 
936
  elif isinstance(obj, (list, tuple)):
937
  return [round_floats(x, ndigits) for x in obj]
938
  return obj
939
+
940
+
 
 
 
 
 
941
  @app.route('/calculation', methods=['POST'])
942
  def handle_calculation():
943
  try: