added check for missing players to HK

This commit is contained in:
2021-11-18 00:01:57 +01:00
parent 85970d0214
commit 58317ed5fa
2 changed files with 68 additions and 0 deletions

36
main.go
View File

@@ -165,6 +165,42 @@ func housekeeping() {
log.Warningf("[HK] Failure trying to parse match %d: %v", m.ID, err) log.Warningf("[HK] Failure trying to parse match %d: %v", m.ID, err)
} }
} }
// check for inconsistent matches
tMatchIDs, err := db.Match.Query().IDs(context.Background())
for _, mid := range tMatchIDs {
var v []struct {
ID int `json:"match_stats"`
Count int `json:"count"`
}
err = db.MatchPlayer.Query().Where(matchplayer.MatchStats(mid)).GroupBy(matchplayer.FieldMatchStats).Aggregate(ent.Count()).Scan(context.Background(), &v)
if err != nil {
log.Warningf("[HK] Unable to query for matchplayers for match %d: %v", mid, err)
continue
}
log.Debugf("%+v", v)
if v[0].Count < 10 {
log.Warningf("[HK] Found match without all players, try to reload it.")
tMatch, err := db.Match.Get(context.Background(), mid)
if err != nil {
log.Warningf("[HK] Unable to get match with id %d: %v", mid, err)
continue
}
err = utils.DeleteMatch(tMatch, db)
if err != nil {
log.Warningf("[HK] Unable to delete match with id %d: %v", mid, err)
continue
}
err = demoLoader.LoadDemo(&csgo.Demo{ShareCode: tMatch.ShareCode})
if err != nil {
log.Warningf("[HK] Unable to requeue match with id %d: %v", mid, err)
}
}
}
} }
} }

View File

@@ -6,6 +6,8 @@ import (
"csgowtfd/ent/match" "csgowtfd/ent/match"
"csgowtfd/ent/matchplayer" "csgowtfd/ent/matchplayer"
"csgowtfd/ent/player" "csgowtfd/ent/player"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/spray"
"csgowtfd/ent/weapon" "csgowtfd/ent/weapon"
"encoding/json" "encoding/json"
"entgo.io/ent/dialect/sql" "entgo.io/ent/dialect/sql"
@@ -388,6 +390,36 @@ func GetMetaStats(dbPlayer *ent.Player) (*MetaStatsResponse, error) {
return mResponse, nil return mResponse, nil
} }
func DeleteMatch(matchDel *ent.Match, db *ent.Client) error {
tMatchPlayer, err := matchDel.QueryStats().IDs(context.Background())
if err != nil {
return err
}
_, err = db.Spray.Delete().Where(spray.HasMatchPlayersWith(matchplayer.IDIn(tMatchPlayer...))).Exec(context.Background())
if err != nil {
return err
}
_, err = db.Weapon.Delete().Where(weapon.HasStatWith(matchplayer.IDIn(tMatchPlayer...))).Exec(context.Background())
if err != nil {
return err
}
_, err = db.RoundStats.Delete().Where(roundstats.HasMatchPlayerWith(matchplayer.IDIn(tMatchPlayer...))).Exec(context.Background())
if err != nil {
return err
}
_, err = db.MatchPlayer.Delete().Where(matchplayer.IDIn(tMatchPlayer...)).Exec(context.Background())
if err != nil {
return err
}
_, err = db.Match.Delete().Where(match.ID(matchDel.ID)).Exec(context.Background())
if err != nil {
return err
}
return nil
}
func GetWinLossTieForPlayer(dbPlayer *ent.Player) (wins int, looses int, ties int, err error) { func GetWinLossTieForPlayer(dbPlayer *ent.Player) (wins int, looses int, ties int, err error) {
var res []struct { var res []struct {
MatchResult int `json:"match_result"` MatchResult int `json:"match_result"`