1
This commit is contained in:
Alex Yatskov 2015-03-25 18:22:57 +09:00
parent b2f9096841
commit 2a32300421
2 changed files with 29 additions and 25 deletions

View File

@ -72,6 +72,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
jsonHint := jsonProjection{ jsonHint := jsonProjection{
Sample: hint.sample, Sample: hint.sample,
Stats: jsonStats{Count: hint.stats.count, Compatibility: hint.stats.compatibility}} Stats: jsonStats{Count: hint.stats.count, Compatibility: hint.stats.compatibility}}
column.Hints = append(column.Hints, jsonHint) column.Hints = append(column.Hints, jsonHint)
} }
@ -268,5 +269,5 @@ func main() {
http.HandleFunc("/access", accessReview) http.HandleFunc("/access", accessReview)
http.Handle("/", http.FileServer(http.Dir(dir))) http.Handle("/", http.FileServer(http.Dir(dir)))
log.Fatal(http.ListenAndServe(":3000", nil)) log.Fatal(http.ListenAndServe(":8080", nil))
} }

51
util.go
View File

@ -118,35 +118,35 @@ func computeRecordGeo(entries records, context queryContext) {
distUserMin := math.MaxFloat64 distUserMin := math.MaxFloat64
distUserMax := 0.0 distUserMax := 0.0
for _, record := range entries { for index := range entries {
entry := &entries[index]
if context.geo != nil { 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) entryPoint := geo.NewPoint(entry.geo.latitude, context.geo.longitude)
record.distanceToUser = userPoint.GreatCircleDistance(recordPoint) entry.distanceToUser = userPoint.GreatCircleDistance(entryPoint)
} }
if record.distanceToUser < distUserMin { distUserMin = math.Min(entry.distanceToUser, distUserMin)
distUserMin = record.distanceToUser distUserMax = math.Max(entry.distanceToUser, distUserMax)
}
if record.distanceToUser > distUserMax {
distUserMax = record.distanceToUser
}
} }
distUserRange := distUserMax - distUserMin distUserRange := distUserMax - distUserMin
for _, record := range entries { for index := range entries {
nearby := -((record.distanceToUser-distUserMin)/distUserRange - 0.5) * 2.0 entry := &entries[index]
accessible := 1.0 - (record.distanceToStn / context.walkingDist) var accessible, nearby float64
if accessible < -1.0 { if distUserRange > 0 {
accessible = 1.0 nearby = -((entry.distanceToUser-distUserMin)/distUserRange - 0.5) * 2.0
} else if accessible > 1.0 {
accessible = 1.0 accessible = 1.0 - (entry.distanceToStn / context.walkingDist)
accessible = math.Max(accessible, -1.0)
accessible = math.Min(accessible, 1.0)
} }
record.features["nearby"] = nearby entry.features["nearby"] = nearby
record.features["accessible"] = accessible entry.features["accessible"] = accessible
} }
} }
@ -234,14 +234,14 @@ func getRecords(context queryContext) records {
distanceToStn: distanceToStn, distanceToStn: distanceToStn,
closestStn: closestStn, closestStn: closestStn,
accessCount: accessCount, accessCount: accessCount,
geo: geoContext{latitude, longitude},
id: id} id: id}
entry.features = make(featureMap) entry.features = featureMap{
entry.features["delicious"] = delicious "delicious": delicious,
entry.features["accomodating"] = accomodating "accomodating": accomodating,
entry.features["affordable"] = affordable "affordable": affordable,
entry.features["atmospheric"] = atmospheric "atmospheric": atmospheric}
entry.geo = geoContext{latitude, longitude}
entries = append(entries, entry) entries = append(entries, entry)
} }
@ -249,5 +249,8 @@ func getRecords(context queryContext) records {
log.Fatal(err) log.Fatal(err)
} }
computeRecordPopularity(entries, context)
computeRecordGeo(entries, context)
return entries return entries
} }