Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -727,12 +727,12 @@ EC_COEFFICIENTS = {
|
|
727 |
}
|
728 |
|
729 |
class NutrientCalculator:
|
730 |
-
def __init__(self, volume_liters=1.0, profile=
|
731 |
self.volume = volume_liters
|
732 |
self.results = {}
|
733 |
-
self.target_profile = profile.copy()
|
734 |
self.actual_profile = {k: 0.0 for k in self.target_profile}
|
735 |
-
self.fertilizers = NUTRIENT_CONTENT_IN_FERTILIZERS
|
736 |
self.total_ec = 0.0
|
737 |
|
738 |
# Расчёт азота
|
@@ -752,7 +752,7 @@ class NutrientCalculator:
|
|
752 |
"K": {"weight": 0.2, "fert": "Калий азотнокислый", "main_element": "K"},
|
753 |
"Mg": {"weight": 0.2, "fert": "Сульфат магния", "main_element": "Mg"},
|
754 |
"P": {"weight": 0.1, "fert": "Монофосфат калия", "main_element": "P"},
|
755 |
-
"S": {"weight": 0.1, "fert": "
|
756 |
"N (NO3-)": {"weight": 0.05, "fert": "Калий азотнокислый", "main_element": "N (NO3-)"},
|
757 |
"N (NH4+)": {"weight": 0.05, "fert": "Аммоний азотнокислый", "main_element": "N (NH4+)"}
|
758 |
}
|
@@ -767,23 +767,45 @@ class NutrientCalculator:
|
|
767 |
|
768 |
def calculate(self):
|
769 |
try:
|
770 |
-
#
|
771 |
-
|
|
|
|
|
|
|
|
|
|
|
772 |
|
773 |
-
|
774 |
-
|
|
|
775 |
|
776 |
-
|
777 |
-
|
|
|
778 |
|
779 |
-
|
780 |
-
|
781 |
|
782 |
return self.results
|
783 |
except Exception as e:
|
784 |
print(f"Ошибка при расчёте: {str(e)}")
|
785 |
raise
|
786 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
787 |
def _compensate_main_elements(self):
|
788 |
"""Компенсация основных элементов (Ca, Mg, P)"""
|
789 |
for element, weight_data in self.compensation_weights.items():
|
|
|
727 |
}
|
728 |
|
729 |
class NutrientCalculator:
|
730 |
+
def __init__(self, volume_liters=1.0, profile=None):
|
731 |
self.volume = volume_liters
|
732 |
self.results = {}
|
733 |
+
self.target_profile = profile.copy() if profile else BASE_PROFILE.copy()
|
734 |
self.actual_profile = {k: 0.0 for k in self.target_profile}
|
735 |
+
self.fertilizers = NUTRIENT_CONTENT_IN_FERTILIZERS
|
736 |
self.total_ec = 0.0
|
737 |
|
738 |
# Расчёт азота
|
|
|
752 |
"K": {"weight": 0.2, "fert": "Калий азотнокислый", "main_element": "K"},
|
753 |
"Mg": {"weight": 0.2, "fert": "Сульфат магния", "main_element": "Mg"},
|
754 |
"P": {"weight": 0.1, "fert": "Монофосфат калия", "main_element": "P"},
|
755 |
+
"S": {"weight": 0.1, "fert": "Сульфат кальция", "main_element": "S"},
|
756 |
"N (NO3-)": {"weight": 0.05, "fert": "Калий азотнокислый", "main_element": "N (NO3-)"},
|
757 |
"N (NH4+)": {"weight": 0.05, "fert": "Аммоний азотнокислый", "main_element": "N (NH4+)"}
|
758 |
}
|
|
|
767 |
|
768 |
def calculate(self):
|
769 |
try:
|
770 |
+
max_iterations = 10 # Максимальное количество итераций для корректировки
|
771 |
+
iteration = 0
|
772 |
+
while iteration < max_iterations:
|
773 |
+
self._reset_actual_profile()
|
774 |
+
self._compensate_main_elements()
|
775 |
+
self._compensate_nitrogen()
|
776 |
+
self._compensate_secondary_elements()
|
777 |
|
778 |
+
# Проверка результатов
|
779 |
+
if self.validate_results():
|
780 |
+
break
|
781 |
|
782 |
+
# Корректировка перебора
|
783 |
+
self._adjust_overages()
|
784 |
+
iteration += 1
|
785 |
|
786 |
+
if iteration == max_iterations:
|
787 |
+
raise ValueError("Не удалось достичь целевых значений после максимального количества итераций.")
|
788 |
|
789 |
return self.results
|
790 |
except Exception as e:
|
791 |
print(f"Ошибка при расчёте: {str(e)}")
|
792 |
raise
|
793 |
|
794 |
+
def validate_results(self):
|
795 |
+
"""Проверка соответствия целевым значениям"""
|
796 |
+
for element, target_value in self.target_profile.items():
|
797 |
+
actual_value = self.actual_profile[element]
|
798 |
+
if abs(actual_value - target_value) > 0.1: # Допустимая погрешность
|
799 |
+
print(f"Несоответствие: {element} (цель: {target_value:.2f}, фактически: {actual_value:.2f})")
|
800 |
+
return False
|
801 |
+
return True
|
802 |
+
|
803 |
+
def _reset_actual_profile(self):
|
804 |
+
"""Сброс фактического профиля перед новой итерацией"""
|
805 |
+
self.actual_profile = {k: 0.0 for k in self.target_profile}
|
806 |
+
self.total_ec = 0.0
|
807 |
+
self.results = {}
|
808 |
+
|
809 |
def _compensate_main_elements(self):
|
810 |
"""Компенсация основных элементов (Ca, Mg, P)"""
|
811 |
for element, weight_data in self.compensation_weights.items():
|