[FIX/BE] add clamp maximum value

This commit is contained in:
ragilap
2026-01-12 00:27:53 +07:00
parent 1217f34dcd
commit d1d94357cf
@@ -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 {