feat(hunt): track walking distance via GPS, show live locations on map
Add foreground-only GPS distance tracking for hunts
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
Reference in New Issue
Block a user