StarCraft II Replay Analysis

This developer journey will guide you through StarCraft II replay analysis.

Note: Instructions assume this notebook is running in IBM Data Science Experience (DSX).

Learning goals

This journey covers the following learning goals:

  1. Getting started with DSX notebooks
  2. Using DSX Object Storage to access a replay file
  3. Using sc2reader to load a replay into a Python object
  4. Examining some of the basic replay information in the result
  5. Parsing the contest details into a usable object
  6. Visualizing the contest with graphics
  7. Storing the processed replay in Cloudant

Setup prerequisites

Install the sc2reader, cloudant and bokeh Python packages from PyPI

  • sc2reader is an open source library for processing StarCraft 2 replay files.
  • cloudant is the Python client for using the Cloudant NoSQL DB.
  • bokeh is a Python interactive visualization library.
Requirement already satisfied: sc2reader in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages
Requirement already satisfied: cloudant in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages
Requirement already satisfied: bokeh in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages
Requirement already satisfied: mpyq>=0.2.4 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from sc2reader)
Requirement already satisfied: requests<3.0.0,>=2.7.0 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from cloudant)
Requirement already satisfied: tornado>=4.3 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from bokeh)
Requirement already satisfied: numpy>=1.7.1 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from bokeh)
Requirement already satisfied: six>=1.5.2 in /usr/local/src/bluemix_jupyter_bundle.v41/notebook/lib/python2.7/site-packages (from bokeh)
Requirement already satisfied: python-dateutil>=2.1 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from bokeh)
Requirement already satisfied: PyYAML>=3.10 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from bokeh)
Requirement already satisfied: futures>=3.0.3 in /usr/local/src/bluemix_jupyter_bundle.v41/notebook/lib/python2.7/site-packages (from bokeh)
Requirement already satisfied: Jinja2>=2.7 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from bokeh)
Requirement already satisfied: certifi in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from tornado>=4.3->bokeh)
Requirement already satisfied: singledispatch in /usr/local/src/bluemix_jupyter_bundle.v41/notebook/lib/python2.7/site-packages (from tornado>=4.3->bokeh)
Requirement already satisfied: backports-abc>=0.4 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from tornado>=4.3->bokeh)
Requirement already satisfied: MarkupSafe>=0.23 in /gpfs/global_fs01/sym_shared/YPProdSpark/user/sbba-ea23373a6e8935-79175279034c/.local/lib/python2.7/site-packages (from Jinja2>=2.7->bokeh)

Load the replay

Load in the replay with sc2reader. We'll use bytes that the inserted code read from our DSX-ObjectStorage container.

Replay successfully loaded.

With the replay added, we can now inspect the object in the notebook. We can easily get information like date, map name, participants, winner/loser, etc.

Date: 2016-07-29 14:20:32
Map Name: King Sejong Station LE
Win: Player 1 - Neeb (Protoss)
Loss: Player 2 - ShoWTimE (Protoss)

Visualize and compare replay events

The replay file was processed to add event statistics using pandas and helper functions. Bokeh is used to create Nelson rules charts and box plot charts.

Loading BokehJS ...

Storing Replay Files

Now that we have loaded and processed the replay, we can store it for future use and aggregation.

The replay_object has an as_dict() method to give us JSON.

We'll store this in Cloudant for future use.

  1. Connect to Cloudant with our Bluemix credentials.
  2. Create 'sc2replays' and 'sc2recents' databases.
  3. Store the current replay as a document in the 'sc2replays' database.
  4. Store the current replay as a document in the 'sc2recents' database and remove the older replays.
Cloudant credentials added for storing replay data as JSON.
sc2replays entry saved. Latest id: e0927181cd420a550dc44efd0c39d51d
sc2recents entry saved. Latest id: 54731d2deb367f8ff5f815942827e074