DmitrMakeev commited on
Commit
8048f77
·
verified ·
1 Parent(s): cb27861

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -692,6 +692,7 @@ def nutri_call():
692
 
693
 
694
 
 
695
  from tabulate import tabulate
696
  import numpy as np
697
 
@@ -719,10 +720,7 @@ NUTRIENT_CONTENT_IN_FERTILIZERS = {
719
  "Сульфат магния": {"Mg": 0.09861, "S": 0.13010},
720
  "Монофосфат калия": {"P": 0.218, "K": 0.275},
721
  "Сульфат кальция": {"Ca": 0.23, "S": 0.186},
722
- "Кольцевая селитра": {"N (NO3-)": 0.15, "Ca": 0.20},
723
- "Калий хлористый": {"K": 0.50}, # Новое удобрение
724
- "Сульфат калия двойной": {"K": 0.40, "S": 0.17}, # Новое удобрение
725
- "Магний хелатированный": {"Mg": 0.12} # Новое удобрение
726
  }
727
 
728
  EC_COEFFICIENTS = {
@@ -802,7 +800,7 @@ class NutrientCalculator:
802
  self.total_ec = 0.0
803
  self.best_solution = None
804
  self.min_difference = float('inf')
805
- self.max_recursion_depth = 5000
806
  self.current_depth = 0
807
 
808
  # Расчёт азота
@@ -833,7 +831,7 @@ class NutrientCalculator:
833
  print(f"Ошибка при расчёте: {str(e)}")
834
  raise
835
 
836
- def _backtrack_search(self, fertilizer_index=0, step=0.01):
837
  self.current_depth += 1
838
  if self.current_depth > self.max_recursion_depth:
839
  return False
@@ -874,7 +872,7 @@ class NutrientCalculator:
874
  self._remove_fertilizer(fert_name, step)
875
 
876
  # Уменьшаем шаг для более точного поиска
877
- if step > 0.01:
878
  if self._backtrack_search(i, step / 2):
879
  return True
880
 
@@ -884,7 +882,7 @@ class NutrientCalculator:
884
  """Проверяет, можно ли применить удобрение без перебора"""
885
  for element, content in zip(nutrients_stencil, fert_composition.vector):
886
  added_ppm = (1 * content * 1000) / self.volume
887
- if self.actual_profile[element] + added_ppm > self.target_profile[element] * 1.05: # Разрешаем перерасход на 5%
888
  return False
889
  return True
890
 
@@ -926,7 +924,7 @@ class NutrientCalculator:
926
  def _calculate_difference(self, current_composition):
927
  """Вычисляет общее отклонение от целевого профиля с учетом весов"""
928
  diff_vector = self.target_composition.vector - current_composition.vector
929
- weights = np.array([2.0 if el in ['K', 'S', 'Mg'] else 1.0 for el in nutrients_stencil])
930
  return np.sum(np.abs(diff_vector) * weights)
931
 
932
  def _copy_results(self):
@@ -945,9 +943,9 @@ class NutrientCalculator:
945
  for fert_name, fert in self.fertilizers.items():
946
  for i, nutrient in enumerate(nutrients_stencil):
947
  deficit = self.target_profile[nutrient] - self.actual_profile[nutrient]
948
- if deficit > 1.0 and fert.vector[i] > 0: # Если дефицит больше 1 ppm
949
  small_amount = deficit * self.volume / (fert.vector[i] * 1000)
950
- self._apply_fertilizer(fert_name, min(small_amount, 1.0)) # Не больше 1 г
951
 
952
  def generate_report(self):
953
  """Генерация отчета о питательном растворе"""
 
692
 
693
 
694
 
695
+
696
  from tabulate import tabulate
697
  import numpy as np
698
 
 
720
  "Сульфат магния": {"Mg": 0.09861, "S": 0.13010},
721
  "Монофосфат калия": {"P": 0.218, "K": 0.275},
722
  "Сульфат кальция": {"Ca": 0.23, "S": 0.186},
723
+ "Кольцевая селитра": {"N (NO3-)": 0.15, "Ca": 0.20} # Новое удобрение
 
 
 
724
  }
725
 
726
  EC_COEFFICIENTS = {
 
800
  self.total_ec = 0.0
801
  self.best_solution = None
802
  self.min_difference = float('inf')
803
+ self.max_recursion_depth = 5000 # Увеличиваем глубину поиска
804
  self.current_depth = 0
805
 
806
  # Расчёт азота
 
831
  print(f"Ошибка при расчёте: {str(e)}")
832
  raise
833
 
834
+ def _backtrack_search(self, fertilizer_index=0, step=1.0):
835
  self.current_depth += 1
836
  if self.current_depth > self.max_recursion_depth:
837
  return False
 
872
  self._remove_fertilizer(fert_name, step)
873
 
874
  # Уменьшаем шаг для более точного поиска
875
+ if step > 0.1:
876
  if self._backtrack_search(i, step / 2):
877
  return True
878
 
 
882
  """Проверяет, можно ли применить удобрение без перебора"""
883
  for element, content in zip(nutrients_stencil, fert_composition.vector):
884
  added_ppm = (1 * content * 1000) / self.volume
885
+ if self.actual_profile[element] + added_ppm > self.target_profile[element] * 1.03: # Разрешаем перерасход на 3%
886
  return False
887
  return True
888
 
 
924
  def _calculate_difference(self, current_composition):
925
  """Вычисляет общее отклонение от целевого профиля с учетом весов"""
926
  diff_vector = self.target_composition.vector - current_composition.vector
927
+ weights = np.array([1.5 if el in ['K', 'S', 'Mg'] else 1.0 for el in nutrients_stencil])
928
  return np.sum(np.abs(diff_vector) * weights)
929
 
930
  def _copy_results(self):
 
943
  for fert_name, fert in self.fertilizers.items():
944
  for i, nutrient in enumerate(nutrients_stencil):
945
  deficit = self.target_profile[nutrient] - self.actual_profile[nutrient]
946
+ if deficit > 2.0 and fert.vector[i] > 0: # Если дефицит больше 2 ppm
947
  small_amount = deficit * self.volume / (fert.vector[i] * 1000)
948
+ self._apply_fertilizer(fert_name, min(small_amount, 2.0)) # Не больше 2 г
949
 
950
  def generate_report(self):
951
  """Генерация отчета о питательном растворе"""