some formatting fixes

This commit is contained in:
2022-11-03 03:39:22 +01:00
parent 4d36ce8899
commit 3e4b90a1bd
2 changed files with 29 additions and 9 deletions

36
main.go
View File

@@ -37,7 +37,6 @@ import (
"time"
)
//goland:noinspection ALL
var (
conf = utils.Conf{}
demoLoader = &csgo.DemoMatchLoader{}
@@ -91,20 +90,34 @@ func housekeeping() {
}
// mark matches as vac/gameban
bPlayers, err := db.Player.Query().Select(player.FieldID, player.FieldGameBanDate, player.FieldVacDate).Where(player.Or(player.GameBanDateNotNil(), player.VacDateNotNil())).All(context.Background())
bPlayers, err := db.Player.Query().
Select(player.FieldID, player.FieldGameBanDate, player.FieldVacDate).
Where(player.Or(player.GameBanDateNotNil(), player.VacDateNotNil())).
All(context.Background())
if err != nil {
log.Warningf("[HK] Unable to query for banned players: %v", err)
}
for _, bp := range bPlayers {
if !bp.GameBanDate.IsZero() {
err := db.Match.Update().Where(match.And(match.HasPlayersWith(player.ID(bp.ID)), match.DateLTE(bp.GameBanDate.AddDate(0, 0, 30)))).SetGamebanPresent(true).Exec(context.Background())
err := db.Match.Update().
Where(
match.And(
match.HasPlayersWith(player.ID(bp.ID)),
match.DateLTE(bp.GameBanDate.AddDate(0, 0, 30)),
)).
SetGamebanPresent(true).Exec(context.Background())
if err != nil {
log.Warningf("[HK] Unable to set gameban/vac for match: %v", err)
}
}
if !bp.VacDate.IsZero() {
err := db.Match.Update().Where(match.And(match.HasPlayersWith(player.ID(bp.ID)), match.DateLTE(bp.VacDate.AddDate(0, 0, 30)))).SetVacPresent(true).Exec(context.Background())
err := db.Match.Update().
Where(
match.And(
match.HasPlayersWith(player.ID(bp.ID)),
match.DateLTE(bp.VacDate.AddDate(0, 0, 30)),
)).SetVacPresent(true).Exec(context.Background())
if err != nil {
log.Warningf("[HK] Unable to set gameban/vac for match: %v", err)
}
@@ -112,7 +125,12 @@ func housekeeping() {
}
// try parsing demos not parsed
tMatches, err := db.Match.Query().Where(match.And(match.DateGT(time.Now().UTC().AddDate(0, 0, -1*conf.Csgowtfd.DemosExpire)), match.DemoParsed(false))).All(context.Background())
tMatches, err := db.Match.Query().
Where(
match.And(
match.DateGT(time.Now().UTC().AddDate(0, 0, -1*conf.Csgowtfd.DemosExpire)),
match.DemoParsed(false))).
All(context.Background())
if err != nil {
log.Warningf("[HK] Failure getting matches to retry parsing: %v", err)
continue
@@ -133,20 +151,22 @@ func housekeeping() {
// 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)
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)