stats.go
1package utils
2
3import "git.kilimanjaro.io/rtw/document"
4
5// Distance returns the maximum distance traveled in a trip. If multiple routes connect
6// two waypoints, the longest is used.
7func Distance(waypoints []document.WaypointAttrs) float64 {
8 total := 0.0
9 for _, wp := range waypoints {
10 maxDist := 0.0
11 for _, route := range wp.From {
12 if route.Distance > maxDist {
13 maxDist = route.Distance
14 }
15 }
16 total += maxDist
17 }
18 return total
19}
20
21// Countries returns the set of countries traveled based on the locations of the waypoints
22func Countries(waypoints []document.WaypointAttrs) []string {
23 countries := make(map[string]struct{})
24 for _, wp := range waypoints {
25 countries[wp.Country] = struct{}{}
26 }
27 var out []string
28 for country := range countries {
29 out = append(out, country)
30 }
31 return out
32}