-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
51 lines (46 loc) · 1.4 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"log"
"strings"
"github.com/neptunao/so-close/data"
"github.com/neptunao/so-close/geo"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
centerLat = kingpin.Flag("center-lat", "Center geo point latitude").Default("51.925146").Float64()
centerLon = kingpin.Flag("center-lon", "Center geo point longitude").Default("4.478617").Float64()
limit = kingpin.Flag("top", "Top results limit (Top N)").Default("5").Int()
filename = kingpin.Arg("filename", "CSV file with geo data").Required().String()
)
func stringifyGeoCoordArray(coords []geo.RelativeCoord) []string {
res := make([]string, len(coords))
for i := 0; i < len(coords); i++ {
res[i] = coords[i].String()
}
return res
}
func main() {
kingpin.Parse()
itr, err := data.ConnectCSVFile(*filename)
if err != nil {
log.Fatalf("error connecting to CSV file %s: %s", *filename, err)
}
defer itr.Close()
center := geo.Coord{
Name: "HousingAnywhere Rotterdam office",
Lat: *centerLat,
Lon: *centerLon,
}
fmt.Printf("Calculating top %d nearest and furthest points relative to %s\n",
limit, center)
min, max, err := geo.CalcTopPoints(center, *limit, itr)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Top %d nearest:\n", limit)
fmt.Println(strings.Join(stringifyGeoCoordArray(min), "\n"))
fmt.Println()
fmt.Printf("Top %d furthest:\n", limit)
fmt.Println(strings.Join(stringifyGeoCoordArray(max), "\n"))
}