煤矿途径地点初始温度代码接收java数据算法.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from flask import Flask, request, jsonify
  2. import math
  3. app = Flask(__name__)
  4. # 功能::: 计算煤矿物料在多个地点经过不同时间后的最终温度
  5. # initial_temperature:初始温度,物料开始时的温度(单位:摄氏度或华氏度)。
  6. # k:热传递系数,表示热量交换的速度。该值越大,物料温度变化越快。
  7. # times:一个列表,表示物料在每个地点停留的时间(单位:时间)。
  8. # locations:一个列表,表示每个地点的环境温度(单位:摄氏度或华氏度)
  9. def calculate_temperature(initial_temperature, k, times, locations):
  10. current_temperature = initial_temperature
  11. for i in range(len(locations)):
  12. t = times[i]
  13. T_env = locations[i]
  14. current_temperature = current_temperature + (T_env - current_temperature) * (1 - math.exp(-k * t))
  15. return current_temperature
  16. @app.route('/calculate', methods=['POST'])
  17. def calculate():
  18. # 获取 JSON 数据
  19. data = request.get_json()
  20. initial_temperature = data.get("initial_temperature")
  21. k = data.get("k")
  22. times = data.get("times")
  23. locations = data.get("locations")
  24. # 计算结果
  25. result = calculate_temperature(initial_temperature, k, times, locations)
  26. return jsonify({"final_temperature": result})
  27. if __name__ == "__main__":
  28. # 启动 Flask 服务
  29. app.run(port=9997, debug=True)