Class: ReplayParser

Inherits:
Object
  • Object
show all
Defined in:
lib/herostats/replay_parser.rb

Constant Summary collapse

PROTOCOL_LOCATION =
'heroprotocol/heroprotocol.py'

Class Method Summary collapse

Class Method Details

.parse(path) ⇒ Object

Returns a Game from a parse .StormReplay file



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
# File 'lib/herostats/replay_parser.rb', line 7

def self.parse(path)
  test = File.dirname(__FILE__) + '/../heroprotocol/heroprotocol.py'


  #return unless File.exist?(path)
  init_data        = Tempfile.new('initdata.json')
  tracker_events  = Tempfile.new('trackerevents.json')
  system "python #{test} --initdata --json \"#{path}\" > #{init_data.path}"
  system "python #{test} --trackerevents --json \"#{path}\" > #{tracker_events.path}"

  game = Game.new
  game = InitDataParser.new(game).parse(init_data)
  game = TrackerEventsParser.new(game).parse(tracker_events)

  previous = 0
  points = []
  #puts game.blue_team.exp_breakdowns.map { |e|  e.total_exp }.join(',')
  game.red_team.exp_breakdowns.each do |b|

    points.push(b.total_exp - previous)
    previous = b.total_exp
  end

  game
end