server: Implement /api/history/week
parent
6d5d07e2e5
commit
84501beb23
@ -0,0 +1,31 @@
|
||||
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
|
||||
}
|
||||
|
||||
func getWeek(serviceName string) []stat {
|
||||
currentDay := today()
|
||||
result := make([]stat, 0)
|
||||
for i := -6; i <= 0; i++ {
|
||||
dayData := getDay(serviceName, currentDay.AddDate(0, 0, i))
|
||||
if dayData.SampleCount > 0 {
|
||||
result = append(result, dayData)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
Loading…
Reference in New Issue