replay toJSON in version 4.0

50 views
Skip to first unread message

Jason Ayre

unread,
Mar 3, 2013, 4:40:25 PM3/3/13
to sc2r...@googlegroups.com
Ive found examples of the 3.0 sending a replay to json, but for the life of me I cannot figure out how to get the replay file into json. I see there is a plugin with a .toJSON function in it, but when I pass the replay file to the toJSON() method (which appears to expect as its first argument as far as I can tell), it tells me it didn't expect an argument. Can anyone shed any light on this? I'm not a python guy.

Graylin Kim

unread,
Mar 3, 2013, 5:32:53 PM3/3/13
to sc2r...@googlegroups.com
Sorry for the trouble Jason,

The code isn't very clear; definitely not if you aren't a "python guy". In the future I'll probably be reworking this to something more clear and simple. Can you point me to the documentation you saw so I can correct/remove it?

There are two issues here, first there was a bug which I fixed in this latest commit to the master branch (also fixed on HotS). Second, the toJSON function isn't really a function. The @plugin decorator changes the toJSON function into a factory function of sorts. Actual usage looks something like this:

>>> from sc2reader.plugins.replay import toJSON
>>> configuredToJSON = toJSON(indent=2)
>>> replay = sc2reader.load_replay('example.SC2Replay')
>>> print configuredToJSON(replay)
{
  "category": "Ladder",
  "map": null,
  "players": [
    ...
  ],
  "type": "1v1",
  "is_ladder": true,
  ...
  "release": "2.0.4.24944"
}

This separates the configuration from the call which is important for configuration plugins before registration.It would have been more transparent how this worked if I had written the plugins as classes instead of as decorated functions. Here's an example of how plugin registration works:

>>> sc2reader.register_plugin('Replay', toJSON(indent=2))
>>> print sc2reader.load_replay('example.SC2Replay')
{
  "category": "Ladder",
  "map": null,
  "players": [
    ...
  ],
  "type": "1v1",
  "is_ladder": true,
  ...
  "release": "2.0.4.24944"
}

Does that clear things up?

~Graylin


On Sun, Mar 3, 2013 at 4:40 PM, Jason Ayre <jaso...@gmail.com> wrote:
Ive found examples of the 3.0 sending a replay to json, but for the life of me I cannot figure out how to get the replay file into json. I see there is a plugin with a .toJSON function in it, but when I pass the replay file to the toJSON() method (which appears to expect as its first argument as far as I can tell), it tells me it didn't expect an argument. Can anyone shed any light on this? I'm not a python guy.

--
You received this message because you are subscribed to the Google Groups "sc2reader" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sc2reader+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jason Ayre

unread,
Mar 3, 2013, 6:34:49 PM3/3/13
to sc2r...@googlegroups.com
No worries, thanks for the help. That does clear some things up regarding the plugin pattern, but Im still getting the same error unfortunately.

Unfortunately Im still geting the same error. Also I am on the hots branch, I had some trouble getting it to work at all initially because it was throwing me an error about 10 arguments but 11 were passed, and when I removed everything and installed hots branch that seemed to fix it. -- Here is the line by line:

>>> import sc2reader

>>> from sc2reader.plugins.replay import toJSON
>>> configuredToJSON = toJSON(indent=2)
>>> replay = sc2reader.load_replay("path/to/replay/ohana_le.SC2Replay")
>>> print configuredToJSON(replay)

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.8-intel/egg/sc2reader/plugins/utils.py", line 20, in call
  File "build/bdist.macosx-10.8-intel/egg/sc2reader/plugins/replay.py", line 17, in toJSON
TypeError: wrapper() takes exactly 0 arguments (1 given)

2nd example you gave:

>>> import sc2reader
>>> from sc2reader.plugins.replay import toJSON
>>> sc2reader.register_plugin('Replay', toJSON(indent=2))
>>> print sc2reader.load_replay("path/to/replay/ohana_le.SC2Replay")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "build/bdist.macosx-10.8-intel/egg/sc2reader/factories.py", line 69, in load_replay
  File "build/bdist.macosx-10.8-intel/egg/sc2reader/factories.py", line 138, in load
  File "build/bdist.macosx-10.8-intel/egg/sc2reader/factories.py", line 151, in _load
  File "build/bdist.macosx-10.8-intel/egg/sc2reader/plugins/utils.py", line 20, in call
  File "build/bdist.macosx-10.8-intel/egg/sc2reader/plugins/replay.py", line 17, in toJSON
TypeError: wrapper() takes exactly 0 arguments (1 given)

---

Which leads me to believe that Im not calling things wrong, considering Im getting the error both places, and the plugin seems to be decorating the replay as it triggers the error only after its loaded. Any idea what the problem could be though?

Graylin Kim

unread,
Mar 3, 2013, 6:45:04 PM3/3/13
to sc2r...@googlegroups.com
What is your current commit id? As mentioned in my previous response I just pushed a new commit to fix the toJSON code. If you haven't updated your local branch then you'll probably still have issues.

Re: the 10 arguments but 11 were passed, the master branch doesn't support the latest WoL or HotS patches. HotS is pretty much the production branch right now but hasn't been merged back to master yet.

~Graylin


--

Jason Ayre

unread,
Mar 3, 2013, 8:21:27 PM3/3/13
to sc2r...@googlegroups.com
I cloned it as of this morning, current ID is: d18f4c51f5faa31488fa6777f1b0627b48801d20

Jason

Jason Ayre

unread,
Mar 3, 2013, 8:25:00 PM3/3/13
to sc2r...@googlegroups.com
My bad, for some reason I thought the commit you referenced was older, didn't see it was 3 hours ago that you fixed it, Ill give it another go around and let you know what happens, thanks!

Graylin Kim

unread,
Mar 3, 2013, 8:29:55 PM3/3/13
to sc2r...@googlegroups.com
No problem Jason.

I'm just happy to see people using the mailing list. I think too often people see sc2reader's rough edges and give up or run away :-/

It really does work quite well though!

Jason Ayre

unread,
Mar 3, 2013, 8:47:37 PM3/3/13
to sc2r...@googlegroups.com
Thanks man that worked!

Ya it definitely seems to be the most comprehensive parser around these days. I had actually one of the first replay sites around back in the day, it was replayladder.com -- ive since let it die because of how bad it would break my site every time changes would happen (was using the php replay lib). Well that and it was my first web app so wasn't great, and Ive since switched to ruby on rails for past couple years. So anyways Im going to be using your repo likely to be a very important core of my new site, but I think Ill likely just run a background process after replays are uploaded, convert the replay to json and then load the replay data from json after.

Anyways I appreciate your help so far, seems like a pretty awesome parsing library (if only it were written in ruby though :)), and Im sure I will have more questions for you soon!

Graylin Kim

unread,
Mar 3, 2013, 9:15:09 PM3/3/13
to sc2r...@googlegroups.com
Great, and thanks for the introduction.

I can say that you aren't the first one looking to use the library for a rails project. In both cases I think that running the processing in a separate worker process worked out pretty well for them as well.

Good luck!

~Graylin
Reply all
Reply to author
Forward
0 new messages