2021-04-17 23:36:37 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
type ServiceItemResponse struct {
|
2021-09-02 23:45:21 +08:00
|
|
|
Monitor *Monitor
|
2021-04-17 23:36:37 +08:00
|
|
|
CurrentUp uint64
|
|
|
|
CurrentDown uint64
|
|
|
|
Delay *[30]float32
|
|
|
|
Up *[30]int
|
|
|
|
Down *[30]int
|
|
|
|
}
|
2022-05-02 00:45:03 +08:00
|
|
|
|
2022-05-02 00:53:39 +08:00
|
|
|
func sum(slice *[30]int) int {
|
2022-05-02 00:45:03 +08:00
|
|
|
if slice == nil {
|
|
|
|
return 0
|
|
|
|
}
|
2022-05-02 00:53:39 +08:00
|
|
|
var sum int
|
2022-05-02 00:45:03 +08: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
|
|
|
|
}
|