Refactor player count calculations to exclude bot counts for accurate statistics
All checks were successful
CI - Build and Push / Build and Push Docker Image (push) Successful in 11s

This commit is contained in:
2025-10-06 19:02:23 +08:00
parent 828d45001f
commit 83630ffe51
3 changed files with 8 additions and 8 deletions

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.playerCount - s.botCount), 0) const totalPlayers = onlineServers.reduce((sum, s) => sum + s.playerCount, 0)
const totalSlots = onlineServers.reduce((sum, s) => sum + s.maxPlayers, 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.playerCount - prev.botCount const prevPlayers = prev.playerCount
const currentPlayers = current.playerCount - current.botCount const currentPlayers = current.playerCount
return currentPlayers > prevPlayers ? current : prev return currentPlayers > prevPlayers ? current : prev
}) })
: null : null

View File

@@ -8,7 +8,7 @@ interface ServerListResponse {
serverPort: number serverPort: number
category: string category: string
mapName: string mapName: string
playerCount: number humanCount: number
botCount: number botCount: number
maxPlayers?: number maxPlayers?: number
} }
@@ -19,7 +19,7 @@ export interface ServerData {
port: number port: number
category: string category: string
mapName: string mapName: string
playerCount: number playerCount: number // Human players only (excluding bots)
botCount: number botCount: number
maxPlayers: number maxPlayers: number
status: 'online' | 'offline' | 'loading' status: 'online' | 'offline' | 'loading'
@@ -62,7 +62,7 @@ export function ServerProvider({ children }: { children: ReactNode }) {
port: server.serverPort, port: server.serverPort,
category: server.category, category: server.category,
mapName: server.mapName, mapName: server.mapName,
playerCount: server.playerCount, playerCount: server.humanCount,
botCount: server.botCount, botCount: server.botCount,
maxPlayers: server.maxPlayers || 0, maxPlayers: server.maxPlayers || 0,
status: 'online' as const status: 'online' as const

View File

@@ -264,7 +264,7 @@ function Servers() {
fontWeight: 'bold', fontWeight: 'bold',
color: 'var(--text-primary)' color: 'var(--text-primary)'
}}> }}>
{server.status === 'online' ? `${server.playerCount - server.botCount}/${server.maxPlayers}` : 'Loading...'} {server.status === 'online' ? `${server.playerCount}/${server.maxPlayers}` : 'Loading...'}
</div> </div>
</div> </div>
<div> <div>
@@ -380,7 +380,7 @@ function Servers() {
color: 'var(--accent-primary)', color: 'var(--accent-primary)',
marginBottom: '0.5rem' marginBottom: '0.5rem'
}}> }}>
{servers.reduce((sum, s) => sum + (s.status === 'online' ? (s.playerCount - s.botCount) : 0), 0)} {servers.reduce((sum, s) => sum + (s.status === 'online' ? s.playerCount : 0), 0)}
</div> </div>
<div style={{ <div style={{
color: 'var(--text-secondary)', color: 'var(--text-secondary)',