Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -682,14 +682,13 @@ def view_image():
|
|
682 |
|
683 |
|
684 |
|
685 |
-
|
686 |
from tabulate import tabulate
|
687 |
|
688 |
# Константы для расчёта
|
689 |
TOTAL_NITROGEN = 125 # ppm
|
690 |
NO3_RATIO = 8.25 # Доля нитратного азота
|
691 |
NH4_RATIO = 1.00 # Доля аммонийного азота
|
692 |
-
VOLUME_LITERS = 100
|
693 |
|
694 |
# Базовый профиль (7 элементов)
|
695 |
BASE_PROFILE = {
|
@@ -749,14 +748,14 @@ class NutrientCalculator:
|
|
749 |
|
750 |
return self.results
|
751 |
|
752 |
-
def _apply_fertilizer(self, name,
|
753 |
content = self.fertilizers[name][main_element]
|
754 |
-
grams = (
|
755 |
|
756 |
added = {}
|
757 |
for element, label in additions.items():
|
758 |
-
|
759 |
-
added[label] = round(
|
760 |
|
761 |
self.results[name] = {
|
762 |
'граммы': round(grams, 3),
|
@@ -765,11 +764,19 @@ class NutrientCalculator:
|
|
765 |
}
|
766 |
|
767 |
def _apply_potassium_sulfate(self):
|
|
|
|
|
|
|
|
|
768 |
k_content = self.fertilizers["Калий сернокислый"]["K"]
|
769 |
s_content = self.fertilizers["Калий сернокислый"]["S"]
|
770 |
|
771 |
-
#
|
772 |
-
grams =
|
|
|
|
|
|
|
|
|
773 |
added_k = grams * k_content * 1000 / self.volume
|
774 |
added_s = grams * s_content * 1000 / self.volume
|
775 |
|
@@ -781,11 +788,13 @@ class NutrientCalculator:
|
|
781 |
}
|
782 |
|
783 |
def _apply_potassium_nitrate(self):
|
|
|
|
|
|
|
784 |
k_content = self.fertilizers["Калий азотнокислый"]["K"]
|
785 |
n_content = self.fertilizers["Калий азотнокислый"]["N (NO3-)"]
|
786 |
|
787 |
-
|
788 |
-
grams = 1.5
|
789 |
added_k = grams * k_content * 1000 / self.volume
|
790 |
added_n = grams * n_content * 1000 / self.volume
|
791 |
|
@@ -798,14 +807,8 @@ class NutrientCalculator:
|
|
798 |
|
799 |
def _recalculate_nitrogen(self):
|
800 |
# Суммируем весь внесенный азот
|
801 |
-
total_no3 = 0
|
802 |
-
total_nh4 = 0
|
803 |
-
|
804 |
-
for fert in self.results.values():
|
805 |
-
if 'внесет NO3' in fert:
|
806 |
-
total_no3 += fert['внесет NO3']
|
807 |
-
if 'внесет NH4' in fert:
|
808 |
-
total_nh4 += fert['внесет NH4']
|
809 |
|
810 |
# Обновляем профиль
|
811 |
self.profile['N (NO3-)'] = total_no3
|
@@ -847,7 +850,7 @@ class NutrientCalculator:
|
|
847 |
print(tabulate(fert_table, headers=["Удобрение", "Граммы", "Миллиграммы", "Добавит"]))
|
848 |
|
849 |
if __name__ == "__main__":
|
850 |
-
calculator = NutrientCalculator(volume_liters=
|
851 |
calculator.calculate()
|
852 |
calculator.print_report()
|
853 |
|
|
|
682 |
|
683 |
|
684 |
|
|
|
685 |
from tabulate import tabulate
|
686 |
|
687 |
# Константы для расчёта
|
688 |
TOTAL_NITROGEN = 125 # ppm
|
689 |
NO3_RATIO = 8.25 # Доля нитратного азота
|
690 |
NH4_RATIO = 1.00 # Доля аммонийного азота
|
691 |
+
VOLUME_LITERS = 100 # Объём раствора (можно менять)
|
692 |
|
693 |
# Базовый профиль (7 элементов)
|
694 |
BASE_PROFILE = {
|
|
|
748 |
|
749 |
return self.results
|
750 |
|
751 |
+
def _apply_fertilizer(self, name, ppm_needed, main_element, additions):
|
752 |
content = self.fertilizers[name][main_element]
|
753 |
+
grams = (ppm_needed * self.volume) / (content * 1000)
|
754 |
|
755 |
added = {}
|
756 |
for element, label in additions.items():
|
757 |
+
added_ppm = grams * self.fertilizers[name][element] * 1000 / self.volume
|
758 |
+
added[label] = round(added_ppm, 1)
|
759 |
|
760 |
self.results[name] = {
|
761 |
'граммы': round(grams, 3),
|
|
|
764 |
}
|
765 |
|
766 |
def _apply_potassium_sulfate(self):
|
767 |
+
# Рассчитываем необходимое количество для покрытия дефицита
|
768 |
+
k_needed = max(0, self.profile['K'] - sum(f.get('внесет K', 0) for f in self.results.values())
|
769 |
+
s_needed = max(0, self.profile['S'] - sum(f.get('внесет S', 0) for f in self.results.values())
|
770 |
+
|
771 |
k_content = self.fertilizers["Калий сернокислый"]["K"]
|
772 |
s_content = self.fertilizers["Калий сернокислый"]["S"]
|
773 |
|
774 |
+
# Рассчитываем граммы для покрытия дефицита
|
775 |
+
grams = min(
|
776 |
+
(k_needed * self.volume) / (k_content * 1000),
|
777 |
+
(s_needed * self.volume) / (s_content * 1000)
|
778 |
+
)
|
779 |
+
|
780 |
added_k = grams * k_content * 1000 / self.volume
|
781 |
added_s = grams * s_content * 1000 / self.volume
|
782 |
|
|
|
788 |
}
|
789 |
|
790 |
def _apply_potassium_nitrate(self):
|
791 |
+
# Рассчитываем остаточную потребность в калии
|
792 |
+
k_needed = max(0, self.profile['K'] - sum(f.get('внесет K', 0) for f in self.results.values()))
|
793 |
+
|
794 |
k_content = self.fertilizers["Калий азотнокислый"]["K"]
|
795 |
n_content = self.fertilizers["Калий азотнокислый"]["N (NO3-)"]
|
796 |
|
797 |
+
grams = (k_needed * self.volume) / (k_content * 1000)
|
|
|
798 |
added_k = grams * k_content * 1000 / self.volume
|
799 |
added_n = grams * n_content * 1000 / self.volume
|
800 |
|
|
|
807 |
|
808 |
def _recalculate_nitrogen(self):
|
809 |
# Суммируем весь внесенный азот
|
810 |
+
total_no3 = sum(f.get('внесет NO3', 0) for f in self.results.values())
|
811 |
+
total_nh4 = sum(f.get('внесет NH4', 0) for f in self.results.values())
|
|
|
|
|
|
|
|
|
|
|
|
|
812 |
|
813 |
# Обновляем профиль
|
814 |
self.profile['N (NO3-)'] = total_no3
|
|
|
850 |
print(tabulate(fert_table, headers=["Удобрение", "Граммы", "Миллиграммы", "Добавит"]))
|
851 |
|
852 |
if __name__ == "__main__":
|
853 |
+
calculator = NutrientCalculator(volume_liters=VOLUME_LITERS)
|
854 |
calculator.calculate()
|
855 |
calculator.print_report()
|
856 |
|