2021-04-17 11:36:37 -04:00
|
|
|
package model
|
|
|
|
|
|
|
|
type ServiceItemResponse struct {
|
2021-09-02 11:45:21 -04:00
|
|
|
Monitor *Monitor
|
2021-04-17 11:36:37 -04:00
|
|
|
CurrentUp uint64
|
|
|
|
CurrentDown uint64
|
|
|
|
Delay *[30]float32
|
|
|
|
Up *[30]int
|
|
|
|
Down *[30]int
|
|
|
|
}
|
2022-05-01 12:45:03 -04:00
|
|
|
|
2022-05-01 12:53:39 -04:00
|
|
|
func sum(slice *[30]int) int {
|
2022-05-01 12:45:03 -04:00
|
|
|
if slice == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2022-05-01 12:53:39 -04:00
|
|
|
var sum int
|
2022-05-01 12:45:03 -04:00
|
|
|
for _, v := range *slice {
|
|
|
|
sum += v
|
|
|
|
}
|
|
|
|
return sum
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r ServiceItemResponse) TotalUp() int {
|
|
|
|
return sum(r.Up)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r ServiceItemResponse) TotalDown() int {
|
|
|
|
return sum(r.Down)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r ServiceItemResponse) TotalUptime() float32 {
|
|
|
|
return float32(r.TotalUp()) / (float32(r.TotalUp() + r.TotalDown())) * 100
|
|
|
|
}
|