All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 1m27s
- Implemented TotalPlayerCountLogic to retrieve the total number of unique players within a specified time range. - Implemented TotalPlayTimeLogic to calculate the total playtime of players within a specified time range. - Created ServiceContext to manage database connections and initialize necessary tables. - Added types for total player count and total playtime requests and responses. - Set up the main server file to start the application with the necessary configurations. - Updated go.mod and go.sum for new dependencies.
61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package logic
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/svc"
|
|
"git.cialloo.com/CiallooWeb/ServerStatistics/app/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type TopKillerLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// Get top players by kill count within a specified time range
|
|
func NewTopKillerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TopKillerLogic {
|
|
return &TopKillerLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *TopKillerLogic) TopKiller(req *types.TopKillerReq) (resp *types.TopKillerResp, err error) {
|
|
query := `
|
|
SELECT attacker_steamid64, attacker_name,
|
|
COUNT(*) as kill_count
|
|
FROM steam_union.event_player_death_log
|
|
WHERE event_player_death_time >= TO_TIMESTAMP($1 / 1000.0)
|
|
AND event_player_death_time <= TO_TIMESTAMP($2 / 1000.0)
|
|
AND attacker_steamid64 > 1
|
|
GROUP BY attacker_steamid64, attacker_name
|
|
ORDER BY kill_count DESC
|
|
LIMIT $3
|
|
`
|
|
|
|
rows, err := l.svcCtx.DB.QueryContext(l.ctx, query, req.TimeRangeStart, req.TimeRangeEnd, req.Limit)
|
|
if err != nil {
|
|
l.Errorf("Failed to query top killers: %v", err)
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var players []types.TopKillerRespPlayer
|
|
for rows.Next() {
|
|
var player types.TopKillerRespPlayer
|
|
if err := rows.Scan(&player.SteamID64, &player.UserName, &player.KillCount); err != nil {
|
|
l.Errorf("Failed to scan top killer: %v", err)
|
|
continue
|
|
}
|
|
players = append(players, player)
|
|
}
|
|
|
|
return &types.TopKillerResp{
|
|
Players: players,
|
|
}, nil
|
|
}
|