Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--stats output can not be redirect #36

Closed
Asesjix opened this issue May 20, 2016 · 5 comments
Closed

--stats output can not be redirect #36

Asesjix opened this issue May 20, 2016 · 5 comments

Comments

@Asesjix
Copy link

Asesjix commented May 20, 2016

the following command creates a blank file
py heroprotocol.py --stats "Blackheart's Bay.StormReplay" > output.txt

@crorella
Copy link

crorella commented May 23, 2016

The problem is not with the redirection, is the --stats flag which is not working (at least when I tried the command)

If you do a py heroprotocol.py --json --trackerevents "Blackheart's Bay.StormReplay" > output.txt
you will see there is data redirected to the file

@johnafogarty4
Copy link

johnafogarty4 commented Mar 6, 2017

Are there any ideas on the reason why the --stats flag isn't working? I've looked and in theory everything looks like it should be working, but clearly it is not.

@WhatIsACore
Copy link

WhatIsACore commented Jun 3, 2017

Here is the code block that controls the --stats flag in heroprotocol.py:

    # Print stats
    if args.stats:
        logger.log_stats(sys.stderr)

and here is the code for log_stats:

    def log_stats(self, output):
        for name, stat in sorted(self._event_stats.iteritems(), key=lambda x: x[1][1]):
            print >> output, '"%s", %d, %d,' % (name, stat[0], stat[1] / 8)

In short, when that argument is passed, a coded-in exception is thrown and nothing happens.

Compare this with the working code for the trackerevents flag, which actually reads the replay file and decodes the contents:

    # Print tracker events
    if args.trackerevents:
        if hasattr(protocol, 'decode_replay_tracker_events'):
            contents = archive.read_file('replay.tracker.events')
            for event in protocol.decode_replay_tracker_events(contents):
                logger.log(sys.stdout, event)

and you can see why this issue exists.

heroprotocol.py

@rohel01
Copy link

rohel01 commented Aug 20, 2017

Your command only redirects stdout. From the code below, it seems stats are printed to stderr instead.

# Print stats
    if args.stats:
        logger.log_stats(sys.stderr)

This would explain why your output file remains blank. A simple workaround is to redirect both stdout and stderr to your file.

py heroprotocol.py --stats "Blackheart's Bay.StormReplay" > output.txt 2>&1

Are there any reasons why stats are specifically printed on stderr ? If not, and if you are okay with modifying the source code, a proper fix would be

# Print stats
    if args.stats:
        logger.log_stats(sys.stdout)

@VashSan
Copy link

VashSan commented Aug 21, 2017

I found out what "stats" actually does. And it works actually fine, however in another way you might think

Please Blizz: add this to the documentation! Without investigating the code you will never guess what happens here.

Explanation
It works only together with one of the event parsing arguments. Test it like this:
heroprotocol --trackerevents --stats "xxx.StormReplay"

It will then print (to the error stream as observed). Here a shortened example:

'NNet.Replay.Tracker.SUnitRevivedEvent':	[29, 5208]	
'NNet.Replay.Tracker.SUnitDiedEvent':	[2808, 834968]	
'NNet.Replay.Tracker.SPlayerSetupEvent':	[10, 1920]	
'NNet.Replay.Tracker.SScoreResultEvent':	[1, 140656]

That means it is not at all about game stats as displayed in the final screen. Its more about some internal stats of the event parser. I believe it is the number of events and the time it took to process, thats just a guess though.

Why is it printed to the error stream? Because it is no content of the actual replay, but generated values which can change (depending on heroprotocol version, in cas of fixes) and are for debugging or optimizing purpose maybe (check if the events processed match the real events in the game).

So you can still process the original output of the standard stream. And if really wanted you may get stats from error stream. No big deal. And for most of us pretty useless?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants