baoshiwei
2026-04-01 81b0ad0124847f083990d574dc8d20961ec6e713
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import pandas as pd
from datetime import timedelta
from app.database.database import DatabaseConnection
 
class MainProcessService:
    def __init__(self):
        self.db = DatabaseConnection()
        self.timezone_offset = 8  # 默认东八区(北京时间)
    
    def _to_utc(self, dt):
        return dt - timedelta(hours=self.timezone_offset)
    
    def _to_local(self, df):
        if not df.empty and 'time' in df.columns:
            df['time'] = pd.to_datetime(df['time']) + timedelta(hours=self.timezone_offset)
        return df
 
    def get_cutting_setting_data(self, start_date, end_date):
        """获取流程主速度数据"""
        try:
            start_utc = self._to_utc(start_date)
            end_utc = self._to_utc(end_date)
            
            if not self.db.is_connected():
                self.db.connect()
            
            query = """
            SELECT time, process_main_speed, cutting_count 
            FROM public.aics_main_process_cutting_setting 
            WHERE time BETWEEN %s AND %s 
            ORDER BY time ASC
            """
            df = pd.read_sql(query, self.db.get_connection(), params=(start_utc, end_utc))
            return self._to_local(df)
        except Exception as e:
            print(f"获取主速度数据失败: {e}")
            return pd.DataFrame()
 
    def get_motor_monitoring_data(self, start_date, end_date):
        """获取电机监控线速数据"""
        try:
            start_utc = self._to_utc(start_date)
            end_utc = self._to_utc(end_date)
            
            if not self.db.is_connected():
                self.db.connect()
            
            query = """
            SELECT time, m1_line_speed, m2_line_speed 
            FROM public.aics_main_process_motor_monitoring 
            WHERE time BETWEEN %s AND %s 
            ORDER BY time ASC
            """
            df = pd.read_sql(query, self.db.get_connection(), params=(start_utc, end_utc))
            return self._to_local(df)
        except Exception as e:
            print(f"获取电机监控数据失败: {e}")
            return pd.DataFrame()
 
    def get_temperature_control_data(self, start_date, end_date):
        """获取中田挤出机温度设定与显示数据"""
        try:
            start_utc = self._to_utc(start_date)
            end_utc = self._to_utc(end_date)
            
            if not self.db.is_connected():
                self.db.connect()
            
            query = """
            SELECT 
                time,
                nakata_extruder_screw_set_temp,
                nakata_extruder_screw_display_temp,
                nakata_extruder_rear_barrel_set_temp,
                nakata_extruder_rear_barrel_display_temp,
                nakata_extruder_front_barrel_set_temp,
                nakata_extruder_front_barrel_display_temp,
                nakata_extruder_head_set_temp,
                nakata_extruder_head_display_temp
            FROM public.aics_main_process_temperature_control_setting 
            WHERE time BETWEEN %s AND %s 
            ORDER BY time ASC
            """
            df = pd.read_sql(query, self.db.get_connection(), params=(start_utc, end_utc))
            return self._to_local(df)
        except Exception as e:
            print(f"获取温度控制数据失败: {e}")
            return pd.DataFrame()