Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -852,6 +852,7 @@ class NutrientCalculator:
|
|
852 |
print(f"Ошибка: отсутствует элемент {str(e)} в удобрении {fert_name}")
|
853 |
raise
|
854 |
|
|
|
855 |
def _compensate_element(self, element):
|
856 |
needed = self.target_profile[element] - self.actual_profile.get(element, 0)
|
857 |
if needed <= 0:
|
@@ -860,14 +861,17 @@ class NutrientCalculator:
|
|
860 |
candidates = []
|
861 |
|
862 |
# Для азотных соединений особый случай
|
863 |
-
if element in ['NH4', 'NO3']:
|
864 |
# Здесь ваша текущая логика для NH4 и NO3
|
865 |
pass
|
866 |
else:
|
867 |
# Стандартная компенсация для других элементов
|
868 |
for weight_key, weight_data in self.element_compensation_weights.items():
|
869 |
fert_name = weight_data["fert"]
|
870 |
-
|
|
|
|
|
|
|
871 |
candidates.append({
|
872 |
'name': fert_name,
|
873 |
'weight': weight_data["weight"],
|
@@ -877,11 +881,25 @@ class NutrientCalculator:
|
|
877 |
if not candidates:
|
878 |
raise ValueError(f"Нет удобрений для элемента {element}")
|
879 |
|
880 |
-
|
|
|
|
|
|
|
|
|
881 |
for candidate in candidates:
|
882 |
-
|
883 |
ppm_to_apply = needed * share
|
884 |
self._apply(candidate['name'], element, ppm_to_apply)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
885 |
|
886 |
def calculate_ec(self):
|
887 |
return round(self.total_ec, 2)
|
|
|
852 |
print(f"Ошибка: отсутствует элемент {str(e)} в удобрении {fert_name}")
|
853 |
raise
|
854 |
|
855 |
+
|
856 |
def _compensate_element(self, element):
|
857 |
needed = self.target_profile[element] - self.actual_profile.get(element, 0)
|
858 |
if needed <= 0:
|
|
|
861 |
candidates = []
|
862 |
|
863 |
# Для азотных соединений особый случай
|
864 |
+
if element in ['N (NH4+)', 'N (NO3-)']:
|
865 |
# Здесь ваша текущая логика для NH4 и NO3
|
866 |
pass
|
867 |
else:
|
868 |
# Стандартная компенсация для других элементов
|
869 |
for weight_key, weight_data in self.element_compensation_weights.items():
|
870 |
fert_name = weight_data["fert"]
|
871 |
+
main_element = weight_data["main_element"]
|
872 |
+
|
873 |
+
# Проверяем, что удобрение содержит нужный элемент
|
874 |
+
if main_element == element and element in self.fertilizers.get(fert_name, {}):
|
875 |
candidates.append({
|
876 |
'name': fert_name,
|
877 |
'weight': weight_data["weight"],
|
|
|
881 |
if not candidates:
|
882 |
raise ValueError(f"Нет удобрений для элемента {element}")
|
883 |
|
884 |
+
# Для отрицательных весов нужно инвертировать знак needed
|
885 |
+
if any(c['weight'] < 0 for c in candidates):
|
886 |
+
needed = -needed
|
887 |
+
|
888 |
+
total_weight = sum(c['weight'] for c in candidates)
|
889 |
for candidate in candidates:
|
890 |
+
share = candidate['weight'] / total_weight
|
891 |
ppm_to_apply = needed * share
|
892 |
self._apply(candidate['name'], element, ppm_to_apply)
|
893 |
+
})
|
894 |
+
|
895 |
+
if not candidates:
|
896 |
+
raise ValueError(f"Нет удобрений для элемента {element}")
|
897 |
+
|
898 |
+
total_weight = sum(abs(c['weight']) for c in candidates) # Берем модуль весов
|
899 |
+
for candidate in candidates:
|
900 |
+
share = abs(candidate['weight']) / total_weight # Используем модуль веса
|
901 |
+
ppm_to_apply = needed * share
|
902 |
+
self._apply(candidate['name'], element, ppm_to_apply)
|
903 |
|
904 |
def calculate_ec(self):
|
905 |
return round(self.total_ec, 2)
|