Skip to content

Developer documentation

GraylinKim edited this page Mar 15, 2011 · 2 revisions

Developer Documentation

Organization

The primary user interface is contained in the __init__.py file for simple export. It consists of basic read and a read_file functions. These files accept an optional configuration argument which determines which readers and processors will be employed in preparing the finished Replay object(s). The rest of sc2reader is composed of 3 core modules as well as several support modules and helper functions.

Core:

  • readers.py - Readers read the various different files out of the MPQArchive
  • parsers.py - Parsers assist in the reading of the 'replay.game.events' file
  • processors.py - Processors post process the extracted information into a more useful form

Support

  • config.py - Contains various different configurations
  • objects.py - Contains all of the structures for sc2reader
  • utils.py - Miscellaneous utilities that didn't fit anywhere else

Configuration

Configuration is pretty straightfoward and serves to instruct sc2reader in reading the .sc2replay file, and performing post processing tasks to improve the usability of the extracted information.

Readers

The readers are stored in an OrderedDict() to allow you to specify the order in which the files need to be parsed in the case that there exist dependencies between the different readers that you are using. For each replay and each archived file, the list of available readers is checked (in order) using the reader.reads(build) function to find a match. In this way you can provide a different reader for any given subset of the possible build values.

readers: {
        'replay.initData': [ List of Available Readers ],
        'replay.details': [ List of Available Readers ],
        'replay.attributes.events': [ List of Available Readers ],
        'replay.message.events': [ List of Available Readers ],
        'replay.game.events': [ List of Available Readers ],
}

Only files listed as keys in the the readers dictionary will be extracted and read, which allows you to customize the reader's approach to extract only the information you need and optimize for speed. To skip event parsing, just exclude the 'replay.message.events' key in the dictionary.

Processors

Processors are called after all the readers have returned and serve as a hook to massage the information into a more consumable form for your purposes. The default configuration includes a dozen or so post processors that do everything from determining winners to organizing events. Because a given processor will frequently depend on the previous execution of another processor the processors are stored in an ordered list which requires you to explicitly set the order of execution. While tedious, its non-trivial to trace a tree of dependencies, to produce an ordering, so sc2reader opts out entirely (at least for now).

processors: [PeopleProcessor, EventProcessor, ApmProcessor, ResultsProcessor]
Clone this wiki locally