2015-03-24 06:17:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Alex Yatskov <alex@foosoft.net>
|
|
|
|
* Author: Alex Yatskov <alex@foosoft.net>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
2015-03-25 03:33:41 +00:00
|
|
|
type featureMap map[string]float64
|
2015-03-24 13:36:53 +00:00
|
|
|
|
2015-03-25 10:10:34 +00:00
|
|
|
type jsonAccessRequest struct {
|
|
|
|
Id int `json:"id"`
|
|
|
|
Profile featureMap `json:"profile"`
|
|
|
|
}
|
|
|
|
|
2015-03-25 11:17:12 +00:00
|
|
|
type jsonGeoData struct {
|
2015-03-24 13:36:53 +00:00
|
|
|
Latitude float64 `json:"latitude"`
|
|
|
|
Longitude float64 `json:"longitude"`
|
|
|
|
}
|
|
|
|
|
2015-03-25 03:00:54 +00:00
|
|
|
type jsonQueryRequest struct {
|
2015-03-25 11:17:12 +00:00
|
|
|
Features featureMap `json:"features"`
|
|
|
|
Geo *jsonGeoData `json:"geo"`
|
|
|
|
HintSteps int `json:"hintSteps"`
|
|
|
|
MaxResults int `json:"maxResults"`
|
|
|
|
MinScore float64 `json:"minScore"`
|
|
|
|
Profile featureMap `json:"profile"`
|
|
|
|
WalkingDist float64 `json:"walkingDist"`
|
2015-03-24 13:36:53 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 03:00:54 +00:00
|
|
|
type jsonColumn struct {
|
|
|
|
Hints []jsonProjection `json:"hints"`
|
|
|
|
Steps int `json:"steps"`
|
|
|
|
Value float64 `json:"value"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type jsonProjection struct {
|
|
|
|
Compatibility float64 `json:"compatibility"`
|
|
|
|
Count int `json:"count"`
|
2015-03-25 11:17:12 +00:00
|
|
|
Sample float64 `json:"sample"`
|
2015-03-25 03:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type jsonRecord struct {
|
|
|
|
AccessCount int `json:"accessCount"`
|
2015-03-25 11:17:12 +00:00
|
|
|
ClosestStn string `json:"closestStn"`
|
2015-03-26 04:09:58 +00:00
|
|
|
Compatibility float64 `json:"compatibility"`
|
2015-03-25 11:17:12 +00:00
|
|
|
DistanceToStn float64 `json:"distanceToStn"`
|
|
|
|
DistanceToUser float64 `json:"distanceToUser"`
|
2015-03-25 03:00:54 +00:00
|
|
|
Id int `json:"id"`
|
2015-03-25 11:17:12 +00:00
|
|
|
Name string `json:"name"`
|
|
|
|
Score float64 `json:"score"`
|
2015-03-26 03:18:43 +00:00
|
|
|
Url string `json:"url"`
|
2015-03-25 03:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type jsonQueryResponse struct {
|
|
|
|
Columns map[string]jsonColumn `json:"columns"`
|
|
|
|
Count int `json:"count"`
|
2015-03-25 11:17:12 +00:00
|
|
|
Records []jsonRecord `json:"records"`
|
2015-03-25 03:00:54 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 13:36:53 +00:00
|
|
|
type jsonCategory struct {
|
|
|
|
Description string `json:"description"`
|
|
|
|
Id int `json:"id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type jsonAddCategoryRequest struct {
|
|
|
|
Description string `json:"description"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type jsonAddCategoryResponse struct {
|
|
|
|
Description string `json:"description"`
|
|
|
|
Id int `json:"id"`
|
|
|
|
Success bool `json:"success"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type jsonRemoveCategoryRequest struct {
|
|
|
|
Id int `json:"id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type jsonRemoveCategoryResponse struct {
|
|
|
|
Success bool `json:"success"`
|
|
|
|
}
|
|
|
|
|
2015-03-24 11:04:52 +00:00
|
|
|
type queryContext struct {
|
2015-03-25 11:17:12 +00:00
|
|
|
geo *geoData
|
2015-03-24 11:04:52 +00:00
|
|
|
profile featureMap
|
2015-03-24 08:29:24 +00:00
|
|
|
walkingDist float64
|
|
|
|
}
|
|
|
|
|
2015-03-24 11:04:52 +00:00
|
|
|
type queryProjection struct {
|
2015-03-24 08:29:24 +00:00
|
|
|
compatibility float64
|
2015-03-24 06:17:37 +00:00
|
|
|
count int
|
2015-03-25 11:17:12 +00:00
|
|
|
sample float64
|
2015-03-24 06:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-25 11:17:12 +00:00
|
|
|
type geoData struct {
|
2015-03-24 08:58:35 +00:00
|
|
|
latitude float64
|
|
|
|
longitude float64
|
|
|
|
}
|
|
|
|
|
2015-03-24 11:04:52 +00:00
|
|
|
type record struct {
|
2015-03-24 06:17:37 +00:00
|
|
|
accessCount int
|
2015-03-25 03:00:54 +00:00
|
|
|
closestStn string
|
2015-03-24 08:29:24 +00:00
|
|
|
compatibility float64
|
|
|
|
distanceToStn float64
|
|
|
|
distanceToUser float64
|
2015-03-24 11:04:52 +00:00
|
|
|
features featureMap
|
2015-03-25 11:17:12 +00:00
|
|
|
geo geoData
|
2015-03-24 06:17:37 +00:00
|
|
|
id int
|
|
|
|
name string
|
2015-03-24 08:29:24 +00:00
|
|
|
score float64
|
2015-03-25 03:00:54 +00:00
|
|
|
url string
|
2015-03-24 06:17:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-24 11:04:52 +00:00
|
|
|
type records []record
|
2015-03-24 06:17:37 +00:00
|
|
|
|
2015-03-24 11:04:52 +00:00
|
|
|
func (slice records) Len() int {
|
2015-03-24 06:17:37 +00:00
|
|
|
return len(slice)
|
|
|
|
}
|
|
|
|
|
2015-03-24 11:04:52 +00:00
|
|
|
func (slice records) Less(i, j int) bool {
|
2015-03-24 06:17:37 +00:00
|
|
|
return slice[i].score > slice[j].score
|
|
|
|
}
|
|
|
|
|
2015-03-24 11:04:52 +00:00
|
|
|
func (slice records) Swap(i, j int) {
|
2015-03-24 06:17:37 +00:00
|
|
|
slice[i], slice[j] = slice[j], slice[i]
|
|
|
|
}
|