def parse(self, replaycode, replayfile):
        localfilename = "./tmp/{}.SC2Replay".format(time.time())
        file = open(localfilename, 'wb')
        file.write(replayfile.file.read())
        file.close()

        replay = sc2reader.load_replay(localfilename, load_level=4)
        errors = []
        for p in ['APMTracker', 'UpgradesTracker']:
            code, details = replay.plugins[p]
            if code == 1:
                errors.append((p, details))
        os.remove(localfilename)

        players = [h for h in replay.humans if not h.is_observer and not h.is_referee]  # May be optimized
        APMPlugin.gatherstatistics(replaycode, players)
        UpgradesPlugin.gatherstatistics(replaycode, players)

        playersdata = []
        for p in players:
            playersdata += [p.name, p.play_race]
        return {'players': playersdata,
                'errors': errors}
 def upgrades(self, code):
     return UpgradesPlugin.getstatistics(code)