Comments (4)
Both of these can be calculated from the event logs, at least the amount I've parsed so far.
-
Read the timestamp on the last events. That would be the match length.
-
There should be example code in the test application. Here's the CalculateAPM function, which calculates a relatively-correct APM, even though it may not match exactly to SC2Gears or SC2. It's tough to say which events they do and don't count towards APM.
private static void CalculateAPM(Replay replay) { var events = replay.PlayerEvents; if (events == null) { // This is experimental. With older replays, it appears to return a close approximation. return; } var eventGroups = events.Where(r => r.Player != null) .Where(r => r.EventType != GameEventType.Inactive) .GroupBy((r) => r.Player); foreach (var group in eventGroups) { var order = group.OrderBy((r) => r.Time); var last = order.Last(); var count = group.Count(); // Calculates APM per second. var apm = count / last.Time.TimeSpan.TotalSeconds; apm *= 60; Debug.WriteLine(last.Player.Name + "'s APM: " + apm); } }
from sc2replay-csharp.
Hi,
I tried the calculateAPM function. It seems always return the first player's APM. Am I missing something? Could you please help?
Thank you,
private string CalculateAPM(Replay replay)
{
string str = "";
var events = replay.PlayerEvents;
if (events == null)
{
// This is experimental. With older replays, it appears to return a close approximation.
return str;
}
var eventGroups = events.Where(r => r.Player != null)
.Where(r => r.EventType != GameEventType.Inactive)
.GroupBy((r) => r.Player);
foreach (var group in eventGroups)
{
var order = group.OrderBy((r) => r.Time);
var last = order.Last();
var count = group.Count();
// Calculates APM per second.
double lastTimeSpan = last.Time.TimeSpan.TotalSeconds;
var apm = count / lastTimeSpan;
apm *= 60;
str += (last.Player.Name + "'s APM: " + apm + "; match length: " + lastTimeSpan) + "<br>";
}
return str;
}
public ActionResult Index()
{
string baseUrl = Request.PhysicalPath + @"\Content\replays\replay4.SC2replay";
Replay replay = Replay.Parse(baseUrl);
ViewBag.Map = replay.Map;
ViewBag.Player = replay.Players;
ViewBag.GameType = replay.GameType;
ViewBag.TeamSize = replay.TeamSize;
ViewBag.ChatMessages = replay.ChatMessages;
ViewBag.GameSpeed = replay.GameSpeed;
ViewBag.PlayerEvents = replay.PlayerEvents;
ViewBag.Gateway = replay.Gateway;
ViewBag.ReplayBuild = replay.ReplayBuild;
ViewBag.ReplayVersion = replay.ReplayVersion;
ViewBag.Timestamp = replay.Timestamp;
ViewBag.APM = CalculateAPM(replay);
return View();
}
from sc2replay-csharp.
It seems to be correct, but there may be an issue with player IDs being used in newer replays. I really haven't had much of a chance to test against the latest patch, so I can take a closer look at it. I'd put a breakpoint inside the foreach loop and check that different players are actually there, or that there are multiple groups at all.
I could imagine getting only the first player's APM if there's only 1 player's actions there for some reason... that or the GroupBy isn't working properly.
from sc2replay-csharp.
Closing based on inactivity. If you're still having issues, feel free to open a new issue.
from sc2replay-csharp.
Related Issues (20)
- teams/players incorrectly parsed HOT 2
- Foreign text causes a crash when parsing the chat HOT 3
- Foreign filenames cause crash HOT 2
- Double namespace "replay" in the latest version HOT 2
- Map fails to parse HOT 1
- Assembly not found when deployed to Microsoft Server 2008 HOT 2
- Store game length as a property in Replay HOT 1
- PlayerEvents dosen't work for Patch v1.1.4.2 (or before) HOT 3
- Adding PlayerType.Observer HOT 1
- Behavior of Replay.Players property changed HOT 3
- Game Length is 0:00 for 1.5.3 replays
- Player events fail to parse for 1.5.3 HOT 2
- AbilityType.CancelTrain isnt parsed correctly. Returns Unknown
- Replay parsing is broken in 1.2.0.6 and up. HOT 3
- HotS replays need event parsing updated
- League? HOT 2
- Problem parsing SC2 Hots version 2.x.x files
- AddChatMessage should support longer strings HOT 1
- Update Wiki to document replay.message.events HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sc2replay-csharp.