mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
Merge branch 'feat/BE/US-281-uniformity' into 'development'
feat(BE-281): add types uniformity See merge request mbugroup/lti-api!141
This commit is contained in:
@@ -346,17 +346,31 @@ func buildChartWeekSummary(weights []float64) utypes.UniformityChartWeek {
|
||||
minBucket := bucket
|
||||
maxBucket := bucket + bucketSize - 1
|
||||
count := 0.0
|
||||
bucketWeights := make([]float64, 0)
|
||||
idealWeights := make([]float64, 0)
|
||||
outsideWeights := make([]float64, 0)
|
||||
for _, w := range weights {
|
||||
if w >= minBucket && w < minBucket+bucketSize {
|
||||
count++
|
||||
bucketWeights = append(bucketWeights, w)
|
||||
if w >= idealMin && w <= idealMax {
|
||||
idealWeights = append(idealWeights, w)
|
||||
} else {
|
||||
outsideWeights = append(outsideWeights, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
idealRangeLabel := rangeFromValues(idealWeights)
|
||||
outsideRangeLabel := rangeFromValues(outsideWeights)
|
||||
isIdealRange := idealRangeLabel != ""
|
||||
distribution = append(distribution, utypes.UniformityChartRange{
|
||||
Range: fmt.Sprintf("%d-%d", int(minBucket), int(maxBucket)),
|
||||
MinWeight: minBucket,
|
||||
MaxWeight: maxBucket,
|
||||
BirdCount: count,
|
||||
IsIdealRange: minBucket >= idealMin && maxBucket <= idealMax,
|
||||
IsIdealRange: isIdealRange,
|
||||
IdealRange: idealRangeLabel,
|
||||
OutsideRange: outsideRangeLabel,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -391,3 +405,29 @@ func roundToPrecision(value float64, precision int) float64 {
|
||||
}
|
||||
return math.Floor(scaled) / scale
|
||||
}
|
||||
|
||||
func rangeFromValues(values []float64) string {
|
||||
if len(values) == 0 {
|
||||
return ""
|
||||
}
|
||||
minValue := values[0]
|
||||
maxValue := values[0]
|
||||
for _, v := range values[1:] {
|
||||
if v < minValue {
|
||||
minValue = v
|
||||
}
|
||||
if v > maxValue {
|
||||
maxValue = v
|
||||
}
|
||||
}
|
||||
return formatRange(minValue, maxValue)
|
||||
}
|
||||
|
||||
func formatRange(minValue, maxValue float64) string {
|
||||
minInt := int(math.Round(minValue))
|
||||
maxInt := int(math.Round(maxValue))
|
||||
if minInt == maxInt {
|
||||
return fmt.Sprintf("%d", minInt)
|
||||
}
|
||||
return fmt.Sprintf("%d-%d", minInt, maxInt)
|
||||
}
|
||||
@@ -29,6 +29,8 @@ type UniformityChartRange struct {
|
||||
MaxWeight float64 `json:"max_weight"`
|
||||
BirdCount float64 `json:"bird_count"`
|
||||
IsIdealRange bool `json:"is_ideal_range"`
|
||||
IdealRange string `json:"ideal_range,omitempty"`
|
||||
OutsideRange string `json:"outside_range,omitempty"`
|
||||
}
|
||||
|
||||
type UniformityChartIdealRange struct {
|
||||
@@ -82,4 +84,4 @@ type UniformityChartGauge struct {
|
||||
type UniformityChartData struct {
|
||||
BarChart UniformityChartBar `json:"bar_chart"`
|
||||
GaugeChart UniformityChartGauge `json:"gauge_chart"`
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user