added match meta stats
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"csgowtfd/ent"
|
||||
"csgowtfd/ent/match"
|
||||
"csgowtfd/ent/player"
|
||||
"csgowtfd/ent/stats"
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
@@ -98,6 +99,50 @@ func SendJSON(data interface{}, w http.ResponseWriter) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetMatchStats(db *ent.Client, lock *sync.RWMutex, player *ent.Player) (int, int, int, error) {
|
||||
var v struct {
|
||||
Wins int `json:"wins"`
|
||||
Ties int `json:"ties"`
|
||||
Total int `json:"total"`
|
||||
}
|
||||
err := player.QueryMatches().
|
||||
WithStats().
|
||||
Where(
|
||||
match.Or(
|
||||
match.And(
|
||||
match.HasStatsWith(stats.TeamIDEQ(1)),
|
||||
match.MatchResultEQ(1)),
|
||||
match.And(
|
||||
match.HasStatsWith(stats.TeamIDEQ(2)),
|
||||
match.MatchResultEQ(2))),
|
||||
).
|
||||
GroupBy(match.FieldMatchID).
|
||||
Aggregate(ent.As(ent.Count(), "wins")).
|
||||
Scan(context.Background(), &v)
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
||||
err = player.QueryMatches().
|
||||
Where(match.MatchResultEQ(0)).
|
||||
GroupBy(match.FieldMatchID).
|
||||
Aggregate(ent.As(ent.Count(), "ties")).
|
||||
Scan(context.Background(), &v)
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
||||
err = player.QueryMatches().
|
||||
GroupBy(match.FieldMatchID).
|
||||
Aggregate(ent.As(ent.Count(), "total")).
|
||||
Scan(context.Background(), &v)
|
||||
if err != nil {
|
||||
return 0, 0, 0, err
|
||||
}
|
||||
|
||||
return v.Wins, v.Ties, v.Total - v.Wins - v.Ties, nil
|
||||
}
|
||||
|
||||
func IsAuthCodeValid(player *ent.Player, lock *sync.RWMutex, apiKey string, shareCode string, authCode string, rl ratelimit.Limiter) (bool, error) {
|
||||
var tMatch *ent.Match
|
||||
var err error
|
||||
|
Reference in New Issue
Block a user