fixed avgrank failing if no rank is present in game
This commit is contained in:
20
main.go
20
main.go
@@ -737,12 +737,14 @@ func getMatches(w http.ResponseWriter, r *http.Request) {
|
|||||||
Avg float64 `json:"avg"`
|
Avg float64 `json:"avg"`
|
||||||
MatchID uint64 `json:"match_stats"`
|
MatchID uint64 `json:"match_stats"`
|
||||||
}
|
}
|
||||||
|
avgRank := 0.0
|
||||||
|
|
||||||
err := iMatch.QueryStats().Where(matchplayer.RankOldNEQ(0)).GroupBy(matchplayer.MatchesColumn).Aggregate(ent.Mean(matchplayer.FieldRankOld)).Scan(context.Background(), &v)
|
err := iMatch.QueryStats().Where(matchplayer.RankOldNEQ(0)).GroupBy(matchplayer.MatchesColumn).Aggregate(ent.Mean(matchplayer.FieldRankOld)).Scan(context.Background(), &v)
|
||||||
if err != nil || len(v) == 0 {
|
if err != nil || len(v) == 0 {
|
||||||
log.Errorf("[GMS] Unable to calc avg rank for match %d: %v", iMatch.ID, err)
|
log.Warningf("[GMS] Unable to calc avg rank for match %d: %v", iMatch.ID, err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
avgRank = 0.0
|
||||||
return
|
} else {
|
||||||
|
avgRank = v[0].Avg
|
||||||
}
|
}
|
||||||
|
|
||||||
mResponse = append(mResponse, &utils.MatchResponse{
|
mResponse = append(mResponse, &utils.MatchResponse{
|
||||||
@@ -756,7 +758,7 @@ func getMatches(w http.ResponseWriter, r *http.Request) {
|
|||||||
Parsed: iMatch.DemoParsed,
|
Parsed: iMatch.DemoParsed,
|
||||||
VAC: iMatch.VacPresent,
|
VAC: iMatch.VacPresent,
|
||||||
GameBan: iMatch.GamebanPresent,
|
GameBan: iMatch.GamebanPresent,
|
||||||
AvgRank: v[0].Avg,
|
AvgRank: avgRank,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -794,11 +796,13 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
|
|||||||
MatchID uint64 `json:"match_stats"`
|
MatchID uint64 `json:"match_stats"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avgRank := 0.0
|
||||||
err = tMatch.QueryStats().Where(matchplayer.RankOldNEQ(0)).GroupBy(matchplayer.MatchesColumn).Aggregate(ent.Mean(matchplayer.FieldRankOld)).Scan(context.Background(), &v)
|
err = tMatch.QueryStats().Where(matchplayer.RankOldNEQ(0)).GroupBy(matchplayer.MatchesColumn).Aggregate(ent.Mean(matchplayer.FieldRankOld)).Scan(context.Background(), &v)
|
||||||
if err != nil || len(v) == 0 {
|
if err != nil || len(v) == 0 {
|
||||||
log.Errorf("[GM] Unable to calc avg rank for match %d: %v", tMatch.ID, err)
|
log.Warningf("[GM] Unable to calc avg rank for match %d: %v", tMatch.ID, err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
avgRank = 0
|
||||||
return
|
} else {
|
||||||
|
avgRank = v[0].Avg
|
||||||
}
|
}
|
||||||
|
|
||||||
mResponse := &utils.MatchResponse{
|
mResponse := &utils.MatchResponse{
|
||||||
@@ -812,7 +816,7 @@ func getMatch(w http.ResponseWriter, r *http.Request) {
|
|||||||
MaxRounds: tMatch.MaxRounds,
|
MaxRounds: tMatch.MaxRounds,
|
||||||
Parsed: tMatch.DemoParsed,
|
Parsed: tMatch.DemoParsed,
|
||||||
Stats: []*utils.StatsResponse{},
|
Stats: []*utils.StatsResponse{},
|
||||||
AvgRank: v[0].Avg,
|
AvgRank: avgRank,
|
||||||
}
|
}
|
||||||
|
|
||||||
if tMatch.Date.After(time.Now().AddDate(0, 0, -1*conf.Csgowtfd.DemosExpire)) {
|
if tMatch.Date.After(time.Now().AddDate(0, 0, -1*conf.Csgowtfd.DemosExpire)) {
|
||||||
|
Reference in New Issue
Block a user