storage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const SecsInADay = 86400

Variables

View Source
var DiscussCode = fmt.Sprintf("%d", game.DISCUSS)
View Source
var TasksCode = fmt.Sprintf("%d", game.TASKS)

Functions

func CanTransfer

func CanTransfer(origin, dest *PostgresGuild) error

CanTransfer determines the set of possible transfers for server premium it does NOT allow for chained transfers! Aka if A -> B, then B cannot transfer to C (nor back to A)

func ConstructPsqlConnectURL

func ConstructPsqlConnectURL(addr, username, password string) string

Types

type GameStatistics

type GameStatistics struct {
	GameDuration time.Duration
	WinType      game.GameResult

	NumMeetings    int
	NumDeaths      int
	NumVotedOff    int
	NumDisconnects int
	Events         []SimpleEvent
}

func StatsFromGameAndEvents

func StatsFromGameAndEvents(pgame *PostgresGame, events []*PostgresGameEvent) GameStatistics

func (*GameStatistics) FormatDurationAndWin

func (stats *GameStatistics) FormatDurationAndWin() string

TODO localize

func (*GameStatistics) ToDiscordEmbed

func (stats *GameStatistics) ToDiscordEmbed(combinedID string, sett *settings.GuildSettings) *discordgo.MessageEmbed

func (*GameStatistics) ToString

func (stats *GameStatistics) ToString() string

type Int16ModeCount

type Int16ModeCount struct {
	Count int64 `db:"count"`
	Mode  int16 `db:"mode"`
}

type PostgresBestTeammatePlayerRanking

type PostgresBestTeammatePlayerRanking struct {
	UserID     uint64  `db:"user_id"`
	TeammateID uint64  `db:"teammate_id"`
	WinCount   int64   `db:"win"`
	Count      int64   `db:"total"`
	WinRate    float64 `db:"win_rate"`
}

type PostgresGame

type PostgresGame struct {
	GameID      int64  `db:"game_id"`
	GuildID     uint64 `db:"guild_id"`
	ConnectCode string `db:"connect_code"`
	StartTime   int32  `db:"start_time"`
	WinType     int16  `db:"win_type"`
	EndTime     int32  `db:"end_time"`
}

type PostgresGameEvent

type PostgresGameEvent struct {
	EventID   uint64  `db:"event_id"`
	UserID    *uint64 `db:"user_id"`
	GameID    int64   `db:"game_id"`
	EventTime int32   `db:"event_time"`
	EventType int16   `db:"event_type"`
	Payload   string  `db:"payload"`
}

type PostgresGuild

type PostgresGuild struct {
	GuildID       uint64  `db:"guild_id"`
	GuildName     string  `db:"guild_name"`
	Premium       int16   `db:"premium"`
	TxTimeUnix    *int32  `db:"tx_time_unix"`
	TransferredTo *uint64 `db:"transferred_to"`
	InheritsFrom  *uint64 `db:"inherits_from"`
}

type PostgresOtherPlayerRanking

type PostgresOtherPlayerRanking struct {
	UserID  uint64  `db:"user_id"`
	Count   int64   `db:"count"`
	Percent float64 `db:"percent"`
}

type PostgresPlayerRanking

type PostgresPlayerRanking struct {
	UserID   uint64  `db:"user_id"`
	WinCount int64   `db:"win"`
	Count    int64   `db:"total"`
	WinRate  float64 `db:"win_rate"`
}

type PostgresUser

type PostgresUser struct {
	UserID uint64 `db:"user_id"`
	Opt    bool   `db:"opt"`
}

type PostgresUserActionRanking

type PostgresUserActionRanking struct {
	UserID      uint64  `db:"user_id"`
	TotalAction int64   `db:"total_action"`
	Count       int64   `db:"total"`
	WinRate     float64 `db:"win_rate"`
}

type PostgresUserGame

type PostgresUserGame struct {
	UserID      uint64 `db:"user_id"`
	GuildID     uint64 `db:"guild_id"`
	GameID      int64  `db:"game_id"`
	PlayerName  string `db:"player_name"`
	PlayerColor int16  `db:"player_color"`
	PlayerRole  int16  `db:"player_role"`
	PlayerWon   bool   `db:"player_won"`
}

type PostgresUserMostFrequentFirstTargetRanking

type PostgresUserMostFrequentFirstTargetRanking struct {
	UserID     uint64  `db:"user_id"`
	TotalDeath int64   `db:"total_death"`
	Count      int64   `db:"total"`
	DeathRate  float64 `db:"death_rate"`
}

type PostgresUserMostFrequentKilledByanking

type PostgresUserMostFrequentKilledByanking struct {
	UserID     uint64  `db:"user_id"`
	TeammateID uint64  `db:"teammate_id"`
	TotalDeath int64   `db:"total_death"`
	Encounter  int64   `db:"encounter"`
	DeathRate  float64 `db:"death_rate"`
}

type PostgresWorstTeammatePlayerRanking

type PostgresWorstTeammatePlayerRanking struct {
	UserID     uint64  `db:"user_id"`
	TeammateID uint64  `db:"teammate_id"`
	LooseCount int64   `db:"loose"`
	Count      int64   `db:"total"`
	LooseRate  float64 `db:"loose_rate"`
}

type PsqlInterface

type PsqlInterface struct {
	Pool *pgxpool.Pool
}

func (*PsqlInterface) AddEvent

func (psqlInterface *PsqlInterface) AddEvent(event *PostgresGameEvent) error

func (*PsqlInterface) AddGoldSubServer

func (psqlInterface *PsqlInterface) AddGoldSubServer(origin, dest string) error

func (*PsqlInterface) AddInitialGame

func (psqlInterface *PsqlInterface) AddInitialGame(game *PostgresGame) (uint64, error)

func (*PsqlInterface) BestTeammateByRole

func (psqlInterface *PsqlInterface) BestTeammateByRole(userID, guildID string, role int16, leaderboardMin int) []*PostgresBestTeammatePlayerRanking

func (*PsqlInterface) BestTeammateForServerByRole

func (psqlInterface *PsqlInterface) BestTeammateForServerByRole(guildID string, role int16, leaderboardMin int) []*PostgresBestTeammatePlayerRanking

func (*PsqlInterface) Close

func (psqlInterface *PsqlInterface) Close()

func (*PsqlInterface) ColorRankingForPlayerOnServer

func (psqlInterface *PsqlInterface) ColorRankingForPlayerOnServer(userID, guildID string) []*Int16ModeCount
func (psqlInterface *PsqlInterface) ColorRankingForPlayer(userID string) []*Int16ModeCount {
	r := []*Int16ModeCount{}
	err := pgxscan.Select(context.Background(), psqlInterface.Pool, &r, "SELECT count(*),mode() within GROUP (ORDER BY player_color) AS mode FROM users_games WHERE user_id=$1 GROUP BY player_color ORDER BY count desc;", userID)

	if err != nil {
		log.Println(err)
	}
	return r
}

func (*PsqlInterface) DeleteAllGamesForServer

func (psqlInterface *PsqlInterface) DeleteAllGamesForServer(guildID string) error

func (*PsqlInterface) DeleteAllGamesForUser

func (psqlInterface *PsqlInterface) DeleteAllGamesForUser(userID string) error

func (*PsqlInterface) EnsureGuildExists

func (psqlInterface *PsqlInterface) EnsureGuildExists(guildID uint64, guildName string) (*PostgresGuild, error)

func (*PsqlInterface) EnsureUserExists

func (psqlInterface *PsqlInterface) EnsureUserExists(userID uint64) (*PostgresUser, error)

func (*PsqlInterface) GetGame

func (psqlInterface *PsqlInterface) GetGame(guildID, connectCode, matchID string) (*PostgresGame, error)

func (*PsqlInterface) GetGameEvents

func (psqlInterface *PsqlInterface) GetGameEvents(matchID string) ([]*PostgresGameEvent, error)

func (*PsqlInterface) GetGuildPremiumStatus

func (psqlInterface *PsqlInterface) GetGuildPremiumStatus(guildID string) (premium.Tier, int)

func (*PsqlInterface) GetUser

func (psqlInterface *PsqlInterface) GetUser(userID uint64) (*PostgresUser, error)

func (*PsqlInterface) GetUserByString

func (psqlInterface *PsqlInterface) GetUserByString(userID string) (*PostgresUser, error)

func (*PsqlInterface) Init

func (psqlInterface *PsqlInterface) Init(addr string) error

func (*PsqlInterface) LoadAndExecFromFile

func (psqlInterface *PsqlInterface) LoadAndExecFromFile(filepath string) error

func (*PsqlInterface) NamesRankingForPlayerOnServer

func (psqlInterface *PsqlInterface) NamesRankingForPlayerOnServer(userID, guildID string) []*StringModeCount

func (*PsqlInterface) NumGamesAsRole

func (psqlInterface *PsqlInterface) NumGamesAsRole(userID string, role int16) int64

func (*PsqlInterface) NumGamesAsRoleOnServer

func (psqlInterface *PsqlInterface) NumGamesAsRoleOnServer(userID, guildID string, role int16) int64

func (*PsqlInterface) NumGamesPlayedByUser

func (psqlInterface *PsqlInterface) NumGamesPlayedByUser(userID string) int64

func (*PsqlInterface) NumGamesPlayedByUserOnServer

func (psqlInterface *PsqlInterface) NumGamesPlayedByUserOnServer(userID, guildID string) int64

func (*PsqlInterface) NumGamesPlayedOnGuild

func (psqlInterface *PsqlInterface) NumGamesPlayedOnGuild(guildID string) int64

func (*PsqlInterface) NumGamesWonAsRoleOnServer

func (psqlInterface *PsqlInterface) NumGamesWonAsRoleOnServer(guildID string, role game.GameRole) int64

func (*PsqlInterface) NumGuildsPlayedInByUser

func (psqlInterface *PsqlInterface) NumGuildsPlayedInByUser(userID string) int64

func (*PsqlInterface) NumWins

func (psqlInterface *PsqlInterface) NumWins(userID string) int64

func (*PsqlInterface) NumWinsAsRole

func (psqlInterface *PsqlInterface) NumWinsAsRole(userID string, role int16) int64

func (*PsqlInterface) NumWinsAsRoleOnServer

func (psqlInterface *PsqlInterface) NumWinsAsRoleOnServer(userID, guildID string, role int16) int64

func (*PsqlInterface) NumWinsOnServer

func (psqlInterface *PsqlInterface) NumWinsOnServer(userID, guildID string) int64

func (*PsqlInterface) OptUserByString

func (psqlInterface *PsqlInterface) OptUserByString(userID string, opt bool) error

func (*PsqlInterface) OtherPlayersRankingForPlayerOnServer

func (psqlInterface *PsqlInterface) OtherPlayersRankingForPlayerOnServer(userID, guildID string) []*PostgresOtherPlayerRanking

func (*PsqlInterface) TotalGamesRankingForServer

func (psqlInterface *PsqlInterface) TotalGamesRankingForServer(guildID uint64) []*Uint64ModeCount

func (*PsqlInterface) TotalWinRankingForServer

func (psqlInterface *PsqlInterface) TotalWinRankingForServer(guildID uint64) []*PostgresPlayerRanking

func (*PsqlInterface) TotalWinRankingForServerByRole

func (psqlInterface *PsqlInterface) TotalWinRankingForServerByRole(guildID uint64, role int16) []*PostgresPlayerRanking

func (*PsqlInterface) TransferPremium

func (psqlInterface *PsqlInterface) TransferPremium(origin, dest string) error

func (*PsqlInterface) UpdateGameAndPlayers

func (psqlInterface *PsqlInterface) UpdateGameAndPlayers(gameID int64, winType int16, endTime int64, players []*PostgresUserGame) error

make sure to call the relevant "ensure" methods before this one...

func (*PsqlInterface) UserFrequentFirstTarget

func (psqlInterface *PsqlInterface) UserFrequentFirstTarget(userID, guildID string, action string, leaderboardSize int) []*PostgresUserMostFrequentFirstTargetRanking

func (*PsqlInterface) UserMostFrequentFirstTargetForServer

func (psqlInterface *PsqlInterface) UserMostFrequentFirstTargetForServer(guildID string, action string, leaderboardSize int) []*PostgresUserMostFrequentFirstTargetRanking

func (*PsqlInterface) UserMostFrequentKilledBy

func (psqlInterface *PsqlInterface) UserMostFrequentKilledBy(userID, guildID string) []*PostgresUserMostFrequentKilledByanking

func (*PsqlInterface) UserMostFrequentKilledByServer

func (psqlInterface *PsqlInterface) UserMostFrequentKilledByServer(guildID string) []*PostgresUserMostFrequentKilledByanking

func (*PsqlInterface) UserWinByActionAndRole

func (psqlInterface *PsqlInterface) UserWinByActionAndRole(userdID, guildID string, action string, role int16) []*PostgresUserActionRanking

func (*PsqlInterface) WorstTeammateByRole

func (psqlInterface *PsqlInterface) WorstTeammateByRole(userID, guildID string, role int16, leaderboardMin int) []*PostgresWorstTeammatePlayerRanking

func (*PsqlInterface) WorstTeammateForServerByRole

func (psqlInterface *PsqlInterface) WorstTeammateForServerByRole(guildID string, role int16, leaderboardMin int) []*PostgresWorstTeammatePlayerRanking

type PsqlParameters

type PsqlParameters struct {
	Addr     string
	Username string
	Password string
}

type SimpleEvent

type SimpleEvent struct {
	EventType       SimpleEventType
	EventTimeOffset time.Duration
	Data            string
}

type SimpleEventType

type SimpleEventType int
const (
	Tasks SimpleEventType = iota
	Discuss
	PlayerDeath
	PlayerDisconnect
)

type StringModeCount

type StringModeCount struct {
	Count int64  `db:"count"`
	Mode  string `db:"mode"`
}

type Uint64ModeCount

type Uint64ModeCount struct {
	Count int64  `db:"count"`
	Mode  uint64 `db:"mode"`
}

Jump to

Keyboard shortcuts

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