Work in progress
This commit is contained in:
parent
3d85aff1a9
commit
0ebd6300cd
@ -42,7 +42,13 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print(request)
|
var geo *geoContext
|
||||||
|
if request.Geo != nil {
|
||||||
|
geo.latitude = request.Geo.Latitude
|
||||||
|
geo.longitude = request.Geo.Longitude
|
||||||
|
}
|
||||||
|
|
||||||
|
context := queryContext{geo, convertFeatures(request.Profile), request.WalkingDist}
|
||||||
|
|
||||||
// function runQuery(query, callback) {
|
// function runQuery(query, callback) {
|
||||||
// query.profile = fixupProfile(query.profile);
|
// query.profile = fixupProfile(query.profile);
|
||||||
|
5
types.go
5
types.go
@ -70,9 +70,7 @@ type jsonRemoveCategoryResponse struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type queryContext struct {
|
type queryContext struct {
|
||||||
geo geoContext
|
geo *geoContext
|
||||||
latitude float64
|
|
||||||
longitude float64
|
|
||||||
profile featureMap
|
profile featureMap
|
||||||
walkingDist float64
|
walkingDist float64
|
||||||
}
|
}
|
||||||
@ -95,7 +93,6 @@ type queryBounds struct {
|
|||||||
type geoContext struct {
|
type geoContext struct {
|
||||||
latitude float64
|
latitude float64
|
||||||
longitude float64
|
longitude float64
|
||||||
valid bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type record struct {
|
type record struct {
|
||||||
|
11
util.go
11
util.go
@ -29,6 +29,15 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func convertFeatures(features jsonFeatureMap) featureMap {
|
||||||
|
resultMap := make(featureMap)
|
||||||
|
for key, value := range features {
|
||||||
|
resultMap[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultMap
|
||||||
|
}
|
||||||
|
|
||||||
func innerProduct(features1 featureMap, features2 featureMap) float64 {
|
func innerProduct(features1 featureMap, features2 featureMap) float64 {
|
||||||
var result float64
|
var result float64
|
||||||
for key, value1 := range features1 {
|
for key, value1 := range features1 {
|
||||||
@ -100,7 +109,7 @@ func computeRecordGeo(entries records, context queryContext) {
|
|||||||
distUserMax := 0.0
|
distUserMax := 0.0
|
||||||
|
|
||||||
for _, record := range entries {
|
for _, record := range entries {
|
||||||
if context.geo.valid {
|
if context.geo != nil {
|
||||||
userPoint := geo.NewPoint(context.geo.latitude, context.geo.longitude)
|
userPoint := geo.NewPoint(context.geo.latitude, context.geo.longitude)
|
||||||
recordPoint := geo.NewPoint(record.geo.latitude, context.geo.longitude)
|
recordPoint := geo.NewPoint(record.geo.latitude, context.geo.longitude)
|
||||||
record.distanceToUser = userPoint.GreatCircleDistance(recordPoint)
|
record.distanceToUser = userPoint.GreatCircleDistance(recordPoint)
|
||||||
|
Loading…
Reference in New Issue
Block a user