db

package
v0.0.0-...-7e087bf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Redis *redis.Client
View Source
var SQL *sql.DB

Functions

func CalculateClanOverallAccuracy

func CalculateClanOverallAccuracy(clan int, mode int) (float64, error)

Calculates the overall accuracy of a clan

func CalculateClanOverallRating

func CalculateClanOverallRating(clan int, mode int) (float64, error)

Calculates the overall rating of a clan

func CalculateOverallAccuracy

func CalculateOverallAccuracy(scores []Score) float64

CalculateOverallAccuracy calculates the overall accuracy from a list of scores Assumes that the scores are sorted by performance rating

func CalculateOverallRating

func CalculateOverallRating(scores []Score) float64

CalculateOverallRating Calculates the overall rating of a list of scores. Assumes that scores are sorted by performance rating

func CloseSQLConnection

func CloseSQLConnection()

CloseSQLConnection Closes the existing SQL connection

func GetCountryLeaderboardKey

func GetCountryLeaderboardKey(u *User, mode common.Mode) string

GetCountryLeaderboardKey Gets the country leaderboard redis key for a country and mode

func GetGlobalLeaderboardKey

func GetGlobalLeaderboardKey(mode common.Mode) string

GetGlobalLeaderboardKey Gets the global leaderboard redis key for a game mode

func IncrementMapPlayCount

func IncrementMapPlayCount(id int, failed bool) error

IncrementMapPlayCount Increments the play count & fail count of the map in the db & ES TODO: Update ES

func InitializeRedis

func InitializeRedis()

InitializeRedis Initializes a Redis client

func InitializeSQL

func InitializeSQL()

InitializeSQL Initializes the SQL database connection

func InsertActivityFeed

func InsertActivityFeed(userId int, feed ActivityFeed, value string, mapsetId int) error

InsertActivityFeed Adds an activity feed log to the database

func InsertClanScore

func InsertClanScore(score *ClanScore) error

Inserts a new clan score to the database (or updates it if it already exists)

func PublishFirstPlaceScoreRedis

func PublishFirstPlaceScoreRedis(username, artist, title, difficultyName string) error

func UpdateClanLeaderboards

func UpdateClanLeaderboards(clan int, mode int, rating float64) error

Update a clan's rating in redis

func UpdateClanStats

func UpdateClanStats(clan int, mode int, rating float64, acc float64) error

Updates a clan's stats in the database

func UpdateCountryLeaderboard

func UpdateCountryLeaderboard(u *User, mode common.Mode, rating float64) error

UpdateCountryLeaderboard Updates the country leaderboard for a given user and game mode

func UpdateGlobalLeaderboard

func UpdateGlobalLeaderboard(u *User, mode common.Mode, rating float64) error

UpdateGlobalLeaderboard Updates the global leaderboard for a user in redis

func UpdateScoreboardCache

func UpdateScoreboardCache(s *Score, m *Map) error

UpdateScoreboardCache Updates the redis cache for a particular score

func UpdateUserLatestActivity

func UpdateUserLatestActivity(id int) error

UpdateUserLatestActivity Updates a user's latest activity to the current time

Types

type ActivityFeed

type ActivityFeed int
const (
	ActivityFeedRegistered ActivityFeed = iota
	ActivityFeedUploadedMapset
	ActivityFeedUpdatedMapset
	ActivityFeedRankedMapset
	ActivityFeedDeniedMapset
	ActivityFeedAchievedFirstPlace
	ActivityFeedLostFirstPlace
	ActivityFeedUnlockedAchievement
	ActivityFeedDonated
	ActivityFeedReceivedDonatorGift
)

type ClanScore

type ClanScore struct {
	Id              int
	ClanId          int
	Mode            int
	MapMD5          string
	OverallRating   float64
	OverallAccuracy float64
}

func CalculateClanMapScore

func CalculateClanMapScore(clan int, md5 string) (ClanScore, error)

Calculates an individual score on a map from a clan

func GetClanOverallScores

func GetClanOverallScores(clan int, mode int) ([]ClanScore, error)

Retrieves a clan's top scores

func (*ClanScore) ToScore

func (c *ClanScore) ToScore() Score

Converts an individual ClanScore to db.Score

type FirstPlaceScore

type FirstPlaceScore struct {
	MD5               string
	UserId            int
	ScoreId           int
	PerformanceRating float64
}

func GetFirstPlaceScore

func GetFirstPlaceScore(md5 string) (FirstPlaceScore, error)

GetFirstPlaceScore Retrieves a first place score for a given map

func NewFirstPlaceScore

func NewFirstPlaceScore(md5 string, userId int, scoreId int, rating float64) FirstPlaceScore

func (*FirstPlaceScore) Insert

func (s *FirstPlaceScore) Insert() error

Insert Inserts this first place score into the database

func (*FirstPlaceScore) Update

func (s *FirstPlaceScore) Update() error

Update Updates the first place score in the database

type Map

type Map struct {
	Id                   int
	MapsetId             int
	MD5                  string
	AlternativeMD5       sql.NullString
	CreatorId            int
	CreatorUsername      string
	GameMode             common.Mode
	RankedStatus         common.RankedStatus
	Length               int32
	Artist               string
	Title                string
	DifficultyName       string
	DifficultyRating     float64
	ClanRanked           bool
	CountHitObjectNormal int32
	CountHitObjectLong   int32
}

func GetMapById

func GetMapById(id int32) (Map, error)

GetMapById Fetches a map in the database by its id

func GetMapByMD5

func GetMapByMD5(md5 string) (Map, error)

GetMapByMD5 Fetches a map in the database by its MD5 hash

func (*Map) GetString

func (m *Map) GetString() string

GetString Returns a stringified version of the map's artist, title, and difficulty name

type RowScanner

type RowScanner interface {
	Scan(dest ...interface{}) error
}

type Score

type Score struct {
	Id                          int
	UserId                      int
	MapMD5                      string
	ReplayMD5                   string
	Timestamp                   int64
	Mode                        common.Mode
	PersonalBest                bool
	PerformanceRating           float64
	Mods                        common.Mods
	Failed                      bool
	TotalScore                  int32
	Accuracy                    float32
	MaxCombo                    int
	CountMarv                   int
	CountPerf                   int
	CountGreat                  int
	CountGood                   int
	CountOkay                   int
	CountMiss                   int
	Grade                       common.Grade
	ScrollSpeed                 int
	TimePlayStart               int64
	TimePlayEnd                 int64
	Ip                          string
	ExecutingAssembly           string
	EntryAssembly               string
	QuaverVersion               string
	PauseCount                  int
	PerformanceProcessorVersion string
	DifficultyProcessorVersion  string
	IsDonatorScore              bool
	TournamentGameId            sql.NullInt32
	ClanId                      sql.NullInt32
}

func ClanScoresToScores

func ClanScoresToScores(clanScores []ClanScore) []Score

Converts a slice of ClanScore to db.Score

func GetClanOverallScoresConverted

func GetClanOverallScoresConverted(clan int, mode int) ([]Score, error)

Returns a converted db.Score object from []ClanScore This is so we can pass it into calculation methods that require that struct

func GetClanPlayerScores

func GetClanPlayerScores(clan int, md5 string) ([]Score, error)

Retrieves a clan's scores on a particualr map MariaDB hack... https://stackoverflow.com/questions/6572110/order-by-date-and-time-before-group-by-name-in-mysql

func GetPersonalBestScore

func GetPersonalBestScore(u *User, m *Map) (Score, error)

GetPersonalBestScore Fetches a user's personal best score on a map

func GetScoreByReplayMD5

func GetScoreByReplayMD5(u *User, md5 string) (Score, error)

GetScoreByReplayMD5 Fetches a user's score by replay MD5 in the database

func GetUserTopScores

func GetUserTopScores(id int, mode common.Mode) ([]Score, error)

GetUserTopScores Fetches a user's top 500 scores

type User

type User struct {
	Id                          int
	SteamId                     string
	Username                    string
	Allowed                     bool
	Privileges                  int64
	UserGroups                  int64
	LatestActivity              int64
	Country                     string
	CheckedPreviousAchievements bool
	AvatarURL                   sql.NullString
	ClanId                      sql.NullInt32
	ShadowBanned                bool
}

func GetUserById

func GetUserById(id int) (User, error)

GetUserById Fetches a user object by their id

func (*User) GetAvatarURL

func (u *User) GetAvatarURL() string

func (*User) GetCountryRank

func (u *User) GetCountryRank(mode common.Mode) (int64, error)

GetCountryRank Retrieves a user's country rank for a specific game mode

func (*User) GetGlobalRank

func (u *User) GetGlobalRank(mode common.Mode) (int64, error)

GetGlobalRank Retrieves a user's global rank for a specific game mode

func (*User) ToString

func (u *User) ToString() string

type UserStats

type UserStats struct {
	Mode              common.Mode
	UserId            int
	TotalScore        int64
	RankedScore       int64
	OverallAccuracy   float64
	OverallRating     float64
	PlayCount         int32
	FailCount         int32
	MaxCombo          int32
	ReplaysWatched    int32
	TotalMarv         int32
	TotalPerf         int32
	TotalGreat        int32
	TotalGood         int32
	TotalOkay         int32
	TotalMiss         int32
	TotalPauses       int
	MultiplayerWins   int
	MultiplayerLosses int
	MultiplayerTies   int
	CountGradeX       int
	CountGradeSS      int
	CountGradeS       int
	CountGradeA       int
	CountGradeB       int
	CountGradeC       int
	CountGradeD       int
}

func GetUserStats

func GetUserStats(id int, mode common.Mode) (UserStats, error)

GetUserStats Retrieves a user's stats for a game mode

func (*UserStats) GetTotalHits

func (s *UserStats) GetTotalHits() int32

GetTotalHits Returns a sum of all hits (misses do onot count)

func (*UserStats) UpdateDatabase

func (s *UserStats) UpdateDatabase() error

UpdateDatabase Updates the user's stats in the database

func (*UserStats) UpdateGradeCount

func (s *UserStats) UpdateGradeCount(pb Score, oldPb Score) error

UpdateGradeCount Takes a users current pb and old pb and updates the grade count statistic.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL