Git Product home page Git Product logo

Comments (4)

ascendedguard avatar ascendedguard commented on June 30, 2024

Both of these can be calculated from the event logs, at least the amount I've parsed so far.

  1. Read the timestamp on the last events. That would be the match length.

  2. 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.

maxxintegration avatar maxxintegration commented on June 30, 2024

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.

ascendedguard avatar ascendedguard commented on June 30, 2024

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.

ascendedguard avatar ascendedguard commented on June 30, 2024

Closing based on inactivity. If you're still having issues, feel free to open a new issue.

from sc2replay-csharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.