mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +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
|
minBucket := bucket
|
||||||
maxBucket := bucket + bucketSize - 1
|
maxBucket := bucket + bucketSize - 1
|
||||||
count := 0.0
|
count := 0.0
|
||||||
|
bucketWeights := make([]float64, 0)
|
||||||
|
idealWeights := make([]float64, 0)
|
||||||
|
outsideWeights := make([]float64, 0)
|
||||||
for _, w := range weights {
|
for _, w := range weights {
|
||||||
if w >= minBucket && w < minBucket+bucketSize {
|
if w >= minBucket && w < minBucket+bucketSize {
|
||||||
count++
|
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{
|
distribution = append(distribution, utypes.UniformityChartRange{
|
||||||
Range: fmt.Sprintf("%d-%d", int(minBucket), int(maxBucket)),
|
Range: fmt.Sprintf("%d-%d", int(minBucket), int(maxBucket)),
|
||||||
MinWeight: minBucket,
|
MinWeight: minBucket,
|
||||||
MaxWeight: maxBucket,
|
MaxWeight: maxBucket,
|
||||||
BirdCount: count,
|
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
|
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"`
|
MaxWeight float64 `json:"max_weight"`
|
||||||
BirdCount float64 `json:"bird_count"`
|
BirdCount float64 `json:"bird_count"`
|
||||||
IsIdealRange bool `json:"is_ideal_range"`
|
IsIdealRange bool `json:"is_ideal_range"`
|
||||||
|
IdealRange string `json:"ideal_range,omitempty"`
|
||||||
|
OutsideRange string `json:"outside_range,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UniformityChartIdealRange struct {
|
type UniformityChartIdealRange struct {
|
||||||
@@ -82,4 +84,4 @@ type UniformityChartGauge struct {
|
|||||||
type UniformityChartData struct {
|
type UniformityChartData struct {
|
||||||
BarChart UniformityChartBar `json:"bar_chart"`
|
BarChart UniformityChartBar `json:"bar_chart"`
|
||||||
GaugeChart UniformityChartGauge `json:"gauge_chart"`
|
GaugeChart UniformityChartGauge `json:"gauge_chart"`
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user