python
import time
import random
from datetime import datetime
class FermentationMonitor:
def __init__(self):
self.temp_history = []
self.start_time = datetime.now
self.ideal_temp_range = (18.0, 24.0) 摄氏度(啤酒发酵典型温度范围)
self.max_temp_variation = 2.0 允许的最大温度波动
def simulate_sensor_reading(self):
模拟温度传感器读数(实际应用时替换为真实传感器接口)
return round(random.uniform(17.5, 25.5), 1)
def check_temperature(self, current_temp):
检查温度是否在理想范围内并返回状态
status = {
current_temp": current_temp,
timestamp": datetime.now.strftime("%Y-%m-%d %H:%M:%S"),
status_code": 0,
message": "Normal
if current_temp < self.ideal_temp_range[0]:
status.update({
status_code": -1,
message": f"温度过低!当前温度:{current_temp}°C
})
elif current_temp > self.ideal_temp_range[1]:
status.update({
status_code": 1,
message": f"温度过高!当前温度:{current_temp}°C
})
return status
def ***yze_fermentation_stage(self):
根据温度变化分析发酵阶段(简单示例)
if len(self.temp_history) < 10:
return "初始发酵阶段
temp_changes = [x[1] for x in self.temp_history[-10:]]
avg_temp = sum(temp_changes) / len(temp_changes)
if avg_temp > 22.0:
return "主发酵阶段(活跃期)
elif 20.0 <= avg_temp <= 22.0:
return "主发酵阶段(稳定期)
else:
return "后发酵阶段
def log_data(self, status):
记录传感器数据
entry = (datetime.now, status["current_temp"])
self.temp_history.append(entry)
print(f"[{entry[0]}] 记录温度:{entry[1]}°C
def generate_report(self):
生成简易发酵报告
duration = datetime.now
avg_temp = sum(t[1] for t in self.temp_history) / len(self.temp_history)
return f
发酵报告:
if __name__ == "__main__":
monitor = FermentationMonitor
try:
模拟72小时监控(实际应调整为持续监控)
for _ in range(72):
current_temp = monitor.simulate_sensor_reading
status = monitor.check_temperature(current_temp)
monitor.log_data(status)
if status["status_code"] != 0:
此处可添加控制逻辑(如触发冷却/加热系统)
print(f"警告:{status['message']}")
time.sleep(3600) 每小时检查一次
print(monitor.generate_report)
except KeyboardInterrupt:
print("
发酵监控终止")
print(monitor.generate_report)
这个代码示例包含以下核心功能:
1. 温度监控系统
2. 发酵阶段分析
3. 数据报告生成
4. 扩展性设计
实际应用中需要根据以下要素进行改进:
这个代码框架可以作为酿酒过程自动监控系统的基础原型,具体实现需要根据实际酿酒工艺参数进行调整优化。