2020-04-23 13:44:23 +07:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"status/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getStatus() map[string]db.PingEntry {
|
|
|
|
entries := db.GetFromDB("", time.Now().Add(time.Duration(-2)*time.Minute), time.Now())
|
|
|
|
result := make(map[string]db.PingEntry)
|
|
|
|
for _, v := range entries {
|
|
|
|
if v.Time.Before(result[v.ServiceName].Time) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
result[v.ServiceName] = v
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-04-23 13:49:23 +07:00
|
|
|
func getHistoryDay(serviceName string, dayCount int) []stat {
|
2020-04-23 13:44:23 +07:00
|
|
|
currentDay := today()
|
|
|
|
result := make([]stat, 0)
|
2020-04-23 13:49:23 +07:00
|
|
|
for i := -dayCount + 1; i <= 0; i++ {
|
2020-04-23 13:44:23 +07:00
|
|
|
dayData := getDay(serviceName, currentDay.AddDate(0, 0, i))
|
|
|
|
if dayData.SampleCount > 0 {
|
|
|
|
result = append(result, dayData)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|