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 {