DmitrMakeev commited on
Commit
ba69c34
·
verified ·
1 Parent(s): d94d3cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -11
app.py CHANGED
@@ -982,31 +982,89 @@ if __name__ == "__main__":
982
  @app.route('/calculation', methods=['POST'])
983
  def handle_calculation():
984
  try:
 
985
  data = request.json
986
 
987
- # Создаем калькулятор с базовыми настройками
988
  calculator = NutrientCalculator(volume_liters=data['profileSettings']['liters'])
989
 
990
- # Вручную устанавливаем профиль и удобрения
991
  calculator.target_profile = {
992
- 'P': data['profileSettings']['P'],
993
- 'K': data['profileSettings']['K'],
994
- 'Mg': data['profileSettings']['Mg'],
995
- 'Ca': data['profileSettings']['Ca'],
996
- 'S': data['profileSettings']['S'],
997
- NO3_RATIO: data['profileSettings']['N (NO3-)'],
998
- NH4_RATIO: data['profileSettings']['N (NH4+)']
999
  }
1000
 
1001
- calculator.fertilizers = data['fertilizerConstants']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
 
1003
  # Выполняем расчет
1004
  calculator.calculate()
1005
- return jsonify(calculator.get_web_results())
 
 
 
 
 
 
 
1006
 
1007
  except Exception as e:
1008
  return jsonify({"error": str(e)}), 500
1009
 
1010
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1011
  if __name__ == '__main__':
1012
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))
 
982
  @app.route('/calculation', methods=['POST'])
983
  def handle_calculation():
984
  try:
985
+ # Получаем данные как есть
986
  data = request.json
987
 
988
+ # Создаем калькулятор
989
  calculator = NutrientCalculator(volume_liters=data['profileSettings']['liters'])
990
 
991
+ # Устанавливаем целевой профиль из полученных данных
992
  calculator.target_profile = {
993
+ 'P': float(data['profileSettings']['P']),
994
+ 'K': float(data['profileSettings']['K']),
995
+ 'Mg': float(data['profileSettings']['Mg']),
996
+ 'Ca': float(data['profileSettings']['Ca']),
997
+ 'S': float(data['profileSettings']['S']),
998
+ 'N (NO3-)': float(data['profileSettings']['NO3']),
999
+ 'N (NH4+)': float(data['profileSettings']['NH4'])
1000
  }
1001
 
1002
+ # Конвертируем удобрения в нужный формат
1003
+ calculator.fertilizers = {
1004
+ "Кальциевая селитра": {
1005
+ "N (NO3-)": data['fertilizerConstants']['CaN2O6']['NO3'] / 100,
1006
+ "Ca": data['fertilizerConstants']['CaN2O6']['Ca'] / 100
1007
+ },
1008
+ "Калий азотнокислый": {
1009
+ "N (NO3-)": data['fertilizerConstants']['KNO3']['NO3'] / 100,
1010
+ "K": data['fertilizerConstants']['KNO3']['K'] / 100
1011
+ },
1012
+ "Аммоний азотнокислый": {
1013
+ "N (NO3-)": data['fertilizerConstants']['NH4NO3']['NO3'] / 100,
1014
+ "N (NH4+)": data['fertilizerConstants']['NH4NO3']['NH4'] / 100
1015
+ },
1016
+ "Сульфат магния": {
1017
+ "Mg": data['fertilizerConstants']['MgSO4']['Mg'] / 100,
1018
+ "S": data['fertilizerConstants']['MgSO4']['S'] / 100
1019
+ },
1020
+ "Монофосфат калия": {
1021
+ "P": data['fertilizerConstants']['KH2PO4']['P'] / 100,
1022
+ "K": data['fertilizerConstants']['KH2PO4']['K'] / 100
1023
+ },
1024
+ "Калий сернокислый": {
1025
+ "K": data['fertilizerConstants']['K2SO4']['K'] / 100,
1026
+ "S": data['fertilizerConstants']['K2SO4']['S'] / 100
1027
+ }
1028
+ }
1029
 
1030
  # Выполняем расчет
1031
  calculator.calculate()
1032
+
1033
+ # Возвращаем результаты
1034
+ return jsonify({
1035
+ "fertilizers": calculator._format_fertilizers(),
1036
+ "profile": calculator._format_profile(),
1037
+ "ec": calculator.calculate_ec(),
1038
+ "deficits": calculator.calculate_deficits()
1039
+ })
1040
 
1041
  except Exception as e:
1042
  return jsonify({"error": str(e)}), 500
1043
 
1044
 
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
  if __name__ == '__main__':
1070
  app.run(host='0.0.0.0', port=int(os.environ.get('PORT', 7860)))