Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -873,13 +873,22 @@ def handle_calculation():
|
|
873 |
calculator = NutrientCalculator(data)
|
874 |
results = calculator.calculate()
|
875 |
|
876 |
-
# 4. Формируем
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
877 |
response = {
|
878 |
"fertilizers": results['fertilizers'],
|
879 |
"actual_profile": results['actual_profile'],
|
880 |
"deficits": results['deficits'],
|
881 |
"total_ppm": results['total_ppm'],
|
882 |
-
"
|
883 |
"nitrogen_ratios": {
|
884 |
"NH4_RATIO": 1,
|
885 |
"NO3_RATIO": data.get("profileSettings", {}).get("NO3_RAT", 0),
|
@@ -887,7 +896,7 @@ def handle_calculation():
|
|
887 |
}
|
888 |
}
|
889 |
|
890 |
-
#
|
891 |
print("\n=== РЕЗУЛЬТАТЫ ===")
|
892 |
print(calculator.generate_report(results))
|
893 |
|
@@ -901,6 +910,7 @@ def handle_calculation():
|
|
901 |
"fertilizers": {},
|
902 |
"actual_profile": {},
|
903 |
"deficits": {},
|
|
|
904 |
"total_ppm": 0
|
905 |
}), 500
|
906 |
|
|
|
873 |
calculator = NutrientCalculator(data)
|
874 |
results = calculator.calculate()
|
875 |
|
876 |
+
# 4. Формируем дополнительные данные: вклад каждого удобрения в каждый элемент
|
877 |
+
element_contributions = {}
|
878 |
+
for fert_name, fert_data in calculator.results.items():
|
879 |
+
grams = fert_data['граммы']
|
880 |
+
element_contributions[fert_name] = {}
|
881 |
+
for element, percent in calculator.fertilizers[fert_name].items():
|
882 |
+
added_ppm = (grams * percent * 1000) / calculator.volume
|
883 |
+
element_contributions[fert_name][element] = round(added_ppm, 3)
|
884 |
+
|
885 |
+
# 5. Формируем полный ответ
|
886 |
response = {
|
887 |
"fertilizers": results['fertilizers'],
|
888 |
"actual_profile": results['actual_profile'],
|
889 |
"deficits": results['deficits'],
|
890 |
"total_ppm": results['total_ppm'],
|
891 |
+
"element_contributions": element_contributions, # Новое поле
|
892 |
"nitrogen_ratios": {
|
893 |
"NH4_RATIO": 1,
|
894 |
"NO3_RATIO": data.get("profileSettings", {}).get("NO3_RAT", 0),
|
|
|
896 |
}
|
897 |
}
|
898 |
|
899 |
+
# 6. Логируем результаты (для отладки)
|
900 |
print("\n=== РЕЗУЛЬТАТЫ ===")
|
901 |
print(calculator.generate_report(results))
|
902 |
|
|
|
910 |
"fertilizers": {},
|
911 |
"actual_profile": {},
|
912 |
"deficits": {},
|
913 |
+
"element_contributions": {}, # Пустое поле при ошибке
|
914 |
"total_ppm": 0
|
915 |
}), 500
|
916 |
|