From 254e4bb9a4ed4f121c324f5df7c0b518b3199089 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20Jurmanovi=C4=87?= Date: Tue, 3 Jun 2025 21:01:55 +0200 Subject: [PATCH] update session statistics --- local/service/state_history.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/local/service/state_history.go b/local/service/state_history.go index 9171e7a..953419b 100644 --- a/local/service/state_history.go +++ b/local/service/state_history.go @@ -70,6 +70,7 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH Session string Track string MaxPlayers int + SessionConcluded bool }) // Maps for aggregating statistics @@ -101,11 +102,13 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH Session string Track string MaxPlayers int + SessionConcluded bool }{ StartTime: entry.DateCreated, Session: entry.Session, Track: entry.Track, MaxPlayers: entry.PlayerCount, + SessionConcluded: false, } // Count session types @@ -116,6 +119,12 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH dailySessionCount[dateStr]++ } else { session := sessionMap[entry.SessionID] + if session.SessionConcluded { + continue + } + if (entry.PlayerCount == 0) { + session.SessionConcluded = true + } session.EndTime = entry.DateCreated if entry.PlayerCount > session.MaxPlayers { session.MaxPlayers = entry.PlayerCount @@ -123,6 +132,15 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH } } + for key, session := range sessionMap { + if !session.SessionConcluded { + session.SessionConcluded = true + } + if (session.MaxPlayers == 0) { + delete(sessionMap, key) + } + } + // Calculate statistics stats.PeakPlayers = peakPlayers stats.TotalSessions = len(sessionMap)