diff options
author | Steve Manuel <nilslice@gmail.com> | 2016-11-04 15:40:26 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2016-11-04 15:40:26 -0700 |
commit | 9c4a92c215153f7bca370396c9135eaebf0ab173 (patch) | |
tree | 0c02e80dfcfebff185d1b031027fda2ea45ca94a /system/api/analytics/init.go | |
parent | eead663156d6b6cb300c96fcf90d3f804e4a5952 (diff) |
keeping 2 weeks of data to show, pruning after 1 week, and testing date range UI on dahsboard
Diffstat (limited to 'system/api/analytics/init.go')
-rw-r--r-- | system/api/analytics/init.go | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/system/api/analytics/init.go b/system/api/analytics/init.go index 14eff7f..41c24c7 100644 --- a/system/api/analytics/init.go +++ b/system/api/analytics/init.go @@ -56,7 +56,7 @@ func Close() { } } -// Init creates a db connection, should run an initial prune of old data, and +// Init creates a db connection, initializes the db with schema and data and // sets up the queue/batching channel func Init() { var err error @@ -65,6 +65,18 @@ func Init() { log.Fatalln(err) } + err = store.Update(func(tx *bolt.Tx) error { + _, err := tx.CreateBucketIfNotExists([]byte("requests")) + if err != nil { + return err + } + + return nil + }) + if err != nil { + log.Fatalln("Error idempotently creating requests bucket in analytics.db:", err) + } + requestChan = make(chan apiRequest, 1024*64*runtime.NumCPU()) go serve() @@ -105,8 +117,8 @@ func serve() { } } -// Week returns the map containing decoded javascript needed to chart a week of data by day -func Week() (map[string]interface{}, error) { +// ChartData returns the map containing decoded javascript needed to chart 2 weeks of data by day +func ChartData() (map[string]interface{}, error) { // set thresholds for today and the 6 days preceeding times := [14]time.Time{} dates := [14]string{} @@ -224,5 +236,7 @@ CHECK_REQUEST: "dates": dates, "unique": string(jsUnique), "total": string(jsTotal), + "from": dates[0], + "to": dates[len(dates)-1], }, nil } |