Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -848,6 +848,10 @@ if __name__ == "__main__":
|
|
848 |
print(calculator.generate_report(results))
|
849 |
|
850 |
|
|
|
|
|
|
|
|
|
851 |
@app.route('/calculation', methods=['POST'])
|
852 |
def handle_calculation():
|
853 |
try:
|
@@ -858,7 +862,8 @@ def handle_calculation():
|
|
858 |
return jsonify({'error': 'Неверный формат данных'}), 400
|
859 |
|
860 |
# Инициализация калькулятора
|
861 |
-
calculator =
|
|
|
862 |
|
863 |
# Базовый профиль (начальные значения)
|
864 |
BASE_PROFILE = {
|
@@ -886,7 +891,7 @@ def handle_calculation():
|
|
886 |
BASE_PROFILE['N (NH4+)'] = total_n * (nh4_ratio / total_parts)
|
887 |
|
888 |
# Настройка целевого профиля
|
889 |
-
calculator.
|
890 |
|
891 |
# Установка констант удобрений из запроса
|
892 |
calculator.fertilizers = data['fertilizerConstants']
|
@@ -896,20 +901,27 @@ def handle_calculation():
|
|
896 |
|
897 |
# Подготовка ответа
|
898 |
response = {
|
899 |
-
"actual_profile": calculator.
|
900 |
-
"fertilizers": results,
|
901 |
"nitrogen_ratios": {
|
902 |
"NH4_RATIO": nh4_ratio,
|
903 |
"NO3_RATIO": no3_ratio,
|
904 |
"TOTAL_NITROGEN": total_n
|
905 |
},
|
906 |
-
"
|
907 |
-
"
|
908 |
}
|
909 |
|
|
|
|
|
|
|
|
|
|
|
910 |
return jsonify(response)
|
911 |
|
912 |
except Exception as e:
|
|
|
|
|
913 |
return jsonify({'error': str(e)}), 500
|
914 |
|
915 |
|
@@ -929,7 +941,6 @@ def handle_calculation():
|
|
929 |
|
930 |
|
931 |
|
932 |
-
|
933 |
|
934 |
|
935 |
if __name__ == '__main__':
|
|
|
848 |
print(calculator.generate_report(results))
|
849 |
|
850 |
|
851 |
+
from flask import Flask, request, jsonify
|
852 |
+
|
853 |
+
app = Flask(__name__)
|
854 |
+
|
855 |
@app.route('/calculation', methods=['POST'])
|
856 |
def handle_calculation():
|
857 |
try:
|
|
|
862 |
return jsonify({'error': 'Неверный формат данных'}), 400
|
863 |
|
864 |
# Инициализация калькулятора
|
865 |
+
calculator = PrecisionNutrientCalculator()
|
866 |
+
calculator.volume = float(data['profileSettings'].get('liters', 100))
|
867 |
|
868 |
# Базовый профиль (начальные значения)
|
869 |
BASE_PROFILE = {
|
|
|
891 |
BASE_PROFILE['N (NH4+)'] = total_n * (nh4_ratio / total_parts)
|
892 |
|
893 |
# Настройка целевого профиля
|
894 |
+
calculator.target = BASE_PROFILE
|
895 |
|
896 |
# Установка констант удобрений из запроса
|
897 |
calculator.fertilizers = data['fertilizerConstants']
|
|
|
901 |
|
902 |
# Подготовка ответа
|
903 |
response = {
|
904 |
+
"actual_profile": {k: round(v, 3) for k, v in calculator.actual.items()},
|
905 |
+
"fertilizers": {k: round(v['граммы'], 3) for k, v in calculator.results.items()},
|
906 |
"nitrogen_ratios": {
|
907 |
"NH4_RATIO": nh4_ratio,
|
908 |
"NO3_RATIO": no3_ratio,
|
909 |
"TOTAL_NITROGEN": total_n
|
910 |
},
|
911 |
+
"total_ppm": round(sum(calculator.actual.values()), 3),
|
912 |
+
"deficits": results.get('deficits', {})
|
913 |
}
|
914 |
|
915 |
+
# Логирование случаев с отрицательными значениями
|
916 |
+
if any(value < 0 for value in calculator.actual.values()):
|
917 |
+
print("ВНИМАНИЕ: В расчетах обнаружены отрицательные значения!")
|
918 |
+
print(f"Фактический профиль: {calculator.actual}")
|
919 |
+
|
920 |
return jsonify(response)
|
921 |
|
922 |
except Exception as e:
|
923 |
+
# Логирование ошибки
|
924 |
+
print(f"Ошибка при обработке запроса: {str(e)}")
|
925 |
return jsonify({'error': str(e)}), 500
|
926 |
|
927 |
|
|
|
941 |
|
942 |
|
943 |
|
|
|
944 |
|
945 |
|
946 |
if __name__ == '__main__':
|