GraylinKim / sc2reader

A python library that extracts data from various Starcraft II resources to power tools and services for the SC2 community. Who doesn't want to hack on the games they play?
http://sc2reader.readthedocs.org
MIT License
413 stars 85 forks source link

Fix APM calculation to have a non-integer denominator #106

Closed dsjoerg closed 11 years ago

dsjoerg commented 11 years ago

In https://github.com/GraylinKim/sc2reader/blob/hots/sc2reader/plugins/replay.py#L94 we have:

            player.avg_apm = sum(player.apm.values())/float(len(player.apm.keys()))

the denominator is the number of minutes, which is an integer (casted to a float, but logically an integer).

It would be more correct to use the actual length of time (in seconds or frames) that player was in the game.

GraylinKim commented 11 years ago

As part of this implementation we'll need to set a player.frames_in_game field when loading context for player leave events. I'm not liking frames_in_game as an attribute name though, suggestions?

dsjoerg commented 11 years ago

frames_alive frames_active frames_before_leaving

Rather than the player leave event, is there an event that tells us when a player no longer has any forces? If so that would be better to use, for NvN games when a player's stuff is all gone but they don't leave right away. If the event doesnt exist then don't worry about it.

GraylinKim commented 11 years ago

frames_active sounds good to me.

There aren't any "out of forces" events, that's more of a game notification than a player action. Also, a player that is out of forces can instead help out a team mate if they have shared control enabled.

We could key off of the last ability command issued though! How about that?

dsjoerg commented 11 years ago

Very good

GraylinKim commented 11 years ago

Note to self: with this logic we need to modify the APM plugin to only count actions taken up to the frames_active frame. A guy with no units can still move his screen around and select stuff.

GraylinKim commented 11 years ago

This uses the number of seconds the player is in the game as the denominator.

As mentioned above, it may be even better to only use the number of seconds in which the player issuing commands to units. Currently a player with no units can have their APM tanked by sitting around and watching the rest of the game.