accept multi search too
This commit is contained in:
36
cmd/run.go
36
cmd/run.go
@@ -15,16 +15,14 @@ import (
|
|||||||
func Run(ctx context.Context) error {
|
func Run(ctx context.Context) error {
|
||||||
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
fs := flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
||||||
searchRadius := fs.Float64("r", 5.0, "search radius in miles")
|
searchRadius := fs.Float64("r", 5.0, "search radius in miles")
|
||||||
area := fs.Float64("a", 0.5, "result radius in miles")
|
|
||||||
doArea := fs.Bool("d", false, "do result radius in miles")
|
doArea := fs.Bool("d", false, "do result radius in miles")
|
||||||
var towns FlagStringArray
|
var towns FlagStringArray
|
||||||
fs.Var(&towns, "t", "list of towns to search around")
|
fs.Var(&towns, "t", "list of towns to search around")
|
||||||
|
searches := StringToFloat64{}
|
||||||
|
fs.Var(&searches, "s", "list of things to search for around each town")
|
||||||
if err := fs.Parse(os.Args[1:]); err != nil {
|
if err := fs.Parse(os.Args[1:]); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
radius := *area / convertToMiles
|
|
||||||
radiusX := 2 * radius / 2
|
|
||||||
radiusY := 2 * radius / 3
|
|
||||||
|
|
||||||
type geoJson struct {
|
type geoJson struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
@@ -38,12 +36,16 @@ func Run(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
geoJsons := []geoJson{}
|
geoJsons := []geoJson{}
|
||||||
for _, town := range towns {
|
for _, town := range towns {
|
||||||
|
for search, area := range searches {
|
||||||
|
radius := area / convertToMiles
|
||||||
|
radiusX := 2 * radius / 2
|
||||||
|
radiusY := 2 * radius / 3
|
||||||
m, err := NewMapsOf(ctx, town)
|
m, err := NewMapsOf(ctx, town)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
results, err := m.Search(ctx, fs.Args()[0], *searchRadius)
|
results, err := m.Search(ctx, search, *searchRadius)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -51,7 +53,7 @@ func Run(ctx context.Context) error {
|
|||||||
for i := range results {
|
for i := range results {
|
||||||
var a geoJson
|
var a geoJson
|
||||||
a.Type = "Feature"
|
a.Type = "Feature"
|
||||||
a.Properties.Name = path.Join(fs.Args()[0], results[i].Name)
|
a.Properties.Name = path.Join(search, results[i].Name)
|
||||||
a.Geometry.Type = "Point"
|
a.Geometry.Type = "Point"
|
||||||
a.Geometry.Coordinates = []any{results[i].Lng, results[i].Lat}
|
a.Geometry.Coordinates = []any{results[i].Lng, results[i].Lat}
|
||||||
if *doArea {
|
if *doArea {
|
||||||
@@ -68,6 +70,7 @@ func Run(ctx context.Context) error {
|
|||||||
geoJsons = append(geoJsons, a)
|
geoJsons = append(geoJsons, a)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
log.Println(len(geoJsons))
|
log.Println(len(geoJsons))
|
||||||
slices.SortFunc(geoJsons, func(a, b geoJson) int {
|
slices.SortFunc(geoJsons, func(a, b geoJson) int {
|
||||||
return strings.Compare(fmt.Sprint(a.Geometry.Coordinates), fmt.Sprint(b.Geometry.Coordinates))
|
return strings.Compare(fmt.Sprint(a.Geometry.Coordinates), fmt.Sprint(b.Geometry.Coordinates))
|
||||||
@@ -95,3 +98,24 @@ func (array *FlagStringArray) Set(s string) error {
|
|||||||
*array = append(*array, s)
|
*array = append(*array, s)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type StringToFloat64 map[string]float64
|
||||||
|
|
||||||
|
func (array *StringToFloat64) String() string {
|
||||||
|
return fmt.Sprintf("%+v", (*map[string]float64)(array))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (array *StringToFloat64) Set(s string) error {
|
||||||
|
idx := strings.Index(s, "=")
|
||||||
|
if idx < 0 {
|
||||||
|
return fmt.Errorf("should be formatted as k=v")
|
||||||
|
}
|
||||||
|
k := s[:idx]
|
||||||
|
v := s[idx+1:]
|
||||||
|
var n float64
|
||||||
|
if err := json.Unmarshal([]byte(v), &n); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
(*array)[k] = n
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user