Documentation ¶
Index ¶
- Constants
- Variables
- func AclCan(c appengine.Context, requestor *datastore.Key, perm Permission, ...) (bool, error)
- func AclFindAll(c appengine.Context, requestor *datastore.Key, resourceKind string, ...) ([]*datastore.Key, error)
- func AclGrant(c appengine.Context, requestor *datastore.Key, resource *datastore.Key, ...) error
- func AclRevoke(c appengine.Context, requestor *datastore.Key, resource *datastore.Key, ...) error
- func AddGameTag(c appengine.Context, userAcls *RequestorAclCache, leagueKey *datastore.Key, ...) error
- func AddUnverifiedSummoner(c appengine.Context, userKey *datastore.Key, region string, summoner string) error
- func AddUserGameTag(c appengine.Context, userKey *datastore.Key, leagueKey *datastore.Key, ...) error
- func CreateScheduledMatch(c appengine.Context, userAcls *RequestorAclCache, league *League, ...) error
- func DecodeKeyShort(c appengine.Context, kind string, encodedKey string, parentKey *datastore.Key) (*datastore.Key, error)
- func DelGameTag(c appengine.Context, userAcls *RequestorAclCache, leagueKey *datastore.Key, ...) error
- func DelUserGameTag(c appengine.Context, userKey *datastore.Key, leagueKey *datastore.Key, ...) error
- func EncodeKeyShort(k *datastore.Key) string
- func EnsureGameExists(c appengine.Context, region string, gameKey *datastore.Key, ...) error
- func GameUri(gameKey *datastore.Key) string
- func GetGroupsForUser(c appengine.Context, userKey *datastore.Key) ([]*Group, []*GroupMembership, error)
- func GroupAddMember(c appengine.Context, groupKey *datastore.Key, userKey *datastore.Key, ...) error
- func GroupAddProposedMember(c appengine.Context, groupKey *datastore.Key, userKey *datastore.Key, ...) error
- func GroupById(c appengine.Context, userKey *datastore.Key, groupId string) (*Group, *datastore.Key, *GroupMembership, error)
- func GroupByKey(c appengine.Context, groupKey *datastore.Key, userKey *datastore.Key) (*Group, *GroupMembership, error)
- func GroupDelMember(c appengine.Context, groupKey *datastore.Key, userKey *datastore.Key) error
- func GroupId(groupKey *datastore.Key) string
- func GroupKeyById(c appengine.Context, groupId string) (*datastore.Key, error)
- func GroupRootKey(c appengine.Context) *datastore.Key
- func GroupUri(groupKey *datastore.Key) string
- func KeyForGame(c appengine.Context, region string, riotGameId int64) *datastore.Key
- func KeyForGameId(c appengine.Context, gameId string) *datastore.Key
- func KeyForPlayer(c appengine.Context, region string, riotSummonerId int64) *datastore.Key
- func KeyForPlayerGameStats(c appengine.Context, game *Game, player *Player) *datastore.Key
- func KeyForPlayerGameStatsId(c appengine.Context, gameId string, playerId string) *datastore.Key
- func LeagueAddGameByTeam(c appengine.Context, leagueKey *datastore.Key, gameByTeam *GameByTeam) error
- func LeagueTeamUri(leagueKey *datastore.Key, teamKey *datastore.Key) string
- func LeagueUri(leagueKey *datastore.Key) string
- func MakeGameId(region string, riotId int64) string
- func MakePlayerId(region string, riotSummonerId int64) string
- func MatchId(matchKey *datastore.Key) string
- func RegionForGameId(id string) string
- func SetPrimarySummoner(c appengine.Context, userKey *datastore.Key, player *Player, ...) error
- func SetRiotApiKey(c appengine.Context, apikey string) error
- func SplitPlayerKey(key *datastore.Key) (string, int64, error)
- func TeamAddPlayer(c appengine.Context, userAcls *RequestorAclCache, league *League, ...) error
- func TeamDelPlayer(c appengine.Context, userAcls *RequestorAclCache, league *League, ...) error
- func VerifySummoner(c appengine.Context, userKey *datastore.Key, playerKey *datastore.Key, ...) error
- type Acl
- type CollectiveGameStats
- func (c *CollectiveGameStats) Add(gameId string, riotSummonerId int64, stats *riot.GameDto)
- func (s *CollectiveGameStats) DebugString() string
- func (s *CollectiveGameStats) FilterToGamesWithPlayersAtLeast(n int)
- func (s *CollectiveGameStats) ForEachGame(fn func(string, *GameStats, int64, *riot.GameDto))
- func (s *CollectiveGameStats) ForEachStat(fn func(string, int64, *riot.GameDto))
- func (c *CollectiveGameStats) Lookup(gameId string, riotSummonerId int64) *riot.GameDto
- func (s *CollectiveGameStats) Size() int
- type DistributedRateLimiter
- type DistributedRateLimiterEntity
- type ErrNotAuthorized
- type ErrRateLimitExceeded
- type ErrorNoRiotApiKey
- type Game
- func GameById(c appengine.Context, gameId string) (*Game, *datastore.Key, error)
- func GetOrCreateGame(c appengine.Context, region string, riotGameId int64) (*Game, *datastore.Key, error)
- func GetPlayerGameStats(c appengine.Context, gameKey *datastore.Key, playerKey *datastore.Key, ...) (*Game, *datastore.Key, error)
- type GameByTeam
- type GameByTime
- type GameInfo
- type GamePlayerInfo
- type GamePlayerStatsInfo
- type GameStats
- type GameTag
- type GameTags
- type GameTeamInfo
- type Group
- type GroupMembership
- type GroupRoot
- type KeysOnlyOption
- type League
- type MatchResult
- type Permission
- type Player
- func GetOrCreatePlayerByRiotId(c appengine.Context, region string, riotId int64) (*Player, *datastore.Key, error)
- func GetOrCreatePlayerBySummoner(c appengine.Context, region string, summoner string) (*Player, *datastore.Key, error)
- func GetPlayerByRiotIdOrStub(c appengine.Context, region string, riotId int64) (*Player, *datastore.Key, error)
- func TeamAllPlayers(c appengine.Context, userAcls *RequestorAclCache, league *League, ...) ([]*Player, []*datastore.Key, error)
- type PlayerCache
- type PlayerGameStats
- type PlayerScoring
- type PlayersBySummoner
- type ProposedGroupMembership
- type RateLimit
- type RequestorAclCache
- func (req *RequestorAclCache) Can(c appengine.Context, perm Permission, resKey *datastore.Key) error
- func (req *RequestorAclCache) FindAll(c appengine.Context, resourceKind string, perm Permission) ([]*datastore.Key, error)
- func (req *RequestorAclCache) PermissionMapFor(c appengine.Context, resKey *datastore.Key) ([]*Group, []*datastore.Key, []map[Permission]bool, error)
- type ResourceAclCache
- type RiotApiKey
- type ScheduledMatch
- type Score
- type SummonerData
- type Team
- func LeagueAddTeam(c appengine.Context, userAcls *RequestorAclCache, leagueId string, ...) (*Team, *datastore.Key, error)
- func LeagueAllTeams(c appengine.Context, userAcls *RequestorAclCache, league *League, ...) ([]*Team, []*datastore.Key, error)
- func TeamById(c appengine.Context, userAcls *RequestorAclCache, league *League, ...) (*Team, *datastore.Key, error)
- type TeamInfo
- type TeamMembership
- type TeamScoring
- type TeamScoringType
- type TokenBucket
- type UnverifiedSummoner
- type User
- type UserGameTag
- type VerifiedSummoner
Constants ¶
const ( PermissionView = iota PermissionEdit )
const ( RegionNA = "na" RegionEUW = "euw" RegionEUNE = "eune" )
Variables ¶
var Regions = []string{ RegionNA, RegionEUW, RegionEUNE, }
var RiotApiRateLimiter = DistributedRateLimiter{ Name: "riot-rest-api", Limits: RiotDevRateLimits, }
var RiotDevRateLimits = []RateLimit{ RateLimit{5, 10}, RateLimit{250, 10 * 60}, }
Functions ¶
func AclFindAll ¶
func AddGameTag ¶
func AddUnverifiedSummoner ¶
func AddUserGameTag ¶
func CreateScheduledMatch ¶
func CreateScheduledMatch( c appengine.Context, userAcls *RequestorAclCache, league *League, leagueKey *datastore.Key, match *ScheduledMatch) error
Creates a scheduled match.
func DecodeKeyShort ¶
func DelGameTag ¶
func DelUserGameTag ¶
func EncodeKeyShort ¶
func EnsureGameExists ¶
func GetGroupsForUser ¶
func GroupAddMember ¶
func GroupAddProposedMember ¶
func GroupByKey ¶
func GroupDelMember ¶
func KeyForGame ¶
func KeyForPlayer ¶
func KeyForPlayerGameStats ¶
func KeyForPlayerGameStatsId ¶
func LeagueAddGameByTeam ¶
func MakeGameId ¶
func MakePlayerId ¶
func RegionForGameId ¶
func SetPrimarySummoner ¶
func TeamAddPlayer ¶
func TeamDelPlayer ¶
Types ¶
type Acl ¶
type Acl struct { // User key or Group key. Requestor *datastore.Key // The key of the protected resource. Resource *datastore.Key // The entity type of the resource key. ResourceKind string Permission Permission }
Ancestor: GroupRootKey
type CollectiveGameStats ¶
type CollectiveGameStats struct {
// contains filtered or unexported fields
}
func (*CollectiveGameStats) Add ¶
func (c *CollectiveGameStats) Add( gameId string, riotSummonerId int64, stats *riot.GameDto)
Adds a player's stats to the collective stats and creates entries with nil stats for players in this game that have not been added to the map yet.
func (*CollectiveGameStats) DebugString ¶
func (s *CollectiveGameStats) DebugString() string
func (*CollectiveGameStats) FilterToGamesWithPlayersAtLeast ¶
func (s *CollectiveGameStats) FilterToGamesWithPlayersAtLeast(n int)
Filters the stats collection to games that have at least n players from the specified list appearing on the same team.
func (*CollectiveGameStats) ForEachGame ¶
Calls the provided function once for each game with a sample player's stat for that game.
func (*CollectiveGameStats) ForEachStat ¶
func (s *CollectiveGameStats) ForEachStat(fn func(string, int64, *riot.GameDto))
Calls the provided function once for each player's stat.
func (*CollectiveGameStats) Lookup ¶
func (c *CollectiveGameStats) Lookup(gameId string, riotSummonerId int64) *riot.GameDto
func (*CollectiveGameStats) Size ¶
func (s *CollectiveGameStats) Size() int
type DistributedRateLimiter ¶
func (*DistributedRateLimiter) Consume ¶
func (r *DistributedRateLimiter) Consume( c appengine.Context, events int) error
Blocks for up to 1 minute.
func (*DistributedRateLimiter) DebugStr ¶
func (r *DistributedRateLimiter) DebugStr(c appengine.Context) string
func (DistributedRateLimiter) Init ¶
func (r DistributedRateLimiter) Init(c appengine.Context) error
Creates a new DistributedRateLimiter that allows events according to the specified limits (or re-initializes the limits of an existing rate limiter with the same name).
func (*DistributedRateLimiter) TryConsume ¶
func (r *DistributedRateLimiter) TryConsume(c appengine.Context, events int) error
Consumes tokens from the rate limiter if nil is returned. Otherwise an error is returned describing why tokens could not be consumed.
type DistributedRateLimiterEntity ¶
type DistributedRateLimiterEntity struct { // Counts of the total number of requests accepted. AcceptCount int64 // Internal buckets. Buckets []TokenBucket }
An opaque type for managing distributed rate limits with the appengine datastore. Use its methods to interact with it.
type ErrNotAuthorized ¶
type ErrNotAuthorized struct { Permission Permission Resource *datastore.Key }
func (ErrNotAuthorized) Error ¶
func (e ErrNotAuthorized) Error() string
type ErrRateLimitExceeded ¶
type ErrRateLimitExceeded struct { RateLimit *DistributedRateLimiter Debug error }
func (ErrRateLimitExceeded) Error ¶
func (e ErrRateLimitExceeded) Error() string
type ErrorNoRiotApiKey ¶
type ErrorNoRiotApiKey struct{}
func (ErrorNoRiotApiKey) Error ¶
func (e ErrorNoRiotApiKey) Error() string
type Game ¶
type Game struct { Region string RiotId int64 // Fields below are populated from riot player stats. HasRiotData bool StartDateTime time.Time MapId int GameMode string GameType string SubType string Players []riot.PlayerDto Invalid bool }
func GetOrCreateGame ¶
func GetPlayerGameStats ¶
func (*Game) FormatGameType ¶
func (*Game) FormatTime ¶
type GameByTeam ¶
type GameByTeam struct { GameKey *datastore.Key TeamKey *datastore.Key DateTime time.Time // Contains {riot.BlueTeamId, riot.PurpleTeamId} if that team contained at least 3 // members of the team. RiotTeamIds []int }
An association between games and teams.
Specifically the games containing at least 3 members of the league-team on the same in-game team.
Ancestor: League
func (*GameByTeam) IsOnBlue ¶
func (g *GameByTeam) IsOnBlue() bool
func (*GameByTeam) IsOnPurple ¶
func (g *GameByTeam) IsOnPurple() bool
type GameByTime ¶
type GameByTime []*Game
func (GameByTime) Len ¶
func (a GameByTime) Len() int
func (GameByTime) Less ¶
func (a GameByTime) Less(i, j int) bool
func (GameByTime) Swap ¶
func (a GameByTime) Swap(i, j int)
type GameInfo ¶
type GameInfo struct { Game *Game // Non-empty when viewed in the context of a league. LeagueId string BlueTeam *GameTeamInfo PurpleTeam *GameTeamInfo // Aliases for BlueTeam/PurpleTeam based on which side has more summoners that are players // of the team someone is inspecting in the application. ThisTeam *GameTeamInfo OtherTeam *GameTeamInfo // contains filtered or unexported fields }
func GetGameInfo ¶
func NewGameInfo ¶
func NewGameInfo() *GameInfo
func TeamRecentGameInfo ¶
func TeamRecentGameInfo( c appengine.Context, userAcls *RequestorAclCache, n int, playerCache *PlayerCache, league *League, leagueKey *datastore.Key, teamKey *datastore.Key) ([]*GameInfo, []error)
Note that sometimes partial results are returned even if there is an error.
func (*GameInfo) AddAppTeamPlayer ¶
When this game was looked up in the context of a team registered with the application, this adds that player to the GameInfo.
func (*GameInfo) AddGamePlayer ¶
func (ginfo *GameInfo) AddGamePlayer( teamId int, p *Player, championId int, pstats *PlayerGameStats)
Adds a player and their in-game-stats to the GameInfo.
type GamePlayerInfo ¶
func NewGamePlayerInfo ¶
func NewGamePlayerInfo(p *Player, championId int) *GamePlayerInfo
type GamePlayerStatsInfo ¶
type GamePlayerStatsInfo struct { Saved bool NotAvailable bool IsOnAppTeam bool Player *Player Stats *PlayerGameStats }
func NewGamePlayerStatsInfo ¶
func NewGamePlayerStatsInfo( player *Player, stats *PlayerGameStats, isOnAppTeam bool) *GamePlayerStatsInfo
type GameStats ¶
type GameStats struct {
// contains filtered or unexported fields
}
func (*GameStats) GetTeamsWithCountAtLeast ¶
func (*GameStats) IncrementTeamCount ¶
type GameTags ¶
An associate between games and tags. A game can have multiple tags.
Ancestor: League
type GameTeamInfo ¶
type GameTeamInfo struct { IsBlueTeam bool IsPurpleTeam bool Players []*GamePlayerInfo PlayerStats []*GamePlayerStatsInfo // stats IsWinner bool ChampionsKilled int NumDeaths int Assists int GoldEarned int }
func NewGameTeamInfo ¶
func NewGameTeamInfo() *GameTeamInfo
type GroupMembership ¶
func GetGroupMemberships ¶
type KeysOnlyOption ¶
type KeysOnlyOption bool
const ( KeysOnly KeysOnlyOption = true KeysAndEntities = false )
type League ¶
type League struct { // The name of the league. Not necessarily unique. Name string // The Riot server region for this league. Defaults to RegionNA. Region string // The datastore key for the User who owns this league. Owner *datastore.Key }
Leagues are identified by their key.
func CreateLeague ¶
func LeagueById ¶
func LeaguesForUser ¶
type MatchResult ¶
type Permission ¶
type Permission int
func AllPermissions ¶
func AllPermissions() []Permission
func (Permission) String ¶
func (p Permission) String() string
type Player ¶
type Player struct { // The current summoner name for this player. Summoner string // This is the region for the given player. Region string // Summoner id as per Riot API. RiotId int64 // This player's in game level. Level int LastUpdated time.Time }
("%s-%s", Region, RiotId) is the key for a player.
func GetPlayerByRiotIdOrStub ¶
func TeamAllPlayers ¶
type PlayerCache ¶
type PlayerCache struct { Region string // contains filtered or unexported fields }
Caches player data within a region.
func NewPlayerCache ¶
func NewPlayerCache(c appengine.Context, region string) *PlayerCache
func (*PlayerCache) Add ¶
func (cache *PlayerCache) Add(p *Player)
func (*PlayerCache) BySummoner ¶
func (cache *PlayerCache) BySummoner(summoner string) (*Player, error)
type PlayerGameStats ¶
type PlayerGameStats struct { GameKey *datastore.Key PlayerKey *datastore.Key // Stats for games that have expired out of recent player history on the Riot side // before we get around to looking for them may be lost forever. This field is set // to true if we know the game stats are no longer available and we don't have a // copy yet. NotAvailable bool // Set to true when we have captured the stats for this player and game already. Saved bool // The raw stats fetched from riot. RiotData riot.RawStatsDto }
The tuple (GameKey, PlayerKey) are unique per entity.
type PlayerScoring ¶
type PlayerScoring interface {
Score(match *ScheduledMatch, player *Player, games []*GameInfo) Score
}
A PlayerScoring is used to take a chronological series of games and compute how many points a player has earned for those results. Results may be negative.
type PlayersBySummoner ¶
type PlayersBySummoner []*Player
sort.Interface for []*Player
func (PlayersBySummoner) Len ¶
func (a PlayersBySummoner) Len() int
func (PlayersBySummoner) Less ¶
func (a PlayersBySummoner) Less(i, j int) bool
func (PlayersBySummoner) Swap ¶
func (a PlayersBySummoner) Swap(i, j int)
type ProposedGroupMembership ¶
type RateLimit ¶
Describes a rate limit that permits MaxEvents in the last IntervalSeconds. Ex: RateLimit{10, 100} would indicate 10 events per 100 seconds.
type RequestorAclCache ¶
type RequestorAclCache struct { UserKey *datastore.Key EncodedUserKey string Groups map[string]*Group GroupKeys map[string]*datastore.Key // contains filtered or unexported fields }
func NewRequestorAclCache ¶
func NewRequestorAclCache(userKey *datastore.Key) *RequestorAclCache
func (*RequestorAclCache) Can ¶
func (req *RequestorAclCache) Can( c appengine.Context, perm Permission, resKey *datastore.Key) error
func (*RequestorAclCache) FindAll ¶
func (req *RequestorAclCache) FindAll( c appengine.Context, resourceKind string, perm Permission) ([]*datastore.Key, error)
func (*RequestorAclCache) PermissionMapFor ¶
func (req *RequestorAclCache) PermissionMapFor( c appengine.Context, resKey *datastore.Key) ([]*Group, []*datastore.Key, []map[Permission]bool, error)
For all the groups this user belongs to, returns a permission map for the given resource.
type ResourceAclCache ¶
type ResourceAclCache struct { ResourceKey *datastore.Key EncodedResourceKey string Permission Permission AuthorizedRequestorKeys map[string]*datastore.Key }
func NewResourceAclCache ¶
func NewResourceAclCache(resourceKey *datastore.Key, perm Permission) *ResourceAclCache
func (*ResourceAclCache) IsAuthorizedRequestor ¶
func (res *ResourceAclCache) IsAuthorizedRequestor(req *datastore.Key) bool
type RiotApiKey ¶
type RiotApiKey struct {
Key string
}
func GetRiotApiKey ¶
func GetRiotApiKey(c appengine.Context) (*RiotApiKey, error)
type ScheduledMatch ¶
type ScheduledMatch struct { // A brief "one-line description" of the match. // Example: "Summoner's Rift Draft (Best of 1)" Summary string // A more detailed description of the match. Description string // The primary tag used to group this with other matches. // Example: "Week 1" PrimaryTag string // The teams involved in the match. TeamKeys []*datastore.Key // The number of games in the match. Zero or less means "no limit". NumGames int // The official suggested date(time) of the match. OfficialDatetime time.Time // The earliest the match should be played. This is not enforced. DateEarliest time.Time // The latest the match should be played. This is not enforced. DateLatest time.Time }
A scheduled match between two teams.
Ancestor: League
func (*ScheduledMatch) AwayTeam ¶
func (m *ScheduledMatch) AwayTeam() *datastore.Key
func (*ScheduledMatch) HomeTeam ¶
func (m *ScheduledMatch) HomeTeam() *datastore.Key
type SummonerData ¶
func GetSummonerDatas ¶
type Team ¶
type Team struct {
Name string
}
Teams are identified by their datastore.Key.
Ancestor: League
func LeagueAddTeam ¶
func LeagueAllTeams ¶
type TeamMembership ¶
A table associating summoners to teams. Summoners may be on more than one team per league. Teams may have any number of summoners.
Ancestor: League
type TeamScoring ¶
type TeamScoring interface {
Score(match *ScheduledMatch, games []*GameInfo) Score
}
A TeamScoring is used to take a chronological series of games and compute how many points a team has earned for those results. Results may be negative.
type TeamScoringType ¶
type TeamScoringType int
A list of supported scoring algorithms for matches.
In the descriptions below, let
M := The number of games in the match (or if the length is unbounded, the number of games played), G := The list of games played, S := The first M games of G, T := The team of interest.
const ( // BestOfSeries // ------------ // Points // 2 points: T wins a majority of games in S // 1 point : T wins exactly M/2 of games in S (if M is even) // 0 points: otherwise // // IsFinal // true : at least M games have been played || T wins or loses a majority of games in S // false: otherwise BestOfSeries TeamScoringType = 0 // ThreeOneZeroSeries // ------------------ // Points // 3 points: T wins a majority of games in S // 1 point : T wins exactly M/2 of games in S (if M is even) // 0 points: otherwise // // IsFinal // true : at least M games have been played // false: otherwise ThreeOneZeroSeries TeamScoringType = 1 )
type TokenBucket ¶
type TokenBucket struct { Limit RateLimit // The number of tokens in the bucket at LastCheckTime. Tokens float64 // Tracks the last time this token bucket was processed so that we can // optimize adding tokens to the bucket each update instead of every // Rate seconds. Time is in UTC. LastCheckTime time.Time }
func (*TokenBucket) AddTokens ¶
func (b *TokenBucket) AddTokens(t time.Time)
func (*TokenBucket) SetLimit ¶
func (b *TokenBucket) SetLimit(limit RateLimit)
If the provided limits are the same as the existing limits this is a no-op. Otherwise the limits are set to the new limits and all tokens are removed from the bucket.
type UnverifiedSummoner ¶
type UnverifiedSummoner struct { User *datastore.Key Player *datastore.Key Token string CreateTime time.Time }
Key: ("%s:%s", User.StringID(), Player.StringID())
type User ¶
func GetUser ¶
Fetches the user from the datastore if it exists, otherwise puts a new user into the datastore and returns it.