1234567891011121314151617181920212223242526272829303132333435 |
- from flask import Flask, request, jsonify
- import math
- app = Flask(__name__)
- # initial_temperature:初始温度。
- # k:热传递系数。
- # times:煤矿在每个地点停留的时间列表。
- # locations:煤矿经过的每个地点的环境温度列表。
- def calculate_temperature(initial_temperature, k, times, locations):
- current_temperature = initial_temperature
- for i in range(len(locations)):
- t = times[i]
- T_env = locations[i]
- current_temperature = current_temperature + (T_env - current_temperature) * (1 - math.exp(-k * t))
- return current_temperature
- @app.route('/calculate', methods=['POST'])
- def calculate():
- # 获取 JSON 数据
- data = request.get_json()
- initial_temperature = data.get("initial_temperature")
- k = data.get("k")
- times = data.get("times")
- locations = data.get("locations")
- # 计算结果
- result = calculate_temperature(initial_temperature, k, times, locations)
- return jsonify({"final_temperature": result})
- if __name__ == "__main__":
- # 启动 Flask 服务
- app.run(port=9997, debug=True)
|