From 7356e0afb78733bd163758acec977eb878a215e2 Mon Sep 17 00:00:00 2001 From: mgw <1392924357@qq.com> Date: Tue, 27 Aug 2024 10:19:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 96708dd8..32d43cb5 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -308,7 +308,7 @@ class Sf_Dashboard_Connect(http.Controller): plan_data_total_counts = plan_obj.search_count([('production_line_id.name', '=', line)]) # 工单完成量 plan_data_finish_counts = plan_obj.search_count( - [('production_line_id.name', '=', line), ('state', 'not in', ['draft'])]) + [('production_line_id.name', '=', line), ('state', 'in', ['finished'])]) # 工单计划量 plan_data_plan_counts = plan_obj.search_count( [('production_line_id.name', '=', line), ('state', 'not in', ['finished'])]) @@ -770,10 +770,11 @@ class Sf_Dashboard_Connect(http.Controller): @http.route('/api/OEEByTime', type='http', auth='public', methods=['GET', 'POST'], csrf=False, cors="*") def OEEByTime(self, **kw): """ - 获取某段时间的oee,根据用户指定的时间单位(day或hour)返回对应的平均值 + 获取某段时间的OEE,根据用户指定的时间单位(day或hour)返回对应的平均值。 + 如果不传time_unit,则默认按天返回,并补全没有数据的时间段,填充0值。 """ res = {'status': 1, 'message': '成功', 'data': {}} - logging.info('前端请求获取某段时间的oee的参数为:%s' % kw) + logging.info('前端请求获取某段时间的OEE的参数为:%s' % kw) # 获取并解析参数 workcenter_list = ast.literal_eval(kw['workcenter_list']) @@ -790,8 +791,10 @@ class Sf_Dashboard_Connect(http.Controller): # 根据时间单位选择不同的时间格式 if time_unit == 'hour': time_format = 'YYYY-MM-DD HH24:00:00' + time_delta = timedelta(hours=1) else: # 默认为'day' time_format = 'YYYY-MM-DD' + time_delta = timedelta(days=1) # 查询并计算OEE平均值 oee_data = {} @@ -806,7 +809,20 @@ class Sf_Dashboard_Connect(http.Controller): """, (workcenter, begin_time, end_time)) results = cur.fetchall() - oee_data[workcenter] = {row[0]: row[1] for row in results} + # 初始化当前产线的OEE数据字典 + workcenter_oee = {row[0]: row[1] for row in results} + + # 补全缺失的时间段 + current_time = begin_time + if time_unit != 'hour': + while current_time <= end_time: + time_key = current_time.strftime('%Y-%m-%d') + if time_key not in workcenter_oee: + workcenter_oee[time_key] = 0 + current_time += time_delta + + # 按时间排序 + oee_data[workcenter] = dict(sorted(workcenter_oee.items())) # 关闭数据库连接 cur.close()