playnite-gameactivity-plugin icon indicating copy to clipboard operation
playnite-gameactivity-plugin copied to clipboard

"Total hours" charts adding up play sessions outside month range

Open claugaete opened this issue 1 year ago • 0 comments

I'm on version 3.2, and the "Total hours" charts (on the "Sources", "Genres" and "Tags" tabs) are adding up the playtime for ALL sessions of the games I played that month, not just the sessions that happened during the month in question. For example, in the image below you can see that the chart says I played 377 hours in October, even though I only played around 22. This is because, since installing Playnite, I have played the 5 games you can see on the chart for a collective 377 hours.

image

This is my first time looking into the plugin's code so this might not be correct, but I think the issue is in the getActivityByMonth method in GameActivityView.xaml.cs. The method creates a list of GameActivities called listGameActivities, which contains all games played during a certain month. Each GameActivities object contains ALL play sessions for a game, and they are added up in the for loops starting in lines 365, 402 and 440 (depending on the type of chart).

The previous version of the plugin had an extra condition (which checked if each session in the GameActivity object was in the date range of the month in question), but that condition was removed in the new version, which means all play sessions are added up for all games that were played at least once during the month.

I believe the issue would be solved by adding the following lines just above the for loops I previously mentioned:

Activities = Activities.Where(y =>
    startOfMonth <= Convert.ToDateTime(y.DateSession).ToLocalTime()
    && Convert.ToDateTime(y.DateSession).ToLocalTime() <= endOfMonth
)

This would filter all activities just to the ones that were actually played during the month (according to the player's local timezone). There is probably a more efficient way to do the filtering (this is my first time working with C#), but I hope my reasoning helped. :)

claugaete avatar Feb 17 '24 15:02 claugaete