From 0ebd6300cdd46dccfa4e94092e0a755d41db4a9c Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 24 Mar 2015 22:55:25 +0900 Subject: [PATCH] Work in progress --- server.go | 8 +++++++- types.go | 5 +---- util.go | 11 ++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index 6b51a75..bfc66c7 100644 --- a/server.go +++ b/server.go @@ -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); diff --git a/types.go b/types.go index 42699d2..5e411fa 100644 --- a/types.go +++ b/types.go @@ -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 { diff --git a/util.go b/util.go index eeb31b1..c073d42 100644 --- a/util.go +++ b/util.go @@ -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)