update session statistics
This commit is contained in:
@@ -70,6 +70,7 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH
|
|||||||
Session string
|
Session string
|
||||||
Track string
|
Track string
|
||||||
MaxPlayers int
|
MaxPlayers int
|
||||||
|
SessionConcluded bool
|
||||||
})
|
})
|
||||||
|
|
||||||
// Maps for aggregating statistics
|
// Maps for aggregating statistics
|
||||||
@@ -101,11 +102,13 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH
|
|||||||
Session string
|
Session string
|
||||||
Track string
|
Track string
|
||||||
MaxPlayers int
|
MaxPlayers int
|
||||||
|
SessionConcluded bool
|
||||||
}{
|
}{
|
||||||
StartTime: entry.DateCreated,
|
StartTime: entry.DateCreated,
|
||||||
Session: entry.Session,
|
Session: entry.Session,
|
||||||
Track: entry.Track,
|
Track: entry.Track,
|
||||||
MaxPlayers: entry.PlayerCount,
|
MaxPlayers: entry.PlayerCount,
|
||||||
|
SessionConcluded: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count session types
|
// Count session types
|
||||||
@@ -116,6 +119,12 @@ func (s *StateHistoryService) GetStatistics(ctx *fiber.Ctx, filter *model.StateH
|
|||||||
dailySessionCount[dateStr]++
|
dailySessionCount[dateStr]++
|
||||||
} else {
|
} else {
|
||||||
session := sessionMap[entry.SessionID]
|
session := sessionMap[entry.SessionID]
|
||||||
|
if session.SessionConcluded {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (entry.PlayerCount == 0) {
|
||||||
|
session.SessionConcluded = true
|
||||||
|
}
|
||||||
session.EndTime = entry.DateCreated
|
session.EndTime = entry.DateCreated
|
||||||
if entry.PlayerCount > session.MaxPlayers {
|
if entry.PlayerCount > session.MaxPlayers {
|
||||||
session.MaxPlayers = entry.PlayerCount
|
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
|
// Calculate statistics
|
||||||
stats.PeakPlayers = peakPlayers
|
stats.PeakPlayers = peakPlayers
|
||||||
stats.TotalSessions = len(sessionMap)
|
stats.TotalSessions = len(sessionMap)
|
||||||
|
|||||||
Reference in New Issue
Block a user