DmitrMakeev commited on
Commit
cb27861
·
verified ·
1 Parent(s): 08a55df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -719,7 +719,10 @@ 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
  }
724
 
725
  EC_COEFFICIENTS = {
@@ -799,7 +802,7 @@ class NutrientCalculator:
799
  self.total_ec = 0.0
800
  self.best_solution = None
801
  self.min_difference = float('inf')
802
- self.max_recursion_depth = 5000 # Увеличиваем глубину поиска
803
  self.current_depth = 0
804
 
805
  # Расчёт азота
@@ -830,7 +833,7 @@ class NutrientCalculator:
830
  print(f"Ошибка при расчёте: {str(e)}")
831
  raise
832
 
833
- def _backtrack_search(self, fertilizer_index=0, step=1.0):
834
  self.current_depth += 1
835
  if self.current_depth > self.max_recursion_depth:
836
  return False
@@ -871,7 +874,7 @@ class NutrientCalculator:
871
  self._remove_fertilizer(fert_name, step)
872
 
873
  # Уменьшаем шаг для более точного поиска
874
- if step > 0.1:
875
  if self._backtrack_search(i, step / 2):
876
  return True
877
 
@@ -881,7 +884,7 @@ class NutrientCalculator:
881
  """Проверяет, можно ли применить удобрение без перебора"""
882
  for element, content in zip(nutrients_stencil, fert_composition.vector):
883
  added_ppm = (1 * content * 1000) / self.volume
884
- if self.actual_profile[element] + added_ppm > self.target_profile[element] * 1.03: # Разрешаем перерасход на 3%
885
  return False
886
  return True
887
 
@@ -923,7 +926,7 @@ class NutrientCalculator:
923
  def _calculate_difference(self, current_composition):
924
  """Вычисляет общее отклонение от целевого профиля с учетом весов"""
925
  diff_vector = self.target_composition.vector - current_composition.vector
926
- weights = np.array([1.5 if el in ['K', 'S', 'Mg'] else 1.0 for el in nutrients_stencil])
927
  return np.sum(np.abs(diff_vector) * weights)
928
 
929
  def _copy_results(self):
@@ -942,9 +945,9 @@ class NutrientCalculator:
942
  for fert_name, fert in self.fertilizers.items():
943
  for i, nutrient in enumerate(nutrients_stencil):
944
  deficit = self.target_profile[nutrient] - self.actual_profile[nutrient]
945
- if deficit > 2.0 and fert.vector[i] > 0: # Если дефицит больше 2 ppm
946
  small_amount = deficit * self.volume / (fert.vector[i] * 1000)
947
- self._apply_fertilizer(fert_name, min(small_amount, 2.0)) # Не больше 2 г
948
 
949
  def generate_report(self):
950
  """Генерация отчета о питательном растворе"""
@@ -975,7 +978,6 @@ if __name__ == "__main__":
975
 
976
 
977
 
978
-
979
  @app.route('/calculation', methods=['POST'])
980
  def handle_calculation():
981
  try:
 
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
  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
  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
  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
  """Проверяет, можно ли применить удобрение без перебора"""
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
  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
  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
  """Генерация отчета о питательном растворе"""
 
978
 
979
 
980
 
 
981
  @app.route('/calculation', methods=['POST'])
982
  def handle_calculation():
983
  try: