Work in progress
This commit is contained in:
parent
5b6e883e4c
commit
1fe44e827a
82
server.go
82
server.go
@ -48,53 +48,57 @@ func executeQuery(rw http.ResponseWriter, req *http.Request) {
|
|||||||
geo.longitude = request.Geo.Longitude
|
geo.longitude = request.Geo.Longitude
|
||||||
}
|
}
|
||||||
|
|
||||||
context := queryContext{geo, convertFeatures(request.Profile), request.WalkingDist}
|
context := queryContext{geo, request.Profile, request.WalkingDist}
|
||||||
entries := getRecords(context)
|
entries := getRecords(context)
|
||||||
|
|
||||||
foundEntries := findRecords(entries, featureMap(request.Features), request.MinScore)
|
foundEntries := findRecords(entries, request.Features, request.MinScore)
|
||||||
|
|
||||||
// function runQuery(query, callback) {
|
var response jsonQueryResponse
|
||||||
// query.profile = fixupProfile(query.profile);
|
for featureName, featureValue := range request.Features {
|
||||||
// query.features = fixupFeatures(query.features);
|
column := jsonColumn{Value: featureValue, Steps: request.HintSteps}
|
||||||
|
|
||||||
// var context = {
|
hints := project(
|
||||||
// geo: query.geo,
|
foundEntries,
|
||||||
// profile: query.profile,
|
request.Features,
|
||||||
// walkingDist: query.walkingDist * 1000.0
|
featureName,
|
||||||
// };
|
request.MinScore,
|
||||||
|
queryBounds{min: request.Range.Min, max: request.Range.Max},
|
||||||
|
request.HintSteps)
|
||||||
|
|
||||||
// getRecords(context, function(data) {
|
for _, hint := range hints {
|
||||||
// var searchResults = findRecords(
|
jsonHint := jsonProjection{
|
||||||
// data,
|
Sample: hint.sample,
|
||||||
// query.features,
|
Stats: jsonStats{Count: hint.stats.count, Compatibility: hint.stats.compatibility}}
|
||||||
// query.minScore
|
column.Hints = append(column.Hints, jsonHint)
|
||||||
// );
|
}
|
||||||
|
|
||||||
// var graphColumns = {};
|
response.Columns[featureName] = column
|
||||||
// for (var feature in query.features) {
|
}
|
||||||
// var searchHints = buildHints(
|
|
||||||
// data,
|
|
||||||
// query.features,
|
|
||||||
// feature,
|
|
||||||
// query.minScore,
|
|
||||||
// query.range,
|
|
||||||
// query.hintSteps
|
|
||||||
// );
|
|
||||||
|
|
||||||
// graphColumns[feature] = {
|
for entryIndex, entryValue := range foundEntries {
|
||||||
// value: query.features[feature],
|
if entryIndex > request.MaxResults {
|
||||||
// hints: searchHints,
|
break
|
||||||
// steps: query.hintSteps
|
}
|
||||||
// };
|
|
||||||
// }
|
|
||||||
|
|
||||||
// callback({
|
jsonEntry := jsonRecord{
|
||||||
// columns: graphColumns,
|
Name: entryValue.name,
|
||||||
// items: searchResults.slice(0, query.maxResults),
|
Score: entryValue.score,
|
||||||
// count: searchResults.length
|
DistanceToUser: entryValue.distanceToUser,
|
||||||
// });
|
DistanceToStn: entryValue.distanceToStn,
|
||||||
// });
|
ClosestStn: entryValue.closestStn,
|
||||||
// }
|
AccessCount: entryValue.accessCount,
|
||||||
|
Id: entryValue.id}
|
||||||
|
|
||||||
|
response.Items = append(response.Items, jsonEntry)
|
||||||
|
}
|
||||||
|
|
||||||
|
js, err := json.Marshal(response)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
rw.Header().Set("Content-Type", "application/json")
|
||||||
|
rw.Write(js)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCategories(rw http.ResponseWriter, req *http.Request) {
|
func getCategories(rw http.ResponseWriter, req *http.Request) {
|
||||||
|
8
types.go
8
types.go
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type jsonFeatureMap map[string]float64
|
type featureMap map[string]float64
|
||||||
|
|
||||||
type jsonRange struct {
|
type jsonRange struct {
|
||||||
Max float64 `json:"max"`
|
Max float64 `json:"max"`
|
||||||
@ -36,12 +36,12 @@ type jsonGeo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type jsonQueryRequest struct {
|
type jsonQueryRequest struct {
|
||||||
Features jsonFeatureMap `json:"features"`
|
Features featureMap `json:"features"`
|
||||||
Geo *jsonGeo `json:"geo"`
|
Geo *jsonGeo `json:"geo"`
|
||||||
HintSteps int `json:"hintSteps"`
|
HintSteps int `json:"hintSteps"`
|
||||||
MaxResults int `json:"maxResults"`
|
MaxResults int `json:"maxResults"`
|
||||||
MinScore float64 `json:"minScore"`
|
MinScore float64 `json:"minScore"`
|
||||||
Profile jsonFeatureMap `json:"profile"`
|
Profile featureMap `json:"profile"`
|
||||||
Range jsonRange `json:"range"`
|
Range jsonRange `json:"range"`
|
||||||
WalkingDist float64 `json:"walkingDist"`
|
WalkingDist float64 `json:"walkingDist"`
|
||||||
}
|
}
|
||||||
@ -154,5 +154,3 @@ func (slice records) Less(i, j int) bool {
|
|||||||
func (slice records) Swap(i, j int) {
|
func (slice records) Swap(i, j int) {
|
||||||
slice[i], slice[j] = slice[j], slice[i]
|
slice[i], slice[j] = slice[j], slice[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
type featureMap map[interface{}]float64
|
|
||||||
|
35
util.go
35
util.go
@ -27,17 +27,9 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func convertFeatures(features jsonFeatureMap) featureMap {
|
|
||||||
resultMap := make(featureMap)
|
|
||||||
for key, value := range features {
|
|
||||||
resultMap[key] = value
|
|
||||||
}
|
|
||||||
|
|
||||||
return resultMap
|
|
||||||
}
|
|
||||||
|
|
||||||
func innerProduct(features1 featureMap, features2 featureMap) float64 {
|
func innerProduct(features1 featureMap, features2 featureMap) float64 {
|
||||||
var result float64
|
var result float64
|
||||||
for key, value1 := range features1 {
|
for key, value1 := range features1 {
|
||||||
@ -171,7 +163,7 @@ func computeRecordPopularity(entries records, context queryContext) {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
recordProfile[categoryId] = categoryValue
|
recordProfile[strconv.Itoa(categoryId)] = categoryValue
|
||||||
}
|
}
|
||||||
if err := groupRows.Err(); err != nil {
|
if err := groupRows.Err(); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
@ -205,9 +197,28 @@ func getRecords(context queryContext) records {
|
|||||||
var delicious, accomodating, affordable, atmospheric, latitude, longitude, distanceToStn float64
|
var delicious, accomodating, affordable, atmospheric, latitude, longitude, distanceToStn float64
|
||||||
var accessCount, id int
|
var accessCount, id int
|
||||||
|
|
||||||
rows.Scan(&name, &url, &delicious, &accomodating, &affordable, &atmospheric, &latitude, &longitude, &distanceToStn, &closestStn, &accessCount, &id)
|
rows.Scan(
|
||||||
|
&name,
|
||||||
|
&url,
|
||||||
|
&delicious,
|
||||||
|
&accomodating,
|
||||||
|
&affordable,
|
||||||
|
&atmospheric,
|
||||||
|
&latitude,
|
||||||
|
&longitude,
|
||||||
|
&distanceToStn,
|
||||||
|
&closestStn,
|
||||||
|
&accessCount,
|
||||||
|
&id)
|
||||||
|
|
||||||
|
entry := record{
|
||||||
|
name: name,
|
||||||
|
url: url,
|
||||||
|
distanceToStn: distanceToStn,
|
||||||
|
closestStn: closestStn,
|
||||||
|
accessCount: accessCount,
|
||||||
|
id: id}
|
||||||
|
|
||||||
entry := record{name: name, url: url, distanceToStn: distanceToStn, closestStn: closestStn, accessCount: accessCount, id: id}
|
|
||||||
entry.features["delicious"] = delicious
|
entry.features["delicious"] = delicious
|
||||||
entry.features["accomodating"] = accomodating
|
entry.features["accomodating"] = accomodating
|
||||||
entry.features["affordable"] = affordable
|
entry.features["affordable"] = affordable
|
||||||
|
Loading…
Reference in New Issue
Block a user