Cleanup
This commit is contained in:
parent
2a32300421
commit
8aaf32c866
@ -47,13 +47,12 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
geo = &geoContext{latitude: request.Geo.Latitude, longitude: request.Geo.Longitude}
|
geo = &geoContext{latitude: request.Geo.Latitude, longitude: request.Geo.Longitude}
|
||||||
}
|
}
|
||||||
|
|
||||||
context := queryContext{geo, request.Profile, request.WalkingDist}
|
entries := getRecords(queryContext{geo, request.Profile, request.WalkingDist})
|
||||||
entries := getRecords(context)
|
|
||||||
features := fixFeatures(request.Features)
|
features := fixFeatures(request.Features)
|
||||||
|
|
||||||
foundEntries := findRecords(entries, features, request.MinScore)
|
foundEntries := findRecords(entries, features, request.MinScore)
|
||||||
|
|
||||||
response := jsonQueryResponse{
|
response := jsonQueryResponse{
|
||||||
|
Count: len(foundEntries),
|
||||||
Columns: make(map[string]jsonColumn),
|
Columns: make(map[string]jsonColumn),
|
||||||
Items: make([]jsonRecord, 0)}
|
Items: make([]jsonRecord, 0)}
|
||||||
|
|
||||||
@ -84,7 +83,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonEntry := jsonRecord{
|
item := jsonRecord{
|
||||||
Name: value.name,
|
Name: value.name,
|
||||||
Score: value.score,
|
Score: value.score,
|
||||||
DistanceToUser: value.distanceToUser,
|
DistanceToUser: value.distanceToUser,
|
||||||
@ -93,7 +92,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
AccessCount: value.accessCount,
|
AccessCount: value.accessCount,
|
||||||
Id: value.id}
|
Id: value.id}
|
||||||
|
|
||||||
response.Items = append(response.Items, jsonEntry)
|
response.Items = append(response.Items, item)
|
||||||
}
|
}
|
||||||
|
|
||||||
js, err := json.Marshal(response)
|
js, err := json.Marshal(response)
|
||||||
|
12
util.go
12
util.go
@ -91,6 +91,7 @@ func findRecords(entries records, features featureMap, minScore float64) records
|
|||||||
var foundEntries records
|
var foundEntries records
|
||||||
|
|
||||||
walkMatches(entries, features, minScore, func(record record, score float64) {
|
walkMatches(entries, features, minScore, func(record record, score float64) {
|
||||||
|
record.score = score
|
||||||
foundEntries = append(foundEntries, record)
|
foundEntries = append(foundEntries, record)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -151,8 +152,10 @@ func computeRecordGeo(entries records, context queryContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func computeRecordPopularity(entries records, context queryContext) {
|
func computeRecordPopularity(entries records, context queryContext) {
|
||||||
for _, record := range entries {
|
for index := range entries {
|
||||||
historyRows, err := db.Query("SELECT id FROM history WHERE reviewId = (?)", record.id)
|
entry := &entries[index]
|
||||||
|
|
||||||
|
historyRows, err := db.Query("SELECT id FROM history WHERE reviewId = (?)", entry.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -193,12 +196,9 @@ func computeRecordPopularity(entries records, context queryContext) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var compatibility float64
|
|
||||||
if groupCount > 0 {
|
if groupCount > 0 {
|
||||||
compatibility = groupSum / float64(groupCount)
|
entry.compatibility = groupSum / float64(groupCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
record.features["compatibility"] = compatibility
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user