故障时长提取

This commit is contained in:
mgw
2025-04-14 11:21:24 +08:00
parent 87786dbd80
commit 91d79008e1
2 changed files with 54 additions and 8 deletions

View File

@@ -18,6 +18,11 @@ db_config = {
"host": "172.16.10.131"
}
# 基础数据
TotalAlarmTime = 0
TodayAlarmTime = 0
MonthAlarmTime = 0
def convert_to_seconds(time_str):
# 修改正则表达式,使 H、M、S 部分可选
@@ -455,7 +460,7 @@ class Sf_Dashboard_Connect(http.Controller):
faulty_plans = request.env['quality.check'].sudo().search([
('operation_id.name', '=', 'CNC加工'),
('quality_state', 'in', ['fail'])
])
])
# 查找制造订单取消与归档的数量
cancel_order_count = production_obj.search_count(
@@ -651,11 +656,12 @@ class Sf_Dashboard_Connect(http.Controller):
for date in date_list:
next_day = date + timedelta(days=1)
orders = request.env['mrp.workorder'].sudo().search([('production_id.production_line_id.name', '=', line), ('state', 'in', ['done']),
('routing_type', '=', 'CNC加工'),
(date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
(date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
])
orders = request.env['mrp.workorder'].sudo().search(
[('production_id.production_line_id.name', '=', line), ('state', 'in', ['done']),
('routing_type', '=', 'CNC加工'),
(date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
(date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
])
rework_orders = request.env['mrp.workorder'].sudo().search(
[('production_id.production_line_id.name', '=', line), ('state', 'in', ['rework']),
@@ -892,6 +898,8 @@ class Sf_Dashboard_Connect(http.Controller):
# 获取请求的机床数据
machine_list = ast.literal_eval(kw['machine_list'])
total_alarm_time = 0
today_alarm_time = 0
month_alarm_time = 0
alarm_count_num = 0
for item in machine_list:
sql = '''
@@ -904,6 +912,11 @@ class Sf_Dashboard_Connect(http.Controller):
) subquery;
'''
# 计算时间范围
now = datetime.now()
today_start = now.replace(hour=0, minute=0, second=0, microsecond=0)
month_start = now.replace(day=1, hour=0, minute=0, second=0, microsecond=0)
sql2 = '''
SELECT DISTINCT ON (alarm_start_time) alarm_time, alarm_start_time
FROM device_data
@@ -918,8 +931,16 @@ class Sf_Dashboard_Connect(http.Controller):
cur.execute(sql2, (item,))
result2 = cur.fetchall()
# print('result2========', result2)
#
today_data = []
month_data = []
for record in result2:
alarm_start = datetime.strptime(record[1], "%Y-%m-%d %H:%M:%S")
if alarm_start >= today_start:
today_data.append(record)
if alarm_start >= month_start:
month_data.append(record)
for row in result:
res['data'][item] = {'idle_count': row[0]}
alarm_count = []
@@ -939,7 +960,28 @@ class Sf_Dashboard_Connect(http.Controller):
alarm_count_num = 1
else:
alarm_count_num = len(list(set(alarm_count)))
for today in today_data:
if today[0]:
if float(today[0]) >= 28800:
continue
today_alarm_time += float(today[0])
else:
today_alarm_time += 0.0
for month in month_data:
if month[0]:
if float(month[0]) >= 28800:
continue
month_alarm_time += float(month[0])
else:
month_alarm_time += 0.0
TotalAlarmTime = total_alarm_time / 3600
TodayAlarmTime = today_alarm_time / 3600
MonthAlarmTime = month_alarm_time / 3600
logging.info('=====AlarmTime===== %s, %s, %s' % (TotalAlarmTime, TodayAlarmTime, MonthAlarmTime))
res['data'][item]['total_alarm_time'] = total_alarm_time / 3600
logging.info('=======================')
res['data'][item]['alarm_count_num'] = alarm_count_num
# 返回统计结果

View File

@@ -78,6 +78,10 @@
<p>公司邮箱: <span t-field="o.company_id.email"/></p>
</div>
</div>
<!-- <div style="border-top: 2px solid black;"></div> -->
<div class="text-center">
<span><span>1</span> 页/共 <span>1</span></span>
</div>
</div>
</template>
<template id="report_quality_inspection">