Skip to content

Commit 8fbb795

Browse files
committed
updated query
1 parent 3654fa6 commit 8fbb795

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

apps/sim/app/api/logs/stats/route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,16 @@ export async function GET(request: NextRequest) {
169169

170170
const existing = wf.segments.get(segmentIndex)
171171
if (existing) {
172-
existing.totalExecutions += Number(row.totalExecutions)
172+
const oldTotal = existing.totalExecutions
173+
const newTotal = oldTotal + Number(row.totalExecutions)
174+
existing.totalExecutions = newTotal
173175
existing.successfulExecutions += Number(row.successfulExecutions)
174-
existing.avgDurationMs = (existing.avgDurationMs + Number(row.avgDurationMs || 0)) / 2
176+
existing.avgDurationMs =
177+
newTotal > 0
178+
? (existing.avgDurationMs * oldTotal +
179+
Number(row.avgDurationMs || 0) * Number(row.totalExecutions)) /
180+
newTotal
181+
: 0
175182
} else {
176183
wf.segments.set(segmentIndex, {
177184
timestamp: new Date(startTime.getTime() + segmentIndex * segmentMs).toISOString(),

0 commit comments

Comments
 (0)