added roundstats with eco info, switched to avatar hash

This commit is contained in:
2021-10-17 03:52:20 +02:00
parent 7f5a2f8956
commit fd8c026a8e
35 changed files with 4187 additions and 160 deletions

View File

@@ -7,6 +7,7 @@ import (
"csgowtfd/ent/match"
"csgowtfd/ent/player"
"csgowtfd/ent/predicate"
"csgowtfd/ent/roundstats"
"csgowtfd/ent/stats"
"csgowtfd/ent/weaponstats"
"database/sql/driver"
@@ -32,6 +33,7 @@ type StatsQuery struct {
withMatches *MatchQuery
withPlayers *PlayerQuery
withWeaponStats *WeaponStatsQuery
withRoundStats *RoundStatsQuery
modifiers []func(s *sql.Selector)
// intermediate query (i.e. traversal path).
sql *sql.Selector
@@ -135,6 +137,28 @@ func (sq *StatsQuery) QueryWeaponStats() *WeaponStatsQuery {
return query
}
// QueryRoundStats chains the current query on the "round_stats" edge.
func (sq *StatsQuery) QueryRoundStats() *RoundStatsQuery {
query := &RoundStatsQuery{config: sq.config}
query.path = func(ctx context.Context) (fromU *sql.Selector, err error) {
if err := sq.prepareQuery(ctx); err != nil {
return nil, err
}
selector := sq.sqlQuery(ctx)
if err := selector.Err(); err != nil {
return nil, err
}
step := sqlgraph.NewStep(
sqlgraph.From(stats.Table, stats.FieldID, selector),
sqlgraph.To(roundstats.Table, roundstats.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, stats.RoundStatsTable, stats.RoundStatsColumn),
)
fromU = sqlgraph.SetNeighbors(sq.driver.Dialect(), step)
return fromU, nil
}
return query
}
// First returns the first Stats entity from the query.
// Returns a *NotFoundError when no Stats was found.
func (sq *StatsQuery) First(ctx context.Context) (*Stats, error) {
@@ -319,6 +343,7 @@ func (sq *StatsQuery) Clone() *StatsQuery {
withMatches: sq.withMatches.Clone(),
withPlayers: sq.withPlayers.Clone(),
withWeaponStats: sq.withWeaponStats.Clone(),
withRoundStats: sq.withRoundStats.Clone(),
// clone intermediate query.
sql: sq.sql.Clone(),
path: sq.path,
@@ -358,6 +383,17 @@ func (sq *StatsQuery) WithWeaponStats(opts ...func(*WeaponStatsQuery)) *StatsQue
return sq
}
// WithRoundStats tells the query-builder to eager-load the nodes that are connected to
// the "round_stats" edge. The optional arguments are used to configure the query builder of the edge.
func (sq *StatsQuery) WithRoundStats(opts ...func(*RoundStatsQuery)) *StatsQuery {
query := &RoundStatsQuery{config: sq.config}
for _, opt := range opts {
opt(query)
}
sq.withRoundStats = query
return sq
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
@@ -423,10 +459,11 @@ func (sq *StatsQuery) sqlAll(ctx context.Context) ([]*Stats, error) {
var (
nodes = []*Stats{}
_spec = sq.querySpec()
loadedTypes = [3]bool{
loadedTypes = [4]bool{
sq.withMatches != nil,
sq.withPlayers != nil,
sq.withWeaponStats != nil,
sq.withRoundStats != nil,
}
)
_spec.ScanValues = func(columns []string) ([]interface{}, error) {
@@ -533,6 +570,35 @@ func (sq *StatsQuery) sqlAll(ctx context.Context) ([]*Stats, error) {
}
}
if query := sq.withRoundStats; query != nil {
fks := make([]driver.Value, 0, len(nodes))
nodeids := make(map[int]*Stats)
for i := range nodes {
fks = append(fks, nodes[i].ID)
nodeids[nodes[i].ID] = nodes[i]
nodes[i].Edges.RoundStats = []*RoundStats{}
}
query.withFKs = true
query.Where(predicate.RoundStats(func(s *sql.Selector) {
s.Where(sql.InValues(stats.RoundStatsColumn, fks...))
}))
neighbors, err := query.All(ctx)
if err != nil {
return nil, err
}
for _, n := range neighbors {
fk := n.stats_round_stats
if fk == nil {
return nil, fmt.Errorf(`foreign-key "stats_round_stats" is nil for node %v`, n.ID)
}
node, ok := nodeids[*fk]
if !ok {
return nil, fmt.Errorf(`unexpected foreign-key "stats_round_stats" returned %v for node %v`, *fk, n.ID)
}
node.Edges.RoundStats = append(node.Edges.RoundStats, n)
}
}
return nodes, nil
}