1

Work in progress

This commit is contained in:
Alex Yatskov 2015-06-28 13:48:53 +09:00
parent c91a8a5c9c
commit daa6941672
4 changed files with 29 additions and 6 deletions

View File

@ -52,14 +52,24 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
entries := getRecords(queryContext{geo, request.Profile, request.WalkingDist}) entries := getRecords(queryContext{geo, request.Profile, request.WalkingDist})
features := fixFeatures(request.Features) features := fixFeatures(request.Features)
foundEntries := findRecords(entries, features, request.MinScore) minScore := request.MinScore
if request.Bracket != nil {
bracket := namedBracket{
request.Bracket.Name,
request.Bracket.Min,
request.Bracket.Max}
minScore = calibrateMinScore(entries, features, bracket)
}
foundEntries := findRecords(entries, features, minScore)
sorter := recordSorter{entries: foundEntries, key: request.SortKey, ascending: request.SortAsc} sorter := recordSorter{entries: foundEntries, key: request.SortKey, ascending: request.SortAsc}
sorter.sort() sorter.sort()
response := jsonQueryResponse{ response := jsonQueryResponse{
Count: len(foundEntries), Count: len(foundEntries),
Columns: make(map[string]jsonColumn), Columns: make(map[string]jsonColumn),
MinScore: request.MinScore, MinScore: minScore,
Records: make([]jsonRecord, 0)} Records: make([]jsonRecord, 0)}
for name, value := range features { for name, value := range features {
@ -72,7 +82,7 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
entries, entries,
features, features,
name, name,
request.MinScore, minScore,
request.Resolution) request.Resolution)
for _, hint := range hints { for _, hint := range hints {

View File

@ -27,7 +27,16 @@
function onStateChanged(name, value, bracket) { function onStateChanged(name, value, bracket) {
_ctx.query.features[name] = value; _ctx.query.features[name] = value;
_ctx.query.bracket = bracket === null ? null : {name: name, bracket: bracket}; if (bracket === null) {
_ctx.query.bracket = null;
}
else {
_ctx.query.bracket = {
name: name,
min: bracket.min,
max: bracket.max
};
}
$.post('/query', JSON.stringify(_ctx.query), function(results) { $.post('/query', JSON.stringify(_ctx.query), function(results) {
saveSnapshot(results); saveSnapshot(results);

View File

@ -80,8 +80,8 @@ type jsonBracket struct {
} }
type jsonNamedBracket struct { type jsonNamedBracket struct {
Bracket jsonBracket `json:"bracket"` jsonBracket
Name string `json:"name"` Name string `json:"name"`
} }
type jsonQueryResponse struct { type jsonQueryResponse struct {

View File

@ -100,6 +100,10 @@ func findRecords(entries records, features featureMap, minScore float64) records
return foundEntries return foundEntries
} }
func calibrateMinScore(entries records, features featureMap, bracket namedBracket) float64 {
return 2
}
func project(entries records, features featureMap, featureName string, minScore float64, steps int) []queryProjection { func project(entries records, features featureMap, featureName string, minScore float64, steps int) []queryProjection {
sampleFeatures := make(featureMap) sampleFeatures := make(featureMap)
for key, value := range features { for key, value := range features {