1

Update calculation for "nearby"

This commit is contained in:
Alex Yatskov 2015-11-22 14:34:40 +09:00
parent 5fd7c7e882
commit a3c8178a15

15
util.go
View File

@ -27,6 +27,7 @@ import (
"math" "math"
"strconv" "strconv"
"github.com/GaryBoone/GoStats/stats"
"github.com/kellydunn/golang-geo" "github.com/kellydunn/golang-geo"
) )
@ -161,9 +162,7 @@ func project(entries []record, features map[string]float64, modes map[string]mod
} }
func computeRecordGeo(entries []record, context queryContext) { func computeRecordGeo(entries []record, context queryContext) {
distUserMin := math.MaxFloat64 var dist stats.Stats
distUserMax := 0.0
for index := range entries { for index := range entries {
entry := &entries[index] entry := &entries[index]
@ -173,18 +172,18 @@ func computeRecordGeo(entries []record, context queryContext) {
entry.DistanceToUser = userPoint.GreatCircleDistance(entryPoint) entry.DistanceToUser = userPoint.GreatCircleDistance(entryPoint)
} }
distUserMin = math.Min(entry.DistanceToUser, distUserMin) dist.Update(entry.DistanceToUser)
distUserMax = math.Max(entry.DistanceToUser, distUserMax)
} }
distUserRange := distUserMax - distUserMin distRange := dist.Max() - dist.Min()
distMean := dist.Mean()
for index := range entries { for index := range entries {
entry := &entries[index] entry := &entries[index]
var nearby float64 var nearby float64
if distUserRange > 0.0 { if distRange > 0.0 {
nearby = 1.0 - ((entry.DistanceToUser-distUserMin)/distUserRange)*2 nearby = -((entry.DistanceToUser - distMean) / distRange)
} }
var accessible float64 var accessible float64