From 8647fa8b5d523d06dad716622e0a9f77df923bf7 Mon Sep 17 00:00:00 2001 From: Rajesh Jonnalagadda <38752904+rajeshj11@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:15:29 +0530 Subject: [PATCH] fix: card stats calculations in workflow executions (#1835) Signed-off-by: Rajesh Jonnalagadda <38752904+rajeshj11@users.noreply.github.com> Co-authored-by: Tal --- keep/api/core/db.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/keep/api/core/db.py b/keep/api/core/db.py index 38f2073a0..cfab9b586 100644 --- a/keep/api/core/db.py +++ b/keep/api/core/db.py @@ -619,17 +619,18 @@ def get_workflow_executions(tenant_id, workflow_id, limit=50, offset=0, tab=2, s total_count = query.count() - status_counts = session.query( + status_counts = query.with_entities( WorkflowExecution.status, func.count().label('count') ).group_by(WorkflowExecution.status).all() statusGroupbyMap = {status: count for status, count in status_counts} - passCount = statusGroupbyMap.get('success', 0) failCount = statusGroupbyMap.get('error', 0) + statusGroupbyMap.get('timeout', 0) - passFail = (passCount / failCount) * 100 if failCount > 0 else 100.00 - + if passCount > 0: + passFail = (passCount / failCount) * 100 if failCount > 0 else 100.00 + else: + passFail = 0.0 avgDuration = query.with_entities(func.avg(WorkflowExecution.execution_time)).scalar() avgDuration = avgDuration if avgDuration else 0.0