Refactor server statistics calculations to remove dependency on a2sData structure
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 12s

This commit is contained in:
2025-10-06 18:37:45 +08:00
parent ec5ea81b87
commit 828d45001f

View File

@@ -42,14 +42,14 @@ function App() {
// Calculate server statistics // Calculate server statistics
const onlineServers = servers.filter(s => s.status === 'online') const onlineServers = servers.filter(s => s.status === 'online')
const totalPlayers = onlineServers.reduce((sum, s) => sum + (s.a2sData ? (s.a2sData.playerCount - s.a2sData.botCount) : 0), 0) const totalPlayers = onlineServers.reduce((sum, s) => sum + (s.playerCount - s.botCount), 0)
const totalSlots = onlineServers.reduce((sum, s) => sum + (s.a2sData?.maxPlayers || 0), 0) const totalSlots = onlineServers.reduce((sum, s) => sum + s.maxPlayers, 0)
// Get most popular server (highest player count) // Get most popular server (highest player count)
const mostPopularServer = onlineServers.length > 0 const mostPopularServer = onlineServers.length > 0
? onlineServers.reduce((prev, current) => { ? onlineServers.reduce((prev, current) => {
const prevPlayers = (prev.a2sData?.playerCount || 0) - (prev.a2sData?.botCount || 0) const prevPlayers = prev.playerCount - prev.botCount
const currentPlayers = (current.a2sData?.playerCount || 0) - (current.a2sData?.botCount || 0) const currentPlayers = current.playerCount - current.botCount
return currentPlayers > prevPlayers ? current : prev return currentPlayers > prevPlayers ? current : prev
}) })
: null : null