DmitrMakeev commited on
Commit
0dee4ea
·
verified ·
1 Parent(s): 787a192

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -27
app.py CHANGED
@@ -1098,36 +1098,52 @@ class WebNutrientCalculator:
1098
  @app.route('/calculation', methods=['POST'])
1099
  def handle_calculation():
1100
  try:
1101
- data = request.json
1102
-
1103
- # Создаем веб-версию калькулятора
1104
- web_calc = WebNutrientCalculator(volume_liters=data['profileSettings']['liters'])
1105
-
1106
- # Выполняем расчет
1107
- result = web_calc.web_calculate(
1108
- profile_settings=data['profileSettings'],
1109
- fertilizer_constants=data['fertilizerConstants']
1110
- )
1111
-
1112
- # Формируем ответ
1113
- response_data = {
1114
- 'fertilizers': result['fertilizers'],
1115
- 'profile': result['profile'],
1116
- 'ec': result['ec'],
1117
- 'volume': result['volume'],
1118
- 'status': 'success'
 
 
 
 
 
 
1119
  }
1120
-
1121
- return jsonify(response_data), 200
1122
-
1123
- except Exception as e:
1124
- error_response = {
1125
- 'error': str(e),
1126
- 'message': 'Calculation error',
1127
- 'status': 'error'
1128
  }
1129
- return jsonify(error_response), 500
1130
 
 
 
 
 
 
 
 
 
 
 
 
 
1131
 
1132
 
1133
 
 
1098
  @app.route('/calculation', methods=['POST'])
1099
  def handle_calculation():
1100
  try:
1101
+ # 1. Получаем данные
1102
+ data = request.get_json()
1103
+ if not data:
1104
+ raise ValueError("No JSON data received")
1105
+
1106
+ # 2. Проверяем обязательные поля
1107
+ required_fields = ['profileSettings', 'fertilizerConstants']
1108
+ for field in required_fields:
1109
+ if field not in data:
1110
+ raise ValueError(f"Missing required field: {field}")
1111
+
1112
+ # 3. Создаем калькулятор (НЕ трогая оригинальный класс)
1113
+ calculator = {
1114
+ 'volume': float(data['profileSettings'].get('liters', 1)),
1115
+ 'target_profile': {
1116
+ 'P': float(data['profileSettings'].get('P', 0)),
1117
+ 'K': float(data['profileSettings'].get('K', 0)),
1118
+ 'Mg': float(data['profileSettings'].get('Mg', 0)),
1119
+ 'Ca': float(data['profileSettings'].get('Ca', 0)),
1120
+ 'S': float(data['profileSettings'].get('S', 0)),
1121
+ 'N_NO3': float(data['profileSettings'].get('N (NO3-)', 0)),
1122
+ 'N_NH4': float(data['profileSettings'].get('N (NH4+)', 0))
1123
+ },
1124
+ 'fertilizers': data['fertilizerConstants']
1125
  }
1126
+
1127
+ # 4. Выполняем расчет (упрощенная логика)
1128
+ results = {
1129
+ 'fertilizers': [],
1130
+ 'profile': calculator['target_profile'],
1131
+ 'ec': 0.0,
1132
+ 'volume': calculator['volume']
 
1133
  }
 
1134
 
1135
+ # 5. Возвращаем результат
1136
+ return jsonify({
1137
+ 'status': 'success',
1138
+ 'data': results
1139
+ })
1140
+
1141
+ except Exception as e:
1142
+ # 6. Обработка ошибок
1143
+ return jsonify({
1144
+ 'status': 'error',
1145
+ 'message': str(e)
1146
+ }), 500
1147
 
1148
 
1149