Class: HoN::PlayerStats
- Inherits:
-
Stats
- Object
- Stats
- HoN::PlayerStats
show all
- Defined in:
- lib/honclient/player_stats.rb
Constant Summary
collapse
- MAPPINGS =
{
:psr => "acc_pub_skill",
:kills => "acc_herokills",
:assists => "acc_heroassists",
:deaths => "acc_deaths",
:games => "acc_games_played"
}
Instance Attribute Summary
Attributes inherited from Stats
#stats
Instance Method Summary
collapse
Methods inherited from Stats
#dump_xml_stats, #error, #error?, #method_missing, #nickname, #stat
Constructor Details
#initialize(nickname) ⇒ PlayerStats
Returns a new instance of PlayerStats.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/honclient/player_stats.rb', line 11
def initialize(nickname)
@nickname = nickname
@stats = {}
begin
url = "http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]=#{@nickname}"
xml_data = Net::HTTP.get_response(URI.parse(url)).body
data = Nokogiri::XML.parse(xml_data)
data.xpath("//xmlRequest/stats/player_stats/stat").each do |stat|
@stats[stat["name"]] = stat.content
end
rescue SocketError
@error = "Could not contact the Newerth XML API."
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class HoN::Stats
Instance Method Details
#assists_per_game ⇒ Object
61
62
63
|
# File 'lib/honclient/player_stats.rb', line 61
def assists_per_game
(assists.to_f / games.to_f * 100).round / 100.0
end
|
#kdr ⇒ Object
26
27
28
29
30
|
# File 'lib/honclient/player_stats.rb', line 26
def kdr
(acc_herokills / acc_deaths).round(2)
rescue ZeroDivisionError
0
end
|
#mmr ⇒ Object
38
39
40
|
# File 'lib/honclient/player_stats.rb', line 38
def mmr
rnk_amm_team_rating.to_f.round
end
|
#ranked_kdr ⇒ Object
32
33
34
35
36
|
# File 'lib/honclient/player_stats.rb', line 32
def ranked_kdr
(rnk_herokills / rnk_deaths).round(2)
rescue ZeroDivisionError
0
end
|
#tsr ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/honclient/player_stats.rb', line 42
def tsr
puts (rnk_herokills / rnk_deaths / 1.1 / 1.15) * 0.65
tsr_value = ((rnk_herokills/rnk_deaths/1.1/1.15)*0.65)+
((rnk_heroassists/rnk_deaths/1.55)*1.20)+
(((rnk_wins/(rnk_wins+rnk_losses))/0.55)*0.9)+
(((rnk_gold/rnk_secs*60)/230) * (1-((230/195)*((rnk_em_played/rnk_games_played))))*0.35)+
((((rnk_exp/rnk_time_earning_exp*60)/380)*(1-((380/565)*(rnk_em_played/rnk_games_played))))*0.40)+
(( ((((rnk_denies/rnk_games_played)/12)*(1-((4.5/8.5)*(rnk_em_played/rnk_games_played))))*0.70)+
((((rnk_teamcreepkills/rnk_games_played)/93)*(1-((63/81)*(rnk_em_played/rnk_games_played))))*0.50)+
((rnk_wards/rnk_games_played)/1.45*0.30))*(37.5/(rnk_secs/rnk_games_played/60)))
if tsr_value > 10
10
elsif tsr_value < 0
0
else
tsr_value
end.round(2)
end
|