-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfrequency_tile.go
67 lines (54 loc) · 1.55 KB
/
frequency_tile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package citus
import (
"encoding/json"
"github.com/unchartedsoftware/veldt"
"github.com/unchartedsoftware/veldt/binning"
)
// FrequencyTile represents a citus implementation of the frequency tile.
type FrequencyTile struct {
Bivariate
Frequency
Tile
}
// NewFrequencyTile instantiates and returns a new tile struct.
func NewFrequencyTile(host, port string) veldt.TileCtor {
return func() (veldt.Tile, error) {
t := &FrequencyTile{}
t.Host = host
t.Port = port
return t, nil
}
}
// Parse parses the provided JSON object and populates the tiles attributes.
func (t *FrequencyTile) Parse(params map[string]interface{}) error {
err := t.Bivariate.Parse(params)
if err != nil {
return err
}
return t.Frequency.Parse(params)
}
// Create generates a tile from the provided URI, tile coordinate and query
// parameters.
func (t *FrequencyTile) Create(uri string, coord *binning.TileCoord, query veldt.Query) ([]byte, error) {
// Initialize the tile processing.
client, citusQuery, err := t.InitializeTile(uri, query)
// add tiling query
citusQuery = t.Bivariate.AddQuery(coord, citusQuery)
// add frequency query
citusQuery = t.Frequency.AddQuery(citusQuery)
// add aggs
citusQuery = t.Frequency.AddAggs(citusQuery)
// send query
res, err := client.Query(citusQuery.GetQuery(false), citusQuery.QueryArgs...)
if err != nil {
return nil, err
}
// get buckets
frequency, err := t.Frequency.GetBuckets(res)
if err != nil {
return nil, err
}
buckets := t.Frequency.encodeResult(frequency)
// marshal results
return json.Marshal(buckets)
}