1
This commit is contained in:
Alex Yatskov 2015-08-23 23:20:32 +09:00
parent 9202bcc59d
commit d253afeaf7

31
util.go
View File

@ -109,8 +109,10 @@ func walkMatches(entries []record, features map[string]float64, modes map[string
} }
func statRecords(entries []record, features map[string]float64, modes map[string]modeType, minScore float64) (float64, int) { func statRecords(entries []record, features map[string]float64, modes map[string]modeType, minScore float64) (float64, int) {
var compatibility float64 var (
var count int compatibility float64
count int
)
walkMatches(entries, features, modes, minScore, func(entry record, score float64) { walkMatches(entries, features, modes, minScore, func(entry record, score float64) {
compatibility += entry.Compatibility compatibility += entry.Compatibility
@ -198,14 +200,18 @@ func computeRecordsGeo(entries []record, context queryContext) {
} }
func computeRecordCompat(entry *record, context queryContext, wg *sync.WaitGroup) { func computeRecordCompat(entry *record, context queryContext, wg *sync.WaitGroup) {
defer wg.Done()
historyRows, err := db.Query("SELECT id FROM history WHERE reviewId = (?)", entry.Id) historyRows, err := db.Query("SELECT id FROM history WHERE reviewId = (?)", entry.Id)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
defer historyRows.Close() defer historyRows.Close()
var groupSum float64 var (
var groupCount int groupSum float64
groupCount int
)
for historyRows.Next() { for historyRows.Next() {
var historyId int var historyId int
@ -221,8 +227,10 @@ func computeRecordCompat(entry *record, context queryContext, wg *sync.WaitGroup
recordProfile := make(map[string]float64) recordProfile := make(map[string]float64)
for groupRows.Next() { for groupRows.Next() {
var categoryId int var (
var categoryValue float64 categoryId int
categoryValue float64
)
if err := groupRows.Scan(&categoryId, &categoryValue); err != nil { if err := groupRows.Scan(&categoryId, &categoryValue); err != nil {
log.Fatal(err) log.Fatal(err)
@ -244,8 +252,6 @@ func computeRecordCompat(entry *record, context queryContext, wg *sync.WaitGroup
if groupCount > 0 { if groupCount > 0 {
entry.Compatibility = groupSum / float64(groupCount) entry.Compatibility = groupSum / float64(groupCount)
} }
wg.Done()
} }
func computeRecordsCompat(entries []record, context queryContext) { func computeRecordsCompat(entries []record, context queryContext) {
@ -278,9 +284,12 @@ func getRecords(context queryContext) []record {
var entries []record var entries []record
for recordRows.Next() { for recordRows.Next() {
var name, url, closestStn string var (
var delicious, accommodating, affordable, atmospheric, latitude, longitude, distanceToStn float64 name, url, closestStn string
var accessCount, id int delicious, accommodating, affordable, atmospheric float64
latitude, longitude, distanceToStn float64
accessCount, id int
)
recordRows.Scan( recordRows.Scan(
&name, &name,