Skip to content

Commit

Permalink
more data
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed May 28, 2015
1 parent a0d7bcc commit e2a252a
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 96 deletions.
2 changes: 1 addition & 1 deletion Dota_on_Rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gem 'rails', '4.2.1'
gem 'thin'

gem 'omniauth-steam'
gem 'dota', '~> 0.0.18'
gem 'dota', github: 'vinnicc/dota'

gem 'bootstrap-sass'

Expand Down
25 changes: 15 additions & 10 deletions Dota_on_Rails/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
GIT
remote: git://github.com/vinnicc/dota.git
revision: 3022b2b3fb512d013af83da00fa43a68ffa6302c
specs:
dota (0.0.18)
facets (~> 3.0.0)
faraday (~> 0.9.1)
faraday_middleware (~> 0.9.1)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -36,11 +45,11 @@ GEM
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
annotate (2.6.8)
annotate (2.6.10)
activerecord (>= 3.2, <= 4.3)
rake (~> 10.4)
arel (6.0.0)
autoprefixer-rails (5.1.11)
autoprefixer-rails (5.2.0)
execjs
json
better_errors (2.1.1)
Expand All @@ -63,10 +72,6 @@ GEM
coffee-script-source (1.9.1.1)
daemons (1.2.2)
debug_inspector (0.0.2)
dota (0.0.18)
facets (~> 3.0.0)
faraday (~> 0.9.1)
faraday_middleware (~> 0.9.1)
erubis (2.7.0)
eventmachine (1.0.7)
execjs (2.5.2)
Expand All @@ -89,9 +94,9 @@ GEM
mail (2.6.3)
mime-types (>= 1.16, < 3)
method_source (0.8.2)
mime-types (2.5)
mime-types (2.6.1)
mini_portile (0.6.2)
minitest (5.6.1)
minitest (5.7.0)
multi_json (1.11.0)
multipart-post (2.0.0)
nokogiri (1.6.6.2-x86-mingw32)
Expand Down Expand Up @@ -150,7 +155,7 @@ GEM
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
ruby-openid (2.7.0)
sass (3.4.13)
sass (3.4.14)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
Expand Down Expand Up @@ -192,7 +197,7 @@ DEPENDENCIES
binding_of_caller
bootstrap-sass
coffee-rails (~> 4.1.0)
dota (~> 0.0.18)
dota!
jquery-rails
omniauth-steam
pg
Expand Down
2 changes: 1 addition & 1 deletion Dota_on_Rails/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def create
rescue
flash[:error] = "Can't authorize you..."
else
@user.load_matches!(1)
@user.load_matches!(3)
session[:user_id] = @user.id
flash[:success] = "Welcome, #{@user.nickname}!"
end
Expand Down
74 changes: 49 additions & 25 deletions Dota_on_Rails/app/models/match.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,42 +16,66 @@
# match_type :string
#

require './lib/utils'

class Match < ActiveRecord::Base
include Utils
belongs_to :user
has_many :players, dependent: :delete_all

serialize :towers_status
serialize :barracks_status

def load_players!(radiant, dire)
roster = {radiant: radiant, dire: dire}
roster.each_pair do |k, v|
v.players.each do |player|
self.players.create({
uid: player.id,
items: player.items.delete_if {
|item| item.name == "Empty"
}.map {
|item| {id: item.id, name: item.name, image: item.image_url}
},
hero: {id: player.hero.id,
name: player.hero.name,
image: player.hero.image_url(:sb)},
level: player.level,
kills: player.kills,
deaths: player.deaths,
assists: player.assists,
last_hits: player.last_hits,
denies: player.denies,
gold: player.gold,
gpm: player.gpm,
xpm: player.xpm,
status: player.status,
gold_spent: player.gold_spent,
hero_damage: player.hero_damage,
tower_damage: player.tower_damage,
hero_healing: player.hero_healing,
slot: player.slot,
radiant: k == :radiant
uid: player.id,
items: parse_items(player.items),
hero: {id: player.hero.id,
name: player.hero.name,
image: player.hero.image_url(:sb)
},
ability_upgrades: player.ability_upgrades.map {
|ability_upgrade| {id: ability_upgrade.ability.id,
name: ability_upgrade.ability.name,
image: ability_upgrade.ability.image_url(:hp1),
level: ability_upgrade.level,
time: parse_duration(ability_upgrade.time)}
}.sort_by {|ability_upgrade| ability_upgrade[:level]},
additional_units: player.additional_units.map {
|unit| {name: unit.name,
items: parse_items(unit.items)}
},
level: player.level,
kills: player.kills,
deaths: player.deaths,
assists: player.assists,
last_hits: player.last_hits,
denies: player.denies,
gold: player.gold,
gpm: player.gpm,
xpm: player.xpm,
status: player.status,
gold_spent: player.gold_spent,
hero_damage: player.hero_damage,
tower_damage: player.tower_damage,
hero_healing: player.hero_healing,
slot: player.slot,
radiant: k == :radiant
})
end
end
end

private

def parse_items(items)
items.delete_if {
|item| item.name == "Empty"
}.map {
|item| {id: item.id, name: item.name, image: item.image_url}
}
end
end
50 changes: 27 additions & 23 deletions Dota_on_Rails/app/models/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@
#
# Table name: players
#
# id :integer not null, primary key
# match_id :integer
# uid :string
# hero :text
# level :integer
# kills :integer
# deaths :integer
# assists :integer
# last_hits :integer
# denies :integer
# gold :integer
# gpm :integer
# xpm :integer
# status :string
# gold_spent :integer
# hero_damage :integer
# tower_damage :integer
# hero_healing :integer
# items :text
# slot :integer
# radiant :boolean not null
# created_at :datetime not null
# updated_at :datetime not null
# id :integer not null, primary key
# match_id :integer
# uid :string
# hero :text
# level :integer
# kills :integer
# deaths :integer
# assists :integer
# last_hits :integer
# denies :integer
# gold :integer
# gpm :integer
# xpm :integer
# status :string
# gold_spent :integer
# hero_damage :integer
# tower_damage :integer
# hero_healing :integer
# items :text
# slot :integer
# radiant :boolean not null
# created_at :datetime not null
# updated_at :datetime not null
# additional_units :text
# ability_upgrades :text
#

class Player < ActiveRecord::Base
belongs_to :match

serialize :hero
serialize :items
serialize :additional_units
serialize :ability_upgrades

def abandoned_or_not_connected?
status != 'played'
Expand Down
31 changes: 18 additions & 13 deletions Dota_on_Rails/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
# updated_at :datetime not null
#

require './lib/utils'

class User < ActiveRecord::Base
include Utils
has_many :matches

class << self
Expand Down Expand Up @@ -55,7 +58,17 @@ def load_matches!(count)
mode: match_info.mode,
cluster: match_info.cluster,
duration: parse_duration(match_info.duration),
match_type: match_info.type
match_type: match_info.type,
likes: match_info.positive_votes,
dislikes: match_info.negative_votes,
towers_status: {
radiant: parse_buildings(match_info.radiant.tower_status),
dire: parse_buildings(match_info.dire.tower_status)
},
barracks_status: {
radiant: parse_buildings(match_info.radiant.barracks_status),
dire: parse_buildings(match_info.dire.barracks_status)
}
})
new_match.load_players!(match_info.radiant, match_info.dire)
end
Expand All @@ -65,19 +78,11 @@ def load_matches!(count)

private

def parse_duration(d)
hr = (d / 3600).floor
min = ((d - (hr * 3600)) / 60).floor
sec = (d - (hr * 3600) - (min * 60)).floor

hr = '0' + hr.to_s if hr.to_i < 10
min = '0' + min.to_s if min.to_i < 10
sec = '0' + sec.to_s if sec.to_i < 10

hr.to_s + ':' + min.to_s + ':' + sec.to_s
end

def find_self_in(match)
match.players.find_by(uid: uid)
end

def parse_buildings(arr)
arr.keep_if {|k, v| v }.keys
end
end
6 changes: 3 additions & 3 deletions Dota_on_Rails/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<body>

<nav class="navbar navbar-inverse">
<div class="container">
<div class="container-fluid">
<div class="navbar-header">
<%= link_to 'Doter', root_path, class: 'navbar-brand' %>
</div>
Expand All @@ -29,7 +29,7 @@
</div>
</nav>

<div class="container">
<div class="container-fluid">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>">
<%= value %>
Expand All @@ -42,7 +42,7 @@
</div>

<div id="footer">
<div class="container">
<div class="container-fluid">
<p class="text-muted">Created by <a href="http://radiant-wind.com" target="_blank">Radiant Wind</a></p>
</div>
</div>
Expand Down
Loading

0 comments on commit e2a252a

Please sign in to comment.