-
Notifications
You must be signed in to change notification settings - Fork 2
/
router_funny.go
109 lines (92 loc) · 2.56 KB
/
router_funny.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
package main
import (
"github.com/TrevorSStone/goriot"
"github.com/go-martini/martini"
"github.com/lab-D8/lol-at-pitt/ols"
"github.com/martini-contrib/render"
)
var fuck int = 310001
var championMap map[int]string
type PlayerStats struct {
Division string
Team string
Summoner string
TotalKills int
TotalDeaths int
TotalAssists int
TotalGold int
GamesPlayed int
KillsPerGame float32
DeathsPerGame float32
AssistsPerGame float32
KDA float32
}
type MatchPlayer struct {
Champion string
Ign string
}
type MatchDisplay struct {
Blue []MatchPlayer
Red []MatchPlayer
}
var stats []PlayerStats
func initFunnyRouter(m *martini.ClassicMartini) {
stats := initStats()
m.Get("/player/stats", func(renderer render.Render) {
renderer.JSON(200, stats)
})
m.Get("/stats", func(renderer render.Render) {
renderer.HTML(200, "stats", stats)
})
}
func initStats() []PlayerStats {
pStats := []PlayerStats{}
for _, team := range ols.GetTeamsDAO().All() {
matches := ols.GetMatchesDAO().LoadTeamMatches(team.Name)
for _, playerId := range team.Players {
pStat := PlayerStats{}
player := ols.GetPlayersDAO().Load(playerId)
pStat.Summoner = player.Ign
pStat.Team = team.Name
pStat.Division = team.League
for _, match := range matches {
leagueMatch := ols.GetMatchesDAO().LoadLeagueGame(match.Id)
index := getParticipantIndex(leagueMatch, *match, player.Id)
if index == -1 {
continue
}
pleague := leagueMatch.Participants[index].Stats
pStat.AssistsPerGame += float32(pleague.Assists)
pStat.DeathsPerGame += float32(pleague.Deaths)
pStat.GamesPlayed += 1
pStat.KillsPerGame += float32(pleague.Kills)
pStat.TotalAssists += int(pleague.Assists)
pStat.TotalDeaths += int(pleague.Deaths)
pStat.TotalGold += int(pleague.GoldEarned)
pStat.TotalKills += int(pleague.Kills)
}
if pStat.GamesPlayed > 0 {
pStat.AssistsPerGame /= float32(pStat.GamesPlayed)
pStat.DeathsPerGame /= float32(pStat.GamesPlayed)
pStat.KillsPerGame /= float32(pStat.GamesPlayed)
pStat.KDA = float32(pStat.TotalAssists+pStat.TotalKills) / float32(pStat.TotalDeaths)
}
pStats = append(pStats, pStat)
}
}
return pStats
}
func getParticipantIndex(match goriot.MatchDetail, olsMatch ols.Match, id int64) int {
pId := 0
for _, participant := range olsMatch.Participants {
if participant.Id == id {
pId = participant.ParticipantId
}
}
for i, participant := range match.Participants {
if participant.ParticipantID == pId {
return i
}
}
return -1
}