1

Work in progress

This commit is contained in:
Alex Yatskov 2015-03-24 22:55:25 +09:00
parent 3d85aff1a9
commit 0ebd6300cd
3 changed files with 18 additions and 6 deletions

View File

@ -42,7 +42,13 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
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) {
// query.profile = fixupProfile(query.profile);

View File

@ -70,9 +70,7 @@ type jsonRemoveCategoryResponse struct {
}
type queryContext struct {
geo geoContext
latitude float64
longitude float64
geo *geoContext
profile featureMap
walkingDist float64
}
@ -95,7 +93,6 @@ type queryBounds struct {
type geoContext struct {
latitude float64
longitude float64
valid bool
}
type record struct {

11
util.go
View File

@ -29,6 +29,15 @@ import (
"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 {
var result float64
for key, value1 := range features1 {
@ -100,7 +109,7 @@ func computeRecordGeo(entries records, context queryContext) {
distUserMax := 0.0
for _, record := range entries {
if context.geo.valid {
if context.geo != nil {
userPoint := geo.NewPoint(context.geo.latitude, context.geo.longitude)
recordPoint := geo.NewPoint(record.geo.latitude, context.geo.longitude)
record.distanceToUser = userPoint.GreatCircleDistance(recordPoint)