Files
Pascal 61cc516f47
Docker Image CI / test (push) Failing after 41s
Docker Image CI / deploy (push) Skipped
Tests / unit (push) Failing after 36s
Tests / integration (push) Successful in 1m34s
feat(hunt): track walking distance via GPS, show live locations on map
Add foreground-only GPS distance tracking for hunts
2026-09-27 20:55:58 +02:00

23 lines
737 B
TypeScript

/**
* 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, number>
): 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);
}