// CountStatesResult count round states (up/down/etc.) result func CountStatesResult(db *sql.DB, round, team int, service steward.Service) (score float64, err error) { halfStatus := steward.Status{round, team, service.ID, steward.StatusUnknown} states, err := steward.GetStates(db, halfStatus) if err != nil { return } if len(states) == 0 { return } ok := 0.0 for _, state := range states { if state == steward.StatusUP { ok++ } } score = 1.0 / float64(len(states)) * ok return }
func TestGetAllStatus(t *testing.T) { db, err := openDB() defer db.Close() round := 1 team := 2 service := 3 status1 := steward.Status{Round: round, TeamID: team, ServiceID: service, State: steward.StatusUP} status2 := steward.Status{Round: round, TeamID: team, ServiceID: service, State: steward.StatusMumble} status3 := steward.Status{Round: round, TeamID: team, ServiceID: service, State: steward.StatusCorrupt} steward.PutStatus(db.db, status1) steward.PutStatus(db.db, status2) steward.PutStatus(db.db, status3) halfStatus := steward.Status{Round: round, TeamID: team, ServiceID: service, State: steward.StatusUnknown} states, err := steward.GetStates(db.db, halfStatus) if err != nil { log.Fatalln("Get states failed:", err) } if len(states) != 3 { log.Fatalln("Get states moar/less than put:", err) } if states[0] != steward.StatusUP || states[1] != steward.StatusMumble || states[2] != steward.StatusCorrupt { log.Fatalln("Get states invalid") } }