From 36835c9fad6fd5946ee8c9204c17aa661663740a Mon Sep 17 00:00:00 2001 From: Kumi Date: Thu, 28 Nov 2024 15:22:11 +0100 Subject: [PATCH] fix: Fix mood calculation key derivation Updates the logic for finding the nearest mood option key by comparing the numeric key directly to the average value. This resolves incorrect mood determinations by ensuring that comparisons are based on numeric values, thus preventing potential mismatches in mood calculations. --- mood/static/mood/dashboard.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mood/static/mood/dashboard.js b/mood/static/mood/dashboard.js index 0d16aee..0973ad7 100644 --- a/mood/static/mood/dashboard.js +++ b/mood/static/mood/dashboard.js @@ -23,7 +23,7 @@ fetch("/mood/statistics/heatmap/values/") x: "date", y: d => { if (d.average) { - const key = Object.keys(moodOptions).reduce((a, b) => Math.abs(moodOptions[a] - d.average) < Math.abs(moodOptions[b] - d.average) ? a : b); + const key = Object.keys(moodOptions).reduce((a, b) => Math.abs(a - d.average) < Math.abs(b - d.average) ? a : b); return key; } return 0; @@ -73,7 +73,7 @@ fetch("/mood/statistics/heatmap/values/") return `${date_str}
Mood Count: ${obj.count}
Average Mood: N/A` } - const key = Object.keys(moodOptions).reduce((a, b) => Math.abs(moodOptions[a] - average) < Math.abs(moodOptions[b] - average) ? a : b); + const key = Object.keys(moodOptions).reduce((a, b) => Math.abs(a - average) < Math.abs(b - average) ? a : b); const mood = moodOptions[key]; return `${date_str}
Mood Count: ${obj.count}
Average Mood: ${mood.name}`