故障时长提取
This commit is contained in:
@@ -18,6 +18,11 @@ db_config = {
|
|||||||
"host": "172.16.10.131"
|
"host": "172.16.10.131"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 基础数据
|
||||||
|
TotalAlarmTime = 0
|
||||||
|
TodayAlarmTime = 0
|
||||||
|
MonthAlarmTime = 0
|
||||||
|
|
||||||
|
|
||||||
def convert_to_seconds(time_str):
|
def convert_to_seconds(time_str):
|
||||||
# 修改正则表达式,使 H、M、S 部分可选
|
# 修改正则表达式,使 H、M、S 部分可选
|
||||||
@@ -455,7 +460,7 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
faulty_plans = request.env['quality.check'].sudo().search([
|
faulty_plans = request.env['quality.check'].sudo().search([
|
||||||
('operation_id.name', '=', 'CNC加工'),
|
('operation_id.name', '=', 'CNC加工'),
|
||||||
('quality_state', 'in', ['fail'])
|
('quality_state', 'in', ['fail'])
|
||||||
])
|
])
|
||||||
|
|
||||||
# 查找制造订单取消与归档的数量
|
# 查找制造订单取消与归档的数量
|
||||||
cancel_order_count = production_obj.search_count(
|
cancel_order_count = production_obj.search_count(
|
||||||
@@ -651,11 +656,12 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
|
|
||||||
for date in date_list:
|
for date in date_list:
|
||||||
next_day = date + timedelta(days=1)
|
next_day = date + timedelta(days=1)
|
||||||
orders = request.env['mrp.workorder'].sudo().search([('production_id.production_line_id.name', '=', line), ('state', 'in', ['done']),
|
orders = request.env['mrp.workorder'].sudo().search(
|
||||||
('routing_type', '=', 'CNC加工'),
|
[('production_id.production_line_id.name', '=', line), ('state', 'in', ['done']),
|
||||||
(date_field_name, '>=', date.strftime('%Y-%m-%d 00:00:00')),
|
('routing_type', '=', 'CNC加工'),
|
||||||
(date_field_name, '<', next_day.strftime('%Y-%m-%d 00:00:00'))
|
(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(
|
rework_orders = request.env['mrp.workorder'].sudo().search(
|
||||||
[('production_id.production_line_id.name', '=', line), ('state', 'in', ['rework']),
|
[('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'])
|
machine_list = ast.literal_eval(kw['machine_list'])
|
||||||
total_alarm_time = 0
|
total_alarm_time = 0
|
||||||
|
today_alarm_time = 0
|
||||||
|
month_alarm_time = 0
|
||||||
alarm_count_num = 0
|
alarm_count_num = 0
|
||||||
for item in machine_list:
|
for item in machine_list:
|
||||||
sql = '''
|
sql = '''
|
||||||
@@ -904,6 +912,11 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
) subquery;
|
) 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 = '''
|
sql2 = '''
|
||||||
SELECT DISTINCT ON (alarm_start_time) alarm_time, alarm_start_time
|
SELECT DISTINCT ON (alarm_start_time) alarm_time, alarm_start_time
|
||||||
FROM device_data
|
FROM device_data
|
||||||
@@ -918,8 +931,16 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
|
|
||||||
cur.execute(sql2, (item,))
|
cur.execute(sql2, (item,))
|
||||||
result2 = cur.fetchall()
|
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:
|
for row in result:
|
||||||
res['data'][item] = {'idle_count': row[0]}
|
res['data'][item] = {'idle_count': row[0]}
|
||||||
alarm_count = []
|
alarm_count = []
|
||||||
@@ -939,7 +960,28 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
alarm_count_num = 1
|
alarm_count_num = 1
|
||||||
else:
|
else:
|
||||||
alarm_count_num = len(list(set(alarm_count)))
|
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
|
res['data'][item]['total_alarm_time'] = total_alarm_time / 3600
|
||||||
|
logging.info('=======================')
|
||||||
res['data'][item]['alarm_count_num'] = alarm_count_num
|
res['data'][item]['alarm_count_num'] = alarm_count_num
|
||||||
|
|
||||||
# 返回统计结果
|
# 返回统计结果
|
||||||
|
|||||||
@@ -78,6 +78,10 @@
|
|||||||
<p>公司邮箱: <span t-field="o.company_id.email"/></p>
|
<p>公司邮箱: <span t-field="o.company_id.email"/></p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- <div style="border-top: 2px solid black;"></div> -->
|
||||||
|
<div class="text-center">
|
||||||
|
<span>第<span>1</span> 页/共 <span>1</span>页</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<template id="report_quality_inspection">
|
<template id="report_quality_inspection">
|
||||||
|
|||||||
Reference in New Issue
Block a user