eklypss / PUBGSharp

C# wrapper for PUBG stats API
25 stars 14 forks source link

Better way to handle seasons, at least until the game is out of EA #14

Open jstillwell opened 7 years ago

jstillwell commented 7 years ago

Since PUBG is now doing monthly resets could we have a way to get the most recent season easily? I assumed that the API was going to return the current season by default but this is not what I see happening. For example if I do this:

 var duos = stats.Stats.Find(s => s.Region == PUBGSharp.Data.Region.NA && s.Mode == 
    PUBGSharp.Data.Mode.Duo);

I still get season 3 stats.

The way it is currently it seems we would need to update the code every month, that is a real pain.

Since season 4 started on September 1 we could start with this and take the current date and figure out how many months since the monthly reset epoch (Sept 2017).

Something like this?

        public static string CurrentSeason() {
            var season4StartDate = new DateTime(2017, 9, 1);
            var today = DateTime.Now;
            var monthsSinceSept2017 = ((today.Year - season4StartDate.Year) * 12) + Math.Abs(today.Month - season4StartDate.Month);

            var season = 4 + monthsSinceSept2017;

            return $"{today.Year}-pre{season}";
        }

It says this problem was solved in the last commit but I don't see how. This would future proof at least until the game is out of early access.

eklypss commented 7 years ago

You can use FindLast, e.g:

var latestSeasonSoloStats = stats.Stats.FindLast(x => x.Mode == Mode.Solo);
var kills = latestSeasonSoloStats.Stats.Find(x => x.Stat == Stats.Kills);
Console.WriteLine($"Season: {latestSeasonSoloStats.Season}, kills: {kills.Value}");

outputs (assuming that player has stats in season 4):

Season: 2017-pre4, kills: 32

The good part about this is that it always returns the stats of the last season the player has actually played, instead of trying to get stats for the current/latest season even if the player hasn't actually played during it.

The latest commit meant that the wrapper wouldn't crash when new season(s) started. I'll probably look into adding more fluent system (if no one else does it first, also I agree that it is a bit tricky to use at the moment) when the game actually releases, but I think that'll work for now.