Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -853,35 +853,35 @@ class NutrientCalculator:
|
|
853 |
raise
|
854 |
|
855 |
def _compensate_element(self, element):
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
|
860 |
-
|
861 |
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
|
886 |
def calculate_ec(self):
|
887 |
return round(self.total_ec, 2)
|
|
|
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:
|
858 |
+
return
|
859 |
|
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 |
+
if element in self.fertilizers.get(fert_name, {}):
|
871 |
+
candidates.append({
|
872 |
+
'name': fert_name,
|
873 |
+
'weight': weight_data["weight"],
|
874 |
+
'content': self.fertilizers[fert_name][element]
|
875 |
+
})
|
876 |
+
|
877 |
+
if not candidates:
|
878 |
+
raise ValueError(f"Нет удобрений для элемента {element}")
|
879 |
+
|
880 |
+
total_weight = sum(abs(c['weight']) for c in candidates) # Берем модуль весов
|
881 |
+
for candidate in candidates:
|
882 |
+
share = abs(candidate['weight']) / total_weight # Используем модуль веса
|
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)
|