Giter Club home page Giter Club logo

hots-parser's Introduction

hots-parser

A fast Heroes of the Storm's replay files parser written in Python.

How to run it:

There are two ways to run hots-parser:

  1. Standalone: where the stats are save to different files, based on the flags you use.

  2. Database: where the stats are inserted into a database. This is the default mode where you don't provide any flag or parameter besides the path to the replay file

usage: main.py [-h] [-o OUTPUT_DIR] [-r] [-t] [-l] [-u] [-p] [-a] replay_path

positional arguments:
  replay_path           Path to the .StormReplay file to process

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT_DIR, --output-dir OUTPUT_DIR
                        Path to the output directory
  -r, --dump-heroes     Indicates you want to dump hero data
  -t, --dump-teams      Indicates you want to dump teams data
  -l, --dump-timeline   Indicates you want to dump timeline data
  -u, --dump-units      Indicates you want to dump units data
  -p, --dump-players    Indicates you want to dump player data
  -a, --dump-all        Shortcut for --dump-heroes --dump-teams --dump-units
                        --dump-players --dump-timeline

Configuration

This parser tries to run as fast as possible, in order to do that we use PyPy which perform better than the default interpreter, so the first thing you need to do is to install PyPy. Please note that the default interpreter will still work, but a lot slower (about 1 second per replay on a mac with [email protected] with 16GB of RAM)

Loading submodules

The parser relies on Blizzard's heroprotocol project, which is included as a submodule in this repo, in order to pull the data for heroprotocol you need to run this command after cloning the repo:

git submodule init
git submodule update

alternativelly, you can clone hots-parser recursively:

git clone --recursive [email protected]:crorella/hots-parser.git

Loading the database schema

You will need a PostgreSQL server running at least the version 9.5, because we make extensive use of the JSONB datatype to store the metrics we extract from the replay.

  • Create a database with the name "hotsdata"
  • Create a user with the name "hotsdata" and grant ALL to the hotsdata database.
CREATE DATABASE hotsdata;
CREATE ROLE hotsdata WITH LOGIN PASSWORD 'hotsdata';
REVOKE CONNECT ON DATABASE hotsdata FROM PUBLIC;
GRANT ALL ON DATABASE hotsdata TO hotsdata;
  • Update credentials.json with the appropriate password and server information.
  • Load the script in database/database_schema.sql into hotsdata. Please note this schema also contains the tables used by the API, data processing (ETL) and frontend that power www.hotsdata.com

Installing python libraries

For now we just use jsonpickle and psycopg2ct. You can use pip to install them.

pip install jsonpickle

pip install psycopg2ct

Testing all

To test if everything is working fine run the following command in the root folder of this project:

pypy main.py Hanamura.HotsReplay

You should see something like this in the console:

Processing: Hanamura.StormReplay
saving 18c0a432362fca4bb38ccf950ede92d562bb3a5b9e72a93beb4ce196c322650d to db

If you query the database you should see data in the following tables:

  • replayinfo: This is the main table where general information about the replay is stored. Every table has a replayid as a foreign key to this table.
  • players: stores the players present in the replay, you should see 10 entries here, one per player.
  • teams: teams present in the replay, you should see 2 entries here.
  • teamstats: this table store generic team metrics which are common across all maps. You should see 2 entries here, one per team.
  • teammapstats: this table store map specific metrics at a team level. You should see 2 entries here, one per team.
  • generalstats: this table store generic player stats which are common across all maps. You should see 10 entries here, one per player.
  • mapstats: this table store map specific metrics for each player. You should see 10 entries here, one per player.
  • battletag_toonhandle_lookup: this table creates a mapping between the battletags and the toonhandles of every player, you should see 10 entries here, one per player.

The others tables are mostly used by the processes that aggregate data and calculate more advanced metrics. This project is still not Open Source, but we are working on cleaning the code to release it in the next couple of days.

hots-parser's People

Contributors

camdavidsonpilon avatar crorella avatar joe-eklund avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hots-parser's Issues

Not python 3 compatible.

I've run into a Python 2 dependency while trying pip3 install -r requirements.txt inside a Python 3 virtual environment.

(hots-parser3) joe@mirkwood:~/projects/github/hots-parser$ pip3 install -r requirements.txt 
Collecting jsonpickle (from -r requirements.txt (line 1))
  Using cached jsonpickle-0.9.5.tar.gz
Collecting psycopg2ct (from -r requirements.txt (line 2))
  Using cached psycopg2ct-2.4.4.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-_58ga757/psycopg2ct/setup.py", line 206
        print '=' * 80
                ^
    SyntaxError: Missing parentheses in call to 'print'
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-_58ga757/psycopg2ct/

Upon further investigation, I see that according to https://pypi.python.org/pypi/psycopg2ct, this package is only tested on Python 2.6+.

I would recommend either removing this package and switching to something Python 3 compatible, or at least putting it in the readme you must use Python 2.

I was able to pip install -r requirements.txt in a Python 2 virtual environment no problem though. For now that is the work around.

Edit: This was tested on Ubuntu 17.04, Python 3.5.3, Python 2.7.13, and GCC 6.3.0 20170118.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.