forked from TrevorSStone/goriot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstats.go
134 lines (124 loc) · 5.89 KB
/
stats.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package goriot
import (
"fmt"
)
type playerStatsSummaryList struct {
PlayerStatSummaries []PlayerStatsSummary `json:"playerStatSummaries"`
SummonerID int64 `json:"summonerId"`
}
//PlayerStatsSummary represents a summary of a League of Legends player's game stats
type PlayerStatsSummary struct {
AggregatedStats AggregatedStats `json:"aggregatedStats"`
Losses int `json:"losses"`
ModifyDate int64 `json:"modifyDate"`
PlayerStatSummaryType string `json:"playerStatSummaryType"`
Wins int `json:"wins"`
}
//AggregatedStats contain all values for a player's game stat values
type AggregatedStats struct {
AverageAssists int `json:"averageAssists"`
AverageChampionsKilled int `json:"averageChampionsKilled"`
AverageCombatPlayerScore int `json:"averageCombatPlayerScore"`
AverageNodeCapture int `json:"averageNodeCapture"`
AverageNodeCaptureAssist int `json:"averageNodeCaptureAssist"`
AverageNodeNeutralize int `json:"averageNodeNeutralize"`
AverageNodeNeutralizeAssist int `json:"averageNodeNeutralizeAssist"`
AverageNumDeaths int `json:"averageNumDeaths"`
AverageObjectivePlayerScore int `json:"averageObjectivePlayerScore"`
AverageTeamObjective int `json:"averageTeamObjective"`
AverageTotalPlayerScore int `json:"averageTotalPlayerScore"`
BotGamesPlayed int `json:"botGamesPlayed"`
KillingSpree int `json:"killingSpree"`
MaxAssists int `json:"maxAssists"`
MaxChampionsKilled int `json:"maxChampionsKilled"`
MaxCombatPlayerScore int `json:"maxCombatPlayerScore"`
MaxLargestCriticalStrike int `json:"maxLargestCriticalStrike"`
MaxLargestKillingSpree int `json:"maxLargestKillingSpree"`
MaxNodeCapture int `json:"maxNodeCapture"`
MaxNodeCaptureAssist int `json:"maxNodeCaptureAssist"`
MaxNodeNeutralize int `json:"maxNodeNeutralize"`
MaxNodeNeutralizeAssist int `json:"maxNodeNeutralizeAssist"`
MaxObjectivePlayerScore int `json:"maxObjectivePlayerScore"`
MaxTeamObjective int `json:"maxTeamObjective"`
MaxTimePlayed int `json:"maxTimePlayed"`
MaxTimeSpentLiving int `json:"maxTimeSpentLiving"`
MaxTotalPlayerScore int `json:"maxTotalPlayerScore"`
MostChampionKillsPerSession int `json:"mostChampionKillsPerSession"`
MostSpellsCast int `json:"mostSpellsCast"`
NormalGamesPlayed int `json:"normalGamesPlayed"`
RankedPremadeGamesPlayed int `json:"rankedPremadeGamesPlayed"`
RankedSoloGamesPlayed int `json:"rankedSoloGamesPlayed"`
TotalAssists int `json:"totalAssists"`
TotalChampionKills int `json:"totalChampionKills"`
TotalDamageDealt int `json:"totalDamageDealt"`
TotalDamageTaken int `json:"totalDamageTaken"`
TotalDeathsPerSession int `json:"totalDeathsPerSession"`
TotalDoubleKills int `json:"totalDoubleKills"`
TotalFirstBlood int `json:"totalFirstBlood"`
TotalGoldEarned int `json:"totalGoldEarned"`
TotalHeal int `json:"totalHeal"`
TotalMagicDamageDealt int `json:"totalMagicDamageDealt"`
TotalMinionKills int `json:"totalMinionKills"`
TotalNeutralMinionsKilled int `json:"totalNeutralMinionsKilled"`
TotalNodeCapture int `json:"totalNodeCapture"`
TotalNodeNeutralize int `json:"totalNodeNeutralize"`
TotalPentaKills int `json:"totalPentaKills"`
TotalPhysicalDamageDealt int `json:"totalPhysicalDamageDealt"`
TotalQuadraKills int `json:"totalQuadraKills"`
TotalSessionsLost int `json:"totalSessionsLost"`
TotalSessionsPlayed int `json:"totalSessionsPlayed"`
TotalSessionsWon int `json:"totalSessionsWon"`
TotalTripleKills int `json:"totalTripleKills"`
TotalTurretsKilled int `json:"totalTurretsKilled"`
TotalUnrealKills int `json:"totalUnrealKills"`
}
//RankedStats represents a League of Legends player's statistics for ranked play
type RankedStats struct {
Champions []ChampionStats `json:"champions"`
ModifyDate int64 `json:"modifyDate"`
SummonerID int64 `json:"summonerId"`
}
//ChampionStats are the stats for a League of Legends player's champion in ranked
type ChampionStats struct {
ID int `json:"id"`
Stats AggregatedStats `json:"stats"`
}
//StatSummariesBySummoner retrieves the statistics of the supplied summonerID from Riot Games API.
//It returns an array of PlayerStatsSummary and any errors that occured from the server
//The global API key must be set before use
func StatSummariesBySummoner(region string, summonerID int64, season string) (stats []PlayerStatsSummary, err error) {
var list playerStatsSummaryList
if !IsKeySet() {
return stats, ErrAPIKeyNotSet
}
var args string
if season != "" {
args = fmt.Sprintf("season=%s&", season)
}
args += "api_key=" + apikey
url := fmt.Sprintf("https://%v.%v/lol/%v/v1.3/stats/by-summoner/%d/summary?%v", region, BaseAPIURL, region, summonerID, args)
err = requestAndUnmarshal(url, &list)
if err != nil {
return
}
return list.PlayerStatSummaries, err
}
//RankedStatsBySummoner retrieves the ranked statistics of the supplied summonerID from Riot Games API.
//It returns a RankedStats and any errors that occured from the server
//The global API key must be set before use
func RankedStatsBySummoner(region string, summonerID int64, season string) (stats RankedStats, err error) {
if !IsKeySet() {
return stats, ErrAPIKeyNotSet
}
var args string
if season != "" {
args = fmt.Sprintf("season=%s&", season)
}
args += "api_key=" + apikey
url := fmt.Sprintf("https://%v.%v/lol/%v/v1.3/stats/by-summoner/%d/ranked?%v", region, BaseAPIURL, region, summonerID, args)
err = requestAndUnmarshal(url, &stats)
if err != nil {
return
}
return
}