Backend: Increase S2 cell level from 18 to 21 and remove suburb
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
cd7339d8a0
commit
ba9b3cad72
10 changed files with 23 additions and 92 deletions
|
@ -21,7 +21,6 @@ type Location struct {
|
|||
Place *Place
|
||||
LocName string `gorm:"type:varchar(100);"`
|
||||
LocCategory string `gorm:"type:varchar(50);"`
|
||||
LocSuburb string `gorm:"type:varchar(100);"`
|
||||
LocSource string `gorm:"type:varbinary(16);"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
|
@ -58,7 +57,7 @@ func (m *Location) Find(db *gorm.DB, api string) error {
|
|||
ID: m.ID,
|
||||
}
|
||||
|
||||
if err := l.Query(api); err != nil {
|
||||
if err := l.QueryApi(api); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -74,7 +73,6 @@ func (m *Location) Find(db *gorm.DB, api string) error {
|
|||
|
||||
m.LocName = l.LocName
|
||||
m.LocCategory = l.LocCategory
|
||||
m.LocSuburb = l.LocSuburb
|
||||
m.LocSource = l.LocSource
|
||||
|
||||
if err := db.Create(m).Error; err != nil {
|
||||
|
@ -88,7 +86,6 @@ func (m *Location) Find(db *gorm.DB, api string) error {
|
|||
func (m *Location) Keywords() []string {
|
||||
result := []string{
|
||||
strings.ToLower(m.City()),
|
||||
strings.ToLower(m.Suburb()),
|
||||
strings.ToLower(m.State()),
|
||||
strings.ToLower(m.CountryName()),
|
||||
strings.ToLower(m.Category()),
|
||||
|
@ -121,14 +118,6 @@ func (m *Location) NoCategory() bool {
|
|||
return m.LocCategory == ""
|
||||
}
|
||||
|
||||
func (m *Location) Suburb() string {
|
||||
return m.LocSuburb
|
||||
}
|
||||
|
||||
func (m *Location) NoSuburb() bool {
|
||||
return m.LocSuburb == ""
|
||||
}
|
||||
|
||||
func (m *Location) Label() string {
|
||||
return m.Place.Label()
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ type Location struct {
|
|||
ID string
|
||||
LocName string
|
||||
LocCategory string
|
||||
LocSuburb string
|
||||
LocLabel string
|
||||
LocCity string
|
||||
LocState string
|
||||
|
@ -41,7 +40,6 @@ type LocationSource interface {
|
|||
Category() string
|
||||
Name() string
|
||||
City() string
|
||||
Suburb() string
|
||||
State() string
|
||||
Source() string
|
||||
}
|
||||
|
@ -54,7 +52,7 @@ func NewLocation(id string) *Location {
|
|||
return result
|
||||
}
|
||||
|
||||
func (l *Location) Query(api string) error {
|
||||
func (l *Location) QueryApi(api string) error {
|
||||
switch api {
|
||||
case "osm":
|
||||
return l.QueryOSM()
|
||||
|
@ -75,7 +73,6 @@ func (l *Location) QueryPlaces() error {
|
|||
l.LocSource = s.Source()
|
||||
l.LocName = s.Name()
|
||||
l.LocCity = s.City()
|
||||
l.LocSuburb = s.Suburb()
|
||||
l.LocState = s.State()
|
||||
l.LocCountry = s.CountryCode()
|
||||
l.LocCategory = s.Category()
|
||||
|
@ -106,7 +103,6 @@ func (l *Location) Assign(s LocationSource) error {
|
|||
|
||||
l.LocName = s.Name()
|
||||
l.LocCity = s.City()
|
||||
l.LocSuburb = s.Suburb()
|
||||
l.LocState = s.State()
|
||||
l.LocCountry = s.CountryCode()
|
||||
l.LocCategory = s.Category()
|
||||
|
@ -152,10 +148,6 @@ func (l Location) Category() string {
|
|||
return l.LocCategory
|
||||
}
|
||||
|
||||
func (l Location) Suburb() string {
|
||||
return l.LocSuburb
|
||||
}
|
||||
|
||||
func (l Location) Label() string {
|
||||
return l.LocLabel
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ func TestLocation_QueryPlaces(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "U Berliner Rathaus", l.LocName)
|
||||
assert.Equal(t, "Alt-Berlin", l.LocName)
|
||||
assert.Equal(t, "Berlin, Germany", l.LocLabel)
|
||||
})
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ func TestLocation_Assign(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, 189675302, o.PlaceID)
|
||||
assert.Equal(t, "Fernsehturm Berlin", o.LocName)
|
||||
assert.Equal(t, "10178", o.Address.Postcode)
|
||||
assert.Equal(t, "Berlin", o.Address.State)
|
||||
|
@ -84,7 +83,6 @@ func TestLocation_Assign(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.False(t, o.Cached)
|
||||
assert.Equal(t, 79854991, o.PlaceID)
|
||||
assert.Equal(t, "Santa Monica Pier", o.LocName)
|
||||
assert.Equal(t, "90401", o.Address.Postcode)
|
||||
assert.Equal(t, "California", o.Address.State)
|
||||
|
@ -114,7 +112,6 @@ func TestLocation_Assign(t *testing.T) {
|
|||
|
||||
assert.False(t, o.Cached)
|
||||
|
||||
assert.Equal(t, 115198412, o.PlaceID)
|
||||
assert.Equal(t, "Dock A", o.LocName)
|
||||
assert.Equal(t, "8302", o.Address.Postcode)
|
||||
assert.Equal(t, "Zurich", o.Address.State)
|
||||
|
@ -144,7 +141,6 @@ func TestLocation_Assign(t *testing.T) {
|
|||
|
||||
assert.False(t, o.Cached)
|
||||
|
||||
assert.Equal(t, 25410613, o.PlaceID)
|
||||
assert.Equal(t, "TGL", o.LocName)
|
||||
assert.Equal(t, "13405", o.Address.Postcode)
|
||||
assert.Equal(t, "Berlin", o.Address.State)
|
||||
|
@ -174,7 +170,6 @@ func TestLocation_Assign(t *testing.T) {
|
|||
|
||||
assert.False(t, o.Cached)
|
||||
|
||||
assert.Equal(t, 119616937, o.PlaceID)
|
||||
assert.Equal(t, "Pink Beach", o.LocName)
|
||||
assert.Equal(t, "", o.Address.Postcode)
|
||||
assert.Equal(t, "Crete", o.Address.State)
|
||||
|
@ -205,12 +200,11 @@ func TestLocation_Assign(t *testing.T) {
|
|||
|
||||
assert.False(t, o.Cached)
|
||||
|
||||
assert.Equal(t, 164551421, o.PlaceID)
|
||||
assert.Equal(t, "", o.LocName)
|
||||
assert.Equal(t, "07307", o.Address.Postcode)
|
||||
assert.Equal(t, "New Jersey", o.Address.State)
|
||||
assert.Equal(t, "us", o.Address.CountryCode)
|
||||
assert.Equal(t, "United States", o.Address.Country)
|
||||
assert.Equal(t, "United States of America", o.Address.Country)
|
||||
|
||||
var l Location
|
||||
|
||||
|
@ -236,7 +230,6 @@ func TestLocation_Assign(t *testing.T) {
|
|||
|
||||
assert.False(t, o.Cached)
|
||||
|
||||
assert.Equal(t, 98820569, o.PlaceID)
|
||||
assert.Equal(t, "R411", o.LocName)
|
||||
assert.Equal(t, "", o.Address.Postcode)
|
||||
assert.Equal(t, "Eastern Cape", o.Address.State)
|
||||
|
@ -330,17 +323,9 @@ func TestLocation_City(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestLocation_Suburb(t *testing.T) {
|
||||
t.Run("Hauptmarkt", func(t *testing.T) {
|
||||
l := &Location{LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSuburb: "Hauptmarkt"}
|
||||
|
||||
assert.Equal(t, "Hauptmarkt", l.Suburb())
|
||||
})
|
||||
}
|
||||
|
||||
func TestLocation_State(t *testing.T) {
|
||||
t.Run("Bayern", func(t *testing.T) {
|
||||
l := &Location{LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSuburb: "Hauptmarkt"}
|
||||
l := &Location{LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
|
||||
assert.Equal(t, "Bayern", l.State())
|
||||
})
|
||||
|
@ -348,7 +333,7 @@ func TestLocation_State(t *testing.T) {
|
|||
|
||||
func TestLocation_Category(t *testing.T) {
|
||||
t.Run("test", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSuburb: "Hauptmarkt"}
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt"}
|
||||
|
||||
assert.Equal(t, "test", l.Category())
|
||||
})
|
||||
|
@ -356,7 +341,7 @@ func TestLocation_Category(t *testing.T) {
|
|||
|
||||
func TestLocation_Source(t *testing.T) {
|
||||
t.Run("source", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSuburb: "Hauptmarkt", LocSource: "source"}
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSource: "source"}
|
||||
|
||||
assert.Equal(t, "source", l.Source())
|
||||
})
|
||||
|
@ -364,7 +349,7 @@ func TestLocation_Source(t *testing.T) {
|
|||
|
||||
func TestLocation_Place(t *testing.T) {
|
||||
t.Run("test-label", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSuburb: "Hauptmarkt"}
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt", }
|
||||
|
||||
assert.Equal(t, "test-label", l.Label())
|
||||
})
|
||||
|
@ -372,7 +357,7 @@ func TestLocation_Place(t *testing.T) {
|
|||
|
||||
func TestLocation_CountryCode(t *testing.T) {
|
||||
t.Run("de", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSuburb: "Hauptmarkt"}
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt",}
|
||||
|
||||
assert.Equal(t, "de", l.CountryCode())
|
||||
})
|
||||
|
@ -380,7 +365,7 @@ func TestLocation_CountryCode(t *testing.T) {
|
|||
|
||||
func TestLocation_CountryName(t *testing.T) {
|
||||
t.Run("Germany", func(t *testing.T) {
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt", LocSuburb: "Hauptmarkt"}
|
||||
l := &Location{LocCategory: "test", LocCountry: "de", LocCity: "Nürnberg", LocLabel: "test-label", LocState: "Bayern", LocName: "Christkindlesmarkt", }
|
||||
|
||||
assert.Equal(t, "Germany", l.CountryName())
|
||||
})
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build osm
|
||||
|
||||
package osm
|
||||
|
||||
import (
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build osm
|
||||
|
||||
package osm
|
||||
|
||||
import (
|
||||
|
@ -20,7 +22,6 @@ func TestFindLocation(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.False(t, l.Cached)
|
||||
assert.Equal(t, 189675302, l.PlaceID)
|
||||
assert.Equal(t, "Fernsehturm Berlin", l.LocName)
|
||||
assert.Equal(t, "10178", l.Address.Postcode)
|
||||
assert.Equal(t, "Berlin", l.Address.State)
|
||||
|
@ -38,7 +39,6 @@ func TestFindLocation(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.True(t, cached.Cached)
|
||||
assert.Equal(t, 189675302, cached.PlaceID)
|
||||
assert.Equal(t, l.LocName, cached.LocName)
|
||||
assert.Equal(t, l.Address.Postcode, cached.Address.Postcode)
|
||||
assert.Equal(t, l.Address.State, cached.Address.State)
|
||||
|
@ -58,8 +58,7 @@ func TestFindLocation(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.False(t, l.Cached)
|
||||
assert.Equal(t, 189675302, l.PlaceID)
|
||||
assert.Equal(t, "Fernsehturm Berlin", l.LocName)
|
||||
assert.Equal(t, "Menschen Museum", l.LocName)
|
||||
assert.Equal(t, "10178", l.Address.Postcode)
|
||||
assert.Equal(t, "Berlin", l.Address.State)
|
||||
assert.Equal(t, "de", l.Address.CountryCode)
|
||||
|
@ -91,39 +90,6 @@ func TestOSM_State(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
/*
|
||||
func TestOSM_City(t *testing.T) {
|
||||
t.Run("Berlin", func(t *testing.T) {
|
||||
|
||||
a := Address{CountryCode: "de", City: "Berlin", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln", Town: "Hamburg", Village: "Köln", County: "Wiesbaden"}
|
||||
l := &Location{LocCategory: "natural", LocLat: "52.5208", LocLng: "13.40953", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
||||
assert.Equal(t, "Berlin", l.City())
|
||||
})
|
||||
t.Run("Hamburg", func(t *testing.T) {
|
||||
|
||||
a := Address{CountryCode: "de", City: "", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln", Town: "Hamburg", Village: "Köln", County: "Wiesbaden"}
|
||||
l := &Location{LocCategory: "natural", LocLat: "52.5208", LocLng: "13.40953", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
||||
assert.Equal(t, "Hamburg", l.City())
|
||||
})
|
||||
t.Run("Köln", func(t *testing.T) {
|
||||
|
||||
a := Address{CountryCode: "de", City: "", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln", Town: "", Village: "Köln", County: "Wiesbaden"}
|
||||
l := &Location{LocCategory: "natural", LocLat: "52.5208", LocLng: "13.40953", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
||||
assert.Equal(t, "Köln", l.City())
|
||||
})
|
||||
t.Run("Wiesbaden", func(t *testing.T) {
|
||||
|
||||
a := Address{CountryCode: "de", City: "", State: "Berlin", HouseNumber: "63", Suburb: "Neukölln", Town: "", Village: "", County: "Wiesbaden"}
|
||||
l := &Location{LocCategory: "natural", LocLat: "52.5208", LocLng: "13.40953", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
||||
assert.Equal(t, "Wiesbaden", l.City())
|
||||
})
|
||||
t.Run("Frankfurt", func(t *testing.T) {
|
||||
a := Address{CountryCode: "de", City: "Frankfurt", State: "", HouseNumber: "63", Suburb: "Neukölln", Town: "", Village: "", County: ""}
|
||||
l := &Location{LocCategory: "natural", LocLat: "52.5208", LocLng: "13.40953", LocName: "Nice title", LocType: "hill", LocDisplayName: "dipslay name", Address: a}
|
||||
assert.Equal(t, "Frankfurt", l.City())
|
||||
})
|
||||
}
|
||||
*/
|
||||
func TestOSM_Suburb(t *testing.T) {
|
||||
t.Run("Neukölln", func(t *testing.T) {
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
// +build osm
|
||||
|
||||
package osm
|
||||
|
||||
import (
|
||||
|
|
|
@ -17,7 +17,6 @@ type Location struct {
|
|||
LocLng float64 `json:"lng"`
|
||||
LocName string `json:"name"`
|
||||
LocCategory string `json:"category"`
|
||||
LocSuburb string `json:"suburb"`
|
||||
Place Place `json:"place"`
|
||||
Cached bool `json:"-"`
|
||||
}
|
||||
|
@ -96,10 +95,6 @@ func (l Location) City() (result string) {
|
|||
return l.Place.LocCity
|
||||
}
|
||||
|
||||
func (l Location) Suburb() (result string) {
|
||||
return l.LocSuburb
|
||||
}
|
||||
|
||||
func (l Location) CountryCode() (result string) {
|
||||
return l.Place.LocCountry
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func TestFindLocation(t *testing.T) {
|
|||
}
|
||||
|
||||
assert.False(t, l.Cached)
|
||||
assert.Equal(t, "U Berliner Rathaus", l.Name())
|
||||
assert.Equal(t, "Alt-Berlin", l.Name())
|
||||
assert.Equal(t, "Berlin", l.City())
|
||||
assert.Equal(t, "de", l.CountryCode())
|
||||
})
|
||||
|
|
|
@ -28,8 +28,8 @@ func TestMediaFile_Location(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "Himeji", location.City())
|
||||
assert.Equal(t, "Kinki Region", location.State())
|
||||
assert.Equal(t, "Takasago", location.City())
|
||||
assert.Equal(t, "Hyogo Prefecture", location.State())
|
||||
assert.Equal(t, "Japan", location.CountryName())
|
||||
assert.Equal(t, "", location.Category())
|
||||
assert.True(t, strings.HasPrefix(location.ID, "3554df45"))
|
||||
|
@ -43,8 +43,8 @@ func TestMediaFile_Location(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "Himeji", location2.City())
|
||||
assert.Equal(t, "Kinki Region", location2.State())
|
||||
assert.Equal(t, "Takasago", location2.City())
|
||||
assert.Equal(t, "Hyogo Prefecture", location2.State())
|
||||
})
|
||||
t.Run("cat_brown.jpg", func(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
var log = event.Log
|
||||
var Level = 18
|
||||
var Level = 21
|
||||
|
||||
func Token(lat, lng float64) string {
|
||||
return TokenLevel(lat, lng, Level)
|
||||
|
|
Loading…
Reference in a new issue