-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarking.go
64 lines (53 loc) · 1.49 KB
/
benchmarking.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package cmes
import (
"errors"
_ "time"
)
type Benchmarking struct {
Standards map[string]PerformanceStandard
}
type PerformanceStandard struct {
MinimumValue int
MaximumValue int
Measurement string
}
func NewPerformanceStandard(minimumValue int, maximumValue int, measurement string) *PerformanceStandard {
return &PerformanceStandard{MinimumValue: minimumValue, MaximumValue: maximumValue, Measurement: measurement}
}
func NewBenchmarking(standards map[string]PerformanceStandard) *Benchmarking {
return &Benchmarking{Standards: standards}
}
func (b *Benchmarking) Benchmark(performer Performer) (int, error) {
if len(b.Standards) == 0 {
return 0, errors.New("no performance standards defined")
}
performanceData := performer.GetPerformance()
if len(performanceData) == 0 {
return 0, errors.New("no performance data available")
}
totalScore := 0
for _, data := range performanceData {
standard, ok := b.Standards[data.KPI]
if !ok {
return 0, errors.New("no performance standard defined for KPI: " + data.KPI)
}
score := calculateScore(data.Value, standard.MinimumValue, standard.MaximumValue)
totalScore += score
}
averageScore := totalScore / len(performanceData)
return averageScore, nil
}
func calculateScore(value, minimum, maximum int) int {
if value < minimum {
return 0
}
if value > maximum {
return 100
}
rangeValue := maximum - minimum
rangeScore := 100
if rangeValue > 0 {
rangeScore = 100 / rangeValue
}
return ((value - minimum) * rangeScore)
}