/
main.go
144 lines (121 loc) · 4.27 KB
/
main.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
135
136
137
138
139
140
141
142
143
144
package main
import (
"log"
"strconv"
"time"
"godota/matchhistory"
"godota/matchdetails"
"godota/heroes"
"godota/filter"
)
var (
)
func main() {
log.SetFlags(0)
FindPlayerMatches()
//FindCascadeMatches()
//FindGamesTogether()
//ListHeroes()
}
func ListHeroes() {
in := heroes.List()
list := <-in
for _, hero := range list.Heroes {
log.Printf("%v %v", hero.Id, hero.LocalizedName)
}
}
func FindPlayerMatches() {
//var accountId uint64 = 51945535 // Arkanian
//var accountId uint64 = 51971876 // Kevlarman
//var accountId uint64 = 75685110 // Nik
var accountId uint64 = 53071885 // Spen
//var accountId uint64 = 105771979 // Skeleton Burglar
//var accountId uint64 = 114426207 // Polychromatic Hyphen
//var accountId uint64 = 96033201 // Regie
//var accountId uint64 = 101495620 // Loda
//var accountId uint64 = 38359315 // Rag
//var accountId uint64 = 38345312 // Edodes
var totalKills, totalDeaths, totalAssists uint64 = 0, 0, 0
/* This is (your team's total gold) / (enemy team's total gold) */
var totalRomanScore, radiantGoldEarned, direGoldEarned float64 = 0, 0, 0
maxMatches := 100
var matchesFound uint64 = 0
matchStream := matchhistory.ForAccountId(accountId)
var match matchhistory.Match
var iAmRadiant bool = true
for ok, count := true, 0; ok && count < maxMatches; count++ {
matchesFound++
radiantGoldEarned, direGoldEarned = 0, 0
match, ok = <-matchStream
if !ok {
break
}
t := time.Unix(int64(match.StartTime), 0)
log.Printf("Match %v on %v", match.MatchId, t.String())
details := <-matchdetails.ForMatch(match.MatchId)
details = details
for _, player := range details.Result.Players {
if player.AccountId == accountId {
if player.PlayerSlot < 64 {
iAmRadiant = true
} else {
iAmRadiant = false
}
log.Printf("Player %v had %v:%v:%v and is radiant = %v", accountId,
player.Kills, player.Deaths, player.Assists, iAmRadiant)
totalKills += player.Kills
totalDeaths += player.Deaths
totalAssists += player.Assists
}
if player.PlayerSlot < 64 {
radiantGoldEarned += float64(player.GoldPerMin /
60 * details.Result.Duration)
} else {
direGoldEarned += float64(player.GoldPerMin /
60 * details.Result.Duration)
}
}
if direGoldEarned > 0 && radiantGoldEarned > 0 {
if iAmRadiant {
totalRomanScore += radiantGoldEarned / direGoldEarned
} else {
totalRomanScore += direGoldEarned / radiantGoldEarned
}
} else {
log.Println("ONE TEAM EARNED NO GOLD!!")
}
log.Printf("Radiant earned %v. Dire earned %v. " +
"New Roman score total: %.3f", radiantGoldEarned, direGoldEarned,
totalRomanScore);
log.Println("----------------------------------------" +
"-----------------------------------")
}
log.Printf("Looked at the last %v matches for %v", matchesFound, accountId);
if (matchesFound == 0) {
return
}
log.Printf("KDA was %v:%v:%v, which is %.2f",
totalKills, totalDeaths, totalAssists,
float64(totalKills + totalAssists) / float64(totalDeaths))
log.Printf("Roman score is %.3f", (totalRomanScore / float64(matchesFound)))
}
func FindCascadeMatches() {
in := filter.MatchHistoryByLobby(matchhistory.ForAccountId(51945535), 5)
var match matchhistory.Match
for ok := true; ok; {
match, ok = <-in
log.Println("Found Cascade TMM Match: " +
strconv.FormatUint(match.MatchId, 10))
}
}
func FindGamesTogether() {
accountIds := []uint64{96033201, 51971876}
in := filter.ByPlayersInvolved(matchhistory.ForAccountId(51945535),
accountIds)
log.Printf("Looking for matches with players %+v", accountIds)
var match matchhistory.Match
for ok := true; ok; {
match, ok = <-in
log.Printf("Found match: %d", match.MatchId)
}
}