Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -856,7 +856,7 @@ class NutrientCalculator:
|
|
| 856 |
report += f"\n- {el}: не хватает {abs(diff)} ppm"
|
| 857 |
|
| 858 |
return report
|
| 859 |
-
|
| 860 |
calculator = NutrientCalculator(INPUT_DATA)
|
| 861 |
results = calculator.calculate()
|
| 862 |
print(calculator.generate_report(results))
|
|
@@ -869,34 +869,30 @@ def handle_calculation():
|
|
| 869 |
if not data:
|
| 870 |
return jsonify({"error": "No JSON data received"}), 400
|
| 871 |
|
| 872 |
-
# 2.
|
| 873 |
-
|
| 874 |
-
|
| 875 |
-
|
| 876 |
-
# 3. Добавляем "Кальций хлористый", если его нет
|
| 877 |
-
if "Кальций хлорид" not in data["fertilizerConstants"]:
|
| 878 |
-
data["fertilizerConstants"]["Кальций хлорид"] = {"Ca": 0.272, "Cl": 0.483}
|
| 879 |
|
| 880 |
-
#
|
| 881 |
calculator = NutrientCalculator(data)
|
| 882 |
results = calculator.calculate()
|
| 883 |
|
| 884 |
-
#
|
| 885 |
element_contributions = {}
|
| 886 |
-
for fert_name in calculator.fertilizers.keys():
|
| 887 |
grams = calculator.results[fert_name]['граммы']
|
| 888 |
element_contributions[fert_name] = {}
|
| 889 |
for element, percent in calculator.fertilizers[fert_name].items():
|
| 890 |
added_ppm = (grams * percent * 1000) / calculator.volume
|
| 891 |
element_contributions[fert_name][element] = round(added_ppm, 3)
|
| 892 |
|
| 893 |
-
#
|
| 894 |
response = {
|
| 895 |
-
"fertilizers":
|
| 896 |
-
"actual_profile":
|
| 897 |
"deficits": results['deficits'],
|
| 898 |
"total_ppm": results['total_ppm'],
|
| 899 |
-
"element_contributions": element_contributions,
|
| 900 |
"nitrogen_ratios": {
|
| 901 |
"NH4_RATIO": 1,
|
| 902 |
"NO3_RATIO": data.get("profileSettings", {}).get("NO3_RAT", 0),
|
|
@@ -904,10 +900,6 @@ def handle_calculation():
|
|
| 904 |
}
|
| 905 |
}
|
| 906 |
|
| 907 |
-
# 7. Логируем результаты (для отладки)
|
| 908 |
-
print("\n=== РЕЗУЛЬТАТЫ ===")
|
| 909 |
-
print(calculator.generate_report(results))
|
| 910 |
-
|
| 911 |
return jsonify(response), 200
|
| 912 |
|
| 913 |
except Exception as e:
|
|
@@ -918,7 +910,7 @@ def handle_calculation():
|
|
| 918 |
"fertilizers": {},
|
| 919 |
"actual_profile": {},
|
| 920 |
"deficits": {},
|
| 921 |
-
"element_contributions": {},
|
| 922 |
"total_ppm": 0
|
| 923 |
}), 500
|
| 924 |
|
|
@@ -930,7 +922,6 @@ def handle_calculation():
|
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
-
|
| 934 |
|
| 935 |
|
| 936 |
if __name__ == '__main__':
|
|
|
|
| 856 |
report += f"\n- {el}: не хватает {abs(diff)} ppm"
|
| 857 |
|
| 858 |
return report
|
| 859 |
+
|
| 860 |
calculator = NutrientCalculator(INPUT_DATA)
|
| 861 |
results = calculator.calculate()
|
| 862 |
print(calculator.generate_report(results))
|
|
|
|
| 869 |
if not data:
|
| 870 |
return jsonify({"error": "No JSON data received"}), 400
|
| 871 |
|
| 872 |
+
# 2. Добавляем "Кальций хлористый", если его нет
|
| 873 |
+
if "Кальций хлористый" not in data["fertilizerConstants"]:
|
| 874 |
+
data["fertilizerConstants"]["Кальций хлористый"] = {"Ca": 0.18294, "Cl": 0.32366}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 875 |
|
| 876 |
+
# 3. Создаем и запускаем калькулятор
|
| 877 |
calculator = NutrientCalculator(data)
|
| 878 |
results = calculator.calculate()
|
| 879 |
|
| 880 |
+
# 4. Формируем дополнительные данные
|
| 881 |
element_contributions = {}
|
| 882 |
+
for fert_name in calculator.fertilizers.keys():
|
| 883 |
grams = calculator.results[fert_name]['граммы']
|
| 884 |
element_contributions[fert_name] = {}
|
| 885 |
for element, percent in calculator.fertilizers[fert_name].items():
|
| 886 |
added_ppm = (grams * percent * 1000) / calculator.volume
|
| 887 |
element_contributions[fert_name][element] = round(added_ppm, 3)
|
| 888 |
|
| 889 |
+
# 5. Формируем полный ответ
|
| 890 |
response = {
|
| 891 |
+
"fertilizers": results['fertilizers'],
|
| 892 |
+
"actual_profile": results['actual_profile'],
|
| 893 |
"deficits": results['deficits'],
|
| 894 |
"total_ppm": results['total_ppm'],
|
| 895 |
+
"element_contributions": element_contributions,
|
| 896 |
"nitrogen_ratios": {
|
| 897 |
"NH4_RATIO": 1,
|
| 898 |
"NO3_RATIO": data.get("profileSettings", {}).get("NO3_RAT", 0),
|
|
|
|
| 900 |
}
|
| 901 |
}
|
| 902 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 903 |
return jsonify(response), 200
|
| 904 |
|
| 905 |
except Exception as e:
|
|
|
|
| 910 |
"fertilizers": {},
|
| 911 |
"actual_profile": {},
|
| 912 |
"deficits": {},
|
| 913 |
+
"element_contributions": {},
|
| 914 |
"total_ppm": 0
|
| 915 |
}), 500
|
| 916 |
|
|
|
|
| 922 |
|
| 923 |
|
| 924 |
|
|
|
|
| 925 |
|
| 926 |
|
| 927 |
if __name__ == '__main__':
|