Bug: getOverviewStats does not calculate actual completion rate
File: server/utils/analyticsUtils.js:19-28
Problem
The avgCompletionRate (returned as avgFieldsPerTemplate) does not calculate an actual completion rate. It simply counts enabled fields per template:
const completionRates = templates.map(t => {
const config = t.config || {};
const toggles = config.toggles || {};
const enabledFields = Object.values(toggles).filter(Boolean).length;
if (enabledFields === 0) return 0;
return enabledFields; // <-- returns count, not a rate
});
const avgCompletionRate = completionRates.length > 0
? Math.round((completionRates.reduce((a, b) => a + b, 0) / completionRates.length))
: 0;
This returns the average number of enabled fields per template, not a completion rate. The KPI card in the frontend labels this as "Avg Fields/Template" which matches the actual behavior, but the variable name avgCompletionRate is misleading and the original intent was likely to calculate submission completion rates.
Fix
Rename the variable to match what it actually computes, or implement actual completion rate calculation:
// Option A: Just rename (current behavior is useful as-is)
const avgFieldsPerTemplate = ...
// Option B: Calculate actual completion rate across all submissions
const totalFields = templates.reduce((sum, t) => {
const toggles = t.config?.toggles || {};
return sum + Object.values(toggles).filter(Boolean).length;
}, 0);
const totalFilled = /* query submissions for filled field counts */;
const avgCompletionRate = totalFields > 0 ? Math.round((totalFilled / totalFields) * 100) : 0;
Severity
Low — The frontend label matches the actual behavior. The issue is misleading naming only.
Phase
Introduced in Phase 1 (PR #26, merged).
Bug: getOverviewStats does not calculate actual completion rate
File:
server/utils/analyticsUtils.js:19-28Problem
The
avgCompletionRate(returned asavgFieldsPerTemplate) does not calculate an actual completion rate. It simply counts enabled fields per template:This returns the average number of enabled fields per template, not a completion rate. The KPI card in the frontend labels this as "Avg Fields/Template" which matches the actual behavior, but the variable name
avgCompletionRateis misleading and the original intent was likely to calculate submission completion rates.Fix
Rename the variable to match what it actually computes, or implement actual completion rate calculation:
Severity
Low — The frontend label matches the actual behavior. The issue is misleading naming only.
Phase
Introduced in Phase 1 (PR #26, merged).