Administrator 5 mēneši atpakaļ
vecāks
revīzija
16e39ec50a

+ 35 - 0
煤矿途径地点初始温度代码接收java数据算法.py

@@ -0,0 +1,35 @@
+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)

+ 80 - 0
解冻库python代码接收java算法数据.py

@@ -0,0 +1,80 @@
+from flask import Flask, request, jsonify
+import math
+import numpy as np
+
+app = Flask(__name__)
+
+# 定义计算解冻时间的函数
+def calculate_thaw_time(mass, specific_heat, thermal_conductivity, length, width, height, T_thaw, T_env, T_initial, alpha=1.2):
+    """
+    mass: 煤矿质量 (kg)
+    specific_heat: 比热容 (kJ/(kg·°C))
+    thermal_conductivity: 热传导系数 (W/m·°C)
+    length: 煤矿堆积的长度 (m)
+    width: 煤矿堆积的宽度 (m)
+    height: 煤矿堆积的高度 (m)
+    T_thaw: 需要解冻的温度 (°C)
+    T_env: 解冻库库温 (°C)
+    T_initial: 煤矿初始温度 (°C)
+    alpha: 修正系数 (默认 1.2)
+    """
+    # 1. 计算煤矿堆的外部表面积 (A)
+    external_area = 2 * (length * width + length * height + width * height)
+
+    # 2. 修正表面积 (A_effective)
+    effective_area = alpha * external_area
+
+    # 3. 避免计算中 log 的负值和分母为零的情况
+    print(f"T_initial: {T_initial}")
+    if T_initial == T_env or (T_thaw - T_env) / (T_initial - T_env) <= 0:
+        return None
+
+    # 4. 计算解冻时间
+    thaw_time = - (mass * specific_heat) / (thermal_conductivity * effective_area) * \
+                math.log((T_thaw - T_env) / (T_initial - T_env))
+
+    return thaw_time
+
+# 定义 REST API 路由
+@app.route('/calculate-thaw-time', methods=['POST'])
+def calculate():
+    try:
+        # 获取 JSON 参数
+        data = request.json
+        # 打印接收到的 JSON 数据
+        print("Received data:", data)
+        print("Request Headers:", request.headers)
+
+        # 必填字段校验
+        required_fields = ['mass', 'specific_heat', 'thermal_conductivity', 'length', 'width', 'height', 'T_thaw', 'T_env', 'T_initial']
+        for field in required_fields:
+            if field not in data:
+                return jsonify({"error": f"Missing field: {field}"}), 400
+
+        # 提取参数
+        mass = data['mass']
+        specific_heat = data['specific_heat']
+        thermal_conductivity = data['thermal_conductivity']
+        length = data['length']
+        width = data['width']
+        height = data['height']
+        T_thaw = data['T_thaw']
+        T_env = data['T_env']
+        T_initial = data['T_initial']
+        alpha = data.get('alpha', 1.2)  # 默认修正系数
+
+        # 计算解冻时间
+        thaw_time = calculate_thaw_time(mass, specific_heat, thermal_conductivity, length, width, height, T_thaw, T_env, T_initial, alpha)
+
+        # 返回结果
+        if thaw_time is None:
+            return jsonify({"error": "Invalid input values for calculation"}), 400
+
+        # 返回的解冻时间是小时
+        return jsonify({"thaw_time": thaw_time})
+
+    except Exception as e:
+        return jsonify({"error": str(e)}), 500
+
+if __name__ == '__main__':
+    app.run(port=9996, debug=True)