Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -858,11 +858,15 @@ def handle_calculation():
|
|
858 |
print("\n=== ВХОДЯЩИЕ ДАННЫЕ ===")
|
859 |
print(json.dumps(data, indent=2, ensure_ascii=False))
|
860 |
|
861 |
-
# 3.
|
|
|
|
|
|
|
|
|
862 |
calculator = NutrientCalculator(data)
|
863 |
results = calculator.calculate()
|
864 |
|
865 |
-
#
|
866 |
element_contributions = {}
|
867 |
for fert_name in calculator.fertilizers.keys(): # Для всех удобрений
|
868 |
grams = calculator.results[fert_name]['граммы']
|
@@ -871,7 +875,7 @@ def handle_calculation():
|
|
871 |
added_ppm = (grams * percent * 1000) / calculator.volume
|
872 |
element_contributions[fert_name][element] = round(added_ppm, 3)
|
873 |
|
874 |
-
#
|
875 |
response = {
|
876 |
"fertilizers": {k: round(v['граммы'], 3) for k, v in calculator.results.items()},
|
877 |
"actual_profile": {k: round(v, 3) for k, v in calculator.actual.items()},
|
@@ -885,7 +889,7 @@ def handle_calculation():
|
|
885 |
}
|
886 |
}
|
887 |
|
888 |
-
#
|
889 |
print("\n=== РЕЗУЛЬТАТЫ ===")
|
890 |
print(calculator.generate_report(results))
|
891 |
|
|
|
858 |
print("\n=== ВХОДЯЩИЕ ДАННЫЕ ===")
|
859 |
print(json.dumps(data, indent=2, ensure_ascii=False))
|
860 |
|
861 |
+
# 3. Добавляем "Кальций хлористый", если его нет
|
862 |
+
if "Кальций хлорид" not in data["fertilizerConstants"]:
|
863 |
+
data["fertilizerConstants"]["Кальций хлорид"] = {"Ca": 0.272, "Cl": 0.483}
|
864 |
+
|
865 |
+
# 4. Создаем и запускаем калькулятор
|
866 |
calculator = NutrientCalculator(data)
|
867 |
results = calculator.calculate()
|
868 |
|
869 |
+
# 5. Формируем дополнительные данные: вклад каждого удобрения в каждый элемент
|
870 |
element_contributions = {}
|
871 |
for fert_name in calculator.fertilizers.keys(): # Для всех удобрений
|
872 |
grams = calculator.results[fert_name]['граммы']
|
|
|
875 |
added_ppm = (grams * percent * 1000) / calculator.volume
|
876 |
element_contributions[fert_name][element] = round(added_ppm, 3)
|
877 |
|
878 |
+
# 6. Формируем полный ответ
|
879 |
response = {
|
880 |
"fertilizers": {k: round(v['граммы'], 3) for k, v in calculator.results.items()},
|
881 |
"actual_profile": {k: round(v, 3) for k, v in calculator.actual.items()},
|
|
|
889 |
}
|
890 |
}
|
891 |
|
892 |
+
# 7. Логируем результаты (для отладки)
|
893 |
print("\n=== РЕЗУЛЬТАТЫ ===")
|
894 |
print(calculator.generate_report(results))
|
895 |
|