structs

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2017 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxIDListSize = 100000
	BloomGrowBy   = 2     // double in size on each grow()
	BloomFpRate   = 0.001 // Increasing means more duplicate requests, decreasing means bloom filter consumes more memory.
)
View Source
const (
	SnapshotSuffix = "-snapshot"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIMatch

type APIMatch struct {
	GameID       RiotID `json:"gameId"`
	SeasonID     int    `json:"seasonId"`
	GameCreation int64  `json:"gameCreation"`
	GameDuration int    `json:"gameDuration"`

	Participants []struct {
		TeamID     int          `json:"teamId"`
		ChampionID RiotID       `json:"championId"`
		Masteries  []rawMastery `json:"masteries"`
		Runes      []rawRune    `json:"runes"`

		Stats struct {
			Win   bool `json:"win"`
			Item0 int32
			Item1 int32
			Item2 int32
			Item3 int32
			Item4 int32
			Item5 int32
			Item6 int32

			Kills                           int32
			Deaths                          int32
			Assists                         int32
			LargestKillingSpree             int32
			LargestMultiKill                int32
			KillingSprees                   int32
			LongestTimeSpentLiving          int32
			DoubleKills                     int32
			TripleKills                     int32
			QuadraKills                     int32
			PentaKills                      int32
			UnrealKills                     int32
			TotalDamageDealt                int32
			MagicDamageDealt                int32
			PhysicalDamageDealt             int32
			TrueDamageDealt                 int32
			LargestCriticalStrike           int32
			TotalDamageDealtToChampions     int32
			MagicDamageDealtToChampions     int32
			PhysicalDamageDealtToChampions  int32
			TrueDamageDealtToChampions      int32
			TotalHeal                       int32
			TotalUnitsHealed                int32
			DamageSelfMitigated             int32
			DamageDealtToObjectives         int32
			DamageDealtToTurrets            int32
			VisionScore                     int32
			TimeCCingOthers                 int32
			TotalDamageTaken                int32
			MagicalDamageTaken              int32
			PhysicalDamageTaken             int32
			TrueDamageTaken                 int32
			GoldEarned                      int32
			GoldSpent                       int32
			TurretKills                     int32
			InhibitorKills                  int32
			TotalMinionsKilled              int32
			NeutralMinionsKilled            int32
			NeutralMinionsKilledTeamJungle  int32
			NeutralMinionsKilledEnemyJungle int32
			TotalTimeCrowdControlDealt      int32
			ChampLevel                      int32
			VisionWardsBoughtInGame         int32
			SightWardsBoughtInGame          int32
			WardsPlaced                     int32
			WardsKilled                     int32
			FirstBloodKill                  bool
			FirstBloodAssist                bool
			FirstTowerKill                  bool
			FirstTowerAssist                bool
			FirstInhibitorKill              bool
			FirstInhibitorAssist            bool
			CombatPlayerScore               int32
			ObjectivePlayerScore            int32
			TotalPlayerScore                int32
			TotalScoreRank                  int32
		} `json:"stats"`
	}

	ParticipantIdentities []struct {
		Player struct {
			AccountID    RiotID `json:"accountId"`
			SummonerName string `json:"summonerName"`
			SummonerID   RiotID `json:"summonerId"`
			ProfileIcon  int    `json:"profileIcon"`
		} `json:"player"`
	}

	Teams []struct {
		Bans []struct {
			ChampionID RiotID `json:"championId"`
		} `json:"bans"`
	}

	GameMode string `json:"gameMode"`
	MapID    int    `json:"mapId"`
	GameType string `json:"gameType"`
}

APIMatch : Raw data returned from Riot's API. Converted to Match using ToMatch() function.

type ChampPack

type ChampPack struct {
	MaxID   RiotID
	MaxSize int
	// contains filtered or unexported fields
}

ChampPack : Low-level mapping struct used to convert between sparse RiotID's and dense packedChampID's. This struct keeps a direct mapping in memory and can convert between the two in a single array lookup, which provides roughly a 5.2x speedup in go1.7.1 (see packedarray_test.go benchmarks for experiment).

func NewChampPack

func NewChampPack(count int, maxID RiotID) *ChampPack

NewChampPack : Return a new ChampPack instance with a max (packed) size of `count` and a maximum ID value of `maxID`. For example, NewChampPack(5, 10) means there will be at most five mappings added, with the max RiotID being 10.

func (*ChampPack) AddRiotID

func (cp *ChampPack) AddRiotID(id RiotID) packedChampID

AddRiotID : Add a new Riot ID to the mapping. Returns the corresponding packedChampID.

func (*ChampPack) GetPacked

func (cp *ChampPack) GetPacked(id RiotID) (packedChampID, bool)

GetPacked : Get a packedChampID for a previously-added RiotID. The boolean return value indicates whether the specified RiotID is known, and if not then the first value should not be trusted.

func (*ChampPack) GetUnpacked

func (cp *ChampPack) GetUnpacked(id packedChampID) (RiotID, bool)

GetUnpacked : Get previously-added RiotID corresponding to a packedChampID. The boolean return value indicates whether the specified RiotID is known, and if not then the first value should not be trusted.

func (*ChampPack) PackedSize

func (cp *ChampPack) PackedSize() int

PackedSize : Returns the current number of champions packed in.

type IDList

type IDList struct {
	Queue chan RiotID
	// contains filtered or unexported fields
}

IDList : A queue-like data structure that only allows items to be added once; if an item has already been added then attempts to re-add it will be rejected. IDLists are safe to use concurrently.

func NewIDList

func NewIDList() *IDList

NewIDList : Create an empty IDList.

func (*IDList) Add

func (ml *IDList) Add(m RiotID) bool

Add : Add a new item to the list if it hasn't been added before. Items are added in order and cannot be added to the same list twice. Note that `IDList` uses a bloom filter to track which elements have been added and some false positives occur, meaning that some items will be incorrectly blocked.

func (*IDList) Available

func (ml *IDList) Available() bool

Available : Returns true if there are any items in the list.

func (*IDList) Blacklist

func (ml *IDList) Blacklist(m RiotID)

Blacklist : Add a new item to the blacklist. This is automatically called by Add() and shouldn't be called externally unless you want to blacklist *without* adding to the list.

func (*IDList) Blacklisted added in v0.1.2

func (ml *IDList) Blacklisted(m RiotID) bool

Blacklisted : Returns a boolean indicating whether the specified ID exists in the list. Note that `IDList` uses a bloom filter to track which elements have been added so some false positives will occur.

func (*IDList) Filled

func (ml *IDList) Filled() float32

Filled : Returns the percentage of the list capacity that's filled

func (*IDList) Next

func (ml *IDList) Next() (RiotID, bool)

Next : Get the next item from the list if anything is available. The second return value will be true whenever an actual value is returned and false otherwise.

func (*IDList) Shuffle

func (ml *IDList) Shuffle()

Shuffle : Randomly distributes all items currently in the queue. Note that this only applies to items *currently in the queue* and will not affect insertion order for new items.

type Match

type Match struct {
	GameID       RiotID `json:"gameId"`
	SeasonID     int    `json:"seasonId"`
	GameCreation int64  `json:"gameCreation"`
	GameDuration int    `json:"gameDuration"`

	Participants []Participant
	Bans         []RiotID

	GameMode string `json:"gameMode"`
	MapID    int    `json:"mapId"`
	GameType string `json:"gameType"`
	// contains filtered or unexported fields
}

Match : Primary structure used to store match information. Generated from APIMatch's using ToMatch(), and can be encoded into a compact binary format for storage using Match.Bytes().

This struct stores all information related to an individual match, including summoner stats if Config.KeepStats is enabled.

func MakeMatch

func MakeMatch(buf []byte) *Match

MakeMatch : Convert an encoded byte array back into a match. This is the inverse of Match.Bytes().

func ToMatch

func ToMatch(raw APIMatch) Match

ToMatch : Convert raw API data to a Match object

func (*Match) Banned

func (m *Match) Banned(id RiotID) bool

func (Match) Bytes

func (m Match) Bytes() []byte

Bytes : Output as protocol buffer-encoded byte array.

func (*Match) Pack

func (m *Match) Pack(packer *ChampPack)

Pack : Improve lookup rates for bans, picks, and wins.

func (*Match) Picked

func (m *Match) Picked(id RiotID) bool

Picked : Returns a boolean indicating whether the specified champion played in this game.

func (*Match) When

func (m *Match) When() time.Time

func (*Match) Won

func (m *Match) Won(id RiotID) bool

Won : Returns a boolean indicating whether the specified champion won the game.

type MatchStore

type MatchStore struct {
	// contains filtered or unexported fields
}

MatchStore : Represents a persistent data store for match data. Implements a thin layer over a LevelDB instance and is capable of reading and writing match data to the database. All writes are serialized and its therefore safe to call `Add()` from multiple goroutines.

func NewMatchStore

func NewMatchStore(filename string) *MatchStore

NewMatchStore : Create a new MatchStore that automatically records data and sync it to a snapshot instance.

func (*MatchStore) Add

func (ms *MatchStore) Add(m Match)

Add : Queue up a new match to be written asynchronously.

func (*MatchStore) Close

func (ms *MatchStore) Close()

Close : Clean up all related resources. No reads or writes are allowed after this function is called.

func (*MatchStore) Count

func (ms *MatchStore) Count() int

Count : Returns the total number of records written to disk. Inaccurate unless Each() has been called at least once.

func (*MatchStore) Each

func (ms *MatchStore) Each(fn func(*Match))

Each : Extract matches one by one.

type MatchSummary

type MatchSummary struct {
	GameID    RiotID
	Timestamp int64
}

MatchSummary : summary information about matches from the API

type Pacer

type Pacer struct {
	// contains filtered or unexported fields
}

Pacer : Runs a function at a specified rate. In matchgrab this is being used for making API requests to Riot but I think its written generically enough that it could be repurposed for something else as well.

When a new pacer is created, a goroutine pool is also launched that monitor the input queue of functions to be executed (added w/ Each() function call). When executing functions from the queue, it will execute up to `maxSimultaneousRequests` functions simultaneously; if you want to avoid this simply set the value to 1 at initialization.

You can also pause execution for any period using the PauseFor() function.

func NewPacer

func NewPacer(rpm int, sim int) *Pacer

func (*Pacer) Close

func (p *Pacer) Close()

func (*Pacer) PauseFor

func (p *Pacer) PauseFor(d time.Duration)

PauseFor : Pauses the pacer and will not start any new executions until the specified duration passes.

func (*Pacer) Run

func (p *Pacer) Run(fn func(), count int)

Each : Runs the specific function as quickly as allowed w/ pacing rules. A pacer starts each run on a separate goroutine (up to maxSimultaneousRequests at a time) so its likely that multiple instances will be running at once if that's > 1.

If count is zero, runs indefinitely.

type PackedChampBooleanArray

type PackedChampBooleanArray struct {
	// contains filtered or unexported fields
}

func NewPackedChampBooleanArray

func NewPackedChampBooleanArray(packer *ChampPack) *PackedChampBooleanArray

func (*PackedChampBooleanArray) Each

func (pcba *PackedChampBooleanArray) Each(fn func(id RiotID, val bool))

func (*PackedChampBooleanArray) Get

func (pcba *PackedChampBooleanArray) Get(id RiotID) (bool, bool)

Get : Returns the boolean value at the specified index, as well as a second boolean indicating whether the value exists. If the second value is false then the first should not be trusted.

func (*PackedChampBooleanArray) Set

func (pcba *PackedChampBooleanArray) Set(id RiotID, val bool) error

type Participant

type Participant struct {
	SummonerName string `json:"summonerName"`
	AccountID    RiotID `json:"accountId"`
	ProfileIcon  int    `json:"profileIcon"`
	SummonerID   RiotID `json:"summonerId"`
	ChampionID   RiotID `json:"championId"`
	TeamID       int    `json:"teamId"`

	Winner bool `json:"winner"`

	Masteries []int32
	Runes     []int32
	Items     []int32

	Stats *ParticipantStats
}

Participant : Stores information about individual players, including stats if requested.

type ParticipantStats added in v0.2.0

type ParticipantStats struct {
	Kills                           int32
	Deaths                          int32
	Assists                         int32
	LargestKillingSpree             int32
	LargestMultiKill                int32
	KillingSprees                   int32
	LongestTimeSpentLiving          int32
	DoubleKills                     int32
	TripleKills                     int32
	QuadraKills                     int32
	PentaKills                      int32
	UnrealKills                     int32
	TotalDamageDealt                int32
	MagicDamageDealt                int32
	PhysicalDamageDealt             int32
	TrueDamageDealt                 int32
	LargestCriticalStrike           int32
	TotalDamageDealtToChampions     int32
	MagicDamageDealtToChampions     int32
	PhysicalDamageDealtToChampions  int32
	TrueDamageDealtToChampions      int32
	TotalHeal                       int32
	TotalUnitsHealed                int32
	DamageSelfMitigated             int32
	DamageDealtToObjectives         int32
	DamageDealtToTurrets            int32
	VisionScore                     int32
	TimeCCingOthers                 int32
	TotalDamageTaken                int32
	MagicalDamageTaken              int32
	PhysicalDamageTaken             int32
	TrueDamageTaken                 int32
	GoldEarned                      int32
	GoldSpent                       int32
	TurretKills                     int32
	InhibitorKills                  int32
	TotalMinionsKilled              int32
	NeutralMinionsKilled            int32
	NeutralMinionsKilledTeamJungle  int32
	NeutralMinionsKilledEnemyJungle int32
	TotalTimeCrowdControlDealt      int32
	ChampLevel                      int32
	VisionWardsBoughtInGame         int32
	SightWardsBoughtInGame          int32
	WardsPlaced                     int32
	WardsKilled                     int32
	FirstBloodKill                  bool
	FirstBloodAssist                bool
	FirstTowerKill                  bool
	FirstTowerAssist                bool
	FirstInhibitorKill              bool
	FirstInhibitorAssist            bool
	CombatPlayerScore               int32
	ObjectivePlayerScore            int32
	TotalPlayerScore                int32
	TotalScoreRank                  int32
}

type RiotID

type RiotID int64

RiotID : Canonical identifier for everything that comes from Riot, including summoner ID's, champion ID's, and account ID's.

func (RiotID) Bytes

func (r RiotID) Bytes() []byte

Bytes : Encode RiotID as bytes.

Jump to

Keyboard shortcuts

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