diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 98c8c37e..d8ed85c9 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -853,10 +853,10 @@ class Sf_Dashboard_Connect(http.Controller): ''' sql2 = ''' - SELECT DISTINCT ON (alarm_time) alarm_time, alarm_repair_time + SELECT DISTINCT ON (alarm_start_time) alarm_time, alarm_start_time FROM device_data - WHERE device_name = %s AND alarm_time IS NOT NULL - ORDER BY alarm_time, time; + WHERE device_name = %s AND alarm_start_time IS NOT NULL + ORDER BY alarm_start_time, time; ''' # 执行SQL命令 @@ -872,7 +872,7 @@ class Sf_Dashboard_Connect(http.Controller): res['data'][item] = {'idle_count': row[0]} alarm_count = [] for row in result2: - alarm_count.append(row[0]) + alarm_count.append(row[1]) total_alarm_time += abs(float(row[0])) if len(list(set(alarm_count))) == 1: if list(set(alarm_count))[0] is None: @@ -1238,6 +1238,8 @@ class Sf_Dashboard_Connect(http.Controller): machine_list = ast.literal_eval(kw['machine_list']) time_threshold = datetime.now() - timedelta(days=1) + alarm_last_24_time = 0.0 + def fetch_result_as_dict(cursor): """辅助函数:将查询结果转为字典""" columns = [desc[0] for desc in cursor.description] @@ -1262,13 +1264,25 @@ class Sf_Dashboard_Connect(http.Controller): LIMIT 1; """, (item, time_threshold)) last_24_time = fetch_result_as_dict(cur) + + with conn.cursor() as cur: + cur.execute(""" + SELECT DISTINCT ON (alarm_start_time) alarm_time, alarm_start_time + FROM device_data + WHERE device_name = %s + AND alarm_start_time IS NOT NULL AND time >= %s; + """, (item, time_threshold)) + results = cur.fetchall() + for result in results: + alarm_last_24_time += float(result[0]) # 返回数据 res['data'][item] = { 'wait_time': last_all_time['run_time'] if last_all_time['run_time'] is not None else 0, 'cut_time': last_all_time['process_time'] if last_all_time['process_time'] is not None else 0, 'cut_24_time': last_24_time['process_time'] if last_24_time['process_time'] is not None else 0, 'power_on_time': last_all_time['power_on_time'] if last_all_time['power_on_time'] is not None else 0, - 'power_on_24_time': last_24_time['power_on_time'] if last_24_time['power_on_time'] is not None else 0 + 'power_on_24_time': last_24_time['power_on_time'] if last_24_time['power_on_time'] is not None else 0, + 'alarm_last_24_time': alarm_last_24_time } conn.close()