/** * Team walking-distance aggregation. * * A team's distance is the average of the `UserTrack.distanceMeters` of its * _current_ participants (the team owner plus its team members) that actually * recorded a distance. Participants without a recorded track are excluded * rather than diluting the average with zeros. */ export function teamAverageDistance( participantIds: number[], tracks: Map ): number { const unique = [...new Set(participantIds)]; const distances = unique .map((id) => tracks.get(id)) .filter((d): d is number => d !== undefined); if (distances.length === 0) return 0; const sum = distances.reduce((acc, d) => acc + d, 0); return Math.round(sum / distances.length); }