struggling to use sc2reader for a data science project

34 views
Skip to first unread message

loic midy

unread,
Nov 23, 2019, 1:39:56 PM11/23/19
to sc2reader
Hello,

I struggle to use sc2reader.
So far I have been able to use :
- sc2reader.load_replay
- get basics infos on a replay
- get basics infos on the players of the replay
- get some infos on BasicCommandEvent
I join a small file containing the code I managed to use.

Can you tell me how I could :
- get the worker count at each frame or each second for each player
- get the army count at each frame or each second for each player
- get at each frame or each second for each player the X,Y position or each army unit
- get the amout of mineral and vespene gaz available for each player

Yours sincerely
Loïc
testsc2bis.py

Philippe Carphin

unread,
Nov 23, 2019, 6:19:43 PM11/23/19
to sc2reader
Hi Loïc,

We did a project where we displayed the current unit counts of each type at each time step.


You can see it in action at http://inf8808.witify.io

Basically, you have to do it yourself.  We took the event list (there are two main ones if I remember well) and filter out all the UnitCreateEvent, UnitDeathEvent, etc.

So took all the relevant events of those types, then split them by player, then by unit.

Once you have all the CreateUnitEvent, UnitDoneEvent, etc for player1's Zealots.  Going through that list and looking at the times allows one to calculate the number of active zealots for player1 at time t.  We were focused on unit lifetimes, but the unit counts at each time can be seen on our graph.

At first, things looked good, we were getting unit counts but I noticed, "hey both these guys are making very few gateway units, that's odd" then I watched the replay and it was full of gateway units!  That was because there is one event for a unit popping out of a building, and one event for a unit finishing to warp in.  Archons make two high templars disappear and one Archon appear.  I was really excited when I saw it in my graph: the lifetime of two high templars stop at time t, then a couple seconds later an archon appears.

Feel free to ask me more questions.

Philippe Carphin

unread,
Nov 23, 2019, 6:25:13 PM11/23/19
to sc2reader
I should add: we deal with (X, Y) positions in the "Events" section and the stuff relevant for unit counts is in "Unit Composition".  We show the unit counts in a tooltip and it can be seen as the number of unit lifetimes that are intersected by a vertical line.


On Saturday, 23 November 2019 13:39:56 UTC-5, loic midy wrote:

loic midy

unread,
Nov 24, 2019, 5:48:12 AM11/24/19
to sc2r...@googlegroups.com
Hello Philippe,

here are a few ligns of my code :
r =sc2reader.load_replay('C:/testsc2/Replays/0000e057beefc9b1e9da959ed921b24b9f0a31c63fedb8d94a1db78b58cf92c5.SC2Replay', load_level=4)
event_names = set([event.name for event in r.events])
print("event_names",event_names)

game_event_names = set([event.name for event in r.game_events])
print("game_event_names",game_event_names)

both print give the same result
event_names {'SetControlGroupEvent', 'SelectionEvent', 'CameraEvent', 'TargetPointCommandEvent', 'UpdateTargetUnitCommandEvent', 'BasicCommandEvent', 'PlayerLeaveEvent', 'GetControlGroupEvent', 'UserOptionsEvent', 'UpdateTargetPointCommandEvent', 'AddToControlGroupEvent', 'ControlGroupEvent', 'TargetUnitCommandEvent'}

I don't see the UnitCreateEvent and UnitDeathEvent.

Yours sincerely
Loïc

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/sc2reader/c3b1ba84-e783-4241-97c9-f552a0c23b04%40googlegroups.com.

Philippe Carphin

unread,
Nov 24, 2019, 8:09:01 AM11/24/19
to sc2reader
Hi Loïc, I posted the wrong repo yesterday.

You should find what you need in here https://github.com/FabriceCh/inf8808-projet

https://github.com/FabriceCh/inf8808-projet/blob/master/data/dataGenerator.py : generate_unit_composition_data() is the main part and there is a function that takes that data and calculates the unit counts at each time.

Later
Phil
To unsubscribe from this group and stop receiving emails from it, send an email to sc2r...@googlegroups.com.

Philippe Carphin

unread,
Nov 24, 2019, 8:14:52 AM11/24/19
to sc2reader
Also the documentation has the details on the events  https://sc2reader.readthedocs.io/en/latest/events/tracker.html

And also, consider using an IDE like PyCharm.  You will be able to set breakpoints and use the Python Debugger to inspect the attributes of objects you might be interested in.  This is how I learned what is not in the documentation.
Reply all
Reply to author
Forward
0 new messages