From d1d94357cf255ea3a1319392ad78de939914074e Mon Sep 17 00:00:00 2001 From: ragilap Date: Mon, 12 Jan 2026 00:27:53 +0700 Subject: [PATCH] [FIX/BE] add clamp maximum value --- .../dashboards/services/dashboard.service.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/modules/dashboards/services/dashboard.service.go b/internal/modules/dashboards/services/dashboard.service.go index f8d532f0..a60f1555 100644 --- a/internal/modules/dashboards/services/dashboard.service.go +++ b/internal/modules/dashboards/services/dashboard.service.go @@ -625,7 +625,7 @@ func higherIsBetterPercent(actual map[int]map[uint]float64, week int, seriesId u if !ok || val <= 0 { return 0, false } - return (val / standard) * 100, true + return clampPercent((val / standard) * 100), true } func lowerIsBetterPercent(actual map[int]map[uint]float64, week int, seriesId uint, standard float64) (float64, bool) { @@ -636,7 +636,7 @@ func lowerIsBetterPercent(actual map[int]map[uint]float64, week int, seriesId ui if !ok || val <= 0 { return 0, false } - return (standard / val) * 100, true + return clampPercent((standard / val) * 100), true } func metricValue(actual map[int]map[uint]float64, week int, seriesId uint) (float64, bool) { @@ -648,6 +648,16 @@ func metricValue(actual map[int]map[uint]float64, week int, seriesId uint) (floa return val, ok } +func clampPercent(value float64) float64 { + if value < 0 { + return 0 + } + if value > 200 { + return 200 + } + return value +} + func buildComparisonAggregateChart(seriesRows []repository.ComparisonSeries, weeks []int, actual map[int]map[uint]float64) dto.DashboardChartDTO { series := make([]dto.DashboardChartSeriesDTO, 0, len(seriesRows)) for _, sRow := range seriesRows {