structs

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIDListSize = 100000

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"`
		Stats      struct {
			Win bool `json:"win"`
		} `json:"stats"`
	} `json:"participants"`

	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
}

func NewIDList

func NewIDList() *IDList

func (*IDList) Add

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

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)

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)

func (*IDList) Shuffle

func (ml *IDList) Shuffle()

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
}

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)

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"`
}

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

Jump to

Keyboard shortcuts

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