1

Compute feature ranges

This commit is contained in:
Alex Yatskov 2015-06-27 12:48:44 +09:00
parent a9a0ab56ca
commit 273e4c34d8
2 changed files with 31 additions and 10 deletions

View File

@ -28,6 +28,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"log" "log"
"math"
"net/http" "net/http"
"strings" "strings"
@ -57,6 +58,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
response := jsonQueryResponse{ response := jsonQueryResponse{
Count: len(foundEntries), Count: len(foundEntries),
Ranges: make(map[string]jsonRange),
Columns: make(map[string]jsonColumn), Columns: make(map[string]jsonColumn),
Records: make([]jsonRecord, 0)} Records: make([]jsonRecord, 0)}
@ -78,21 +80,34 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
response.Columns[name] = column response.Columns[name] = column
} }
for index, value := range foundEntries { for index, record := range foundEntries {
for feature, value := range record.features {
rng, ok := response.Ranges[feature]
if ok {
rng.Max = math.Max(rng.Max, value)
rng.Min = math.Min(rng.Min, value)
} else {
rng.Max = value
rng.Min = value
}
response.Ranges[feature] = rng
}
if index >= request.MaxResults { if index >= request.MaxResults {
break break
} }
item := jsonRecord{ item := jsonRecord{
Name: value.name, Name: record.name,
Url: value.url, Url: record.url,
Score: value.score, Score: record.score,
Compatibility: value.compatibility, Compatibility: record.compatibility,
DistanceToUser: value.distanceToUser, DistanceToUser: record.distanceToUser,
DistanceToStn: value.distanceToStn, DistanceToStn: record.distanceToStn,
ClosestStn: value.closestStn, ClosestStn: record.closestStn,
AccessCount: value.accessCount, AccessCount: record.accessCount,
Id: value.id} Id: record.id}
response.Records = append(response.Records, item) response.Records = append(response.Records, item)
} }

View File

@ -72,9 +72,15 @@ type jsonRecord struct {
Url string `json:"url"` Url string `json:"url"`
} }
type jsonRange struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
}
type jsonQueryResponse struct { type jsonQueryResponse struct {
Columns map[string]jsonColumn `json:"columns"` Columns map[string]jsonColumn `json:"columns"`
Count int `json:"count"` Count int `json:"count"`
Ranges map[string]jsonRange `json:"ranges"`
Records []jsonRecord `json:"records"` Records []jsonRecord `json:"records"`
} }