gosora/common/statistics.go
Azareal 547254c4a1 Added Chartist as a dependency.
Fixed a XSS exploit.
Centralised the post escaping logic.

Began work on the Analytics UI.
2017-12-30 05:47:46 +00:00

40 lines
1.0 KiB
Go

package common
// EXPERIMENTAL
import (
"errors"
)
var StatStore StatStoreInt
type StatStoreInt interface {
LookupInt(name string, duration int, unit string) (int, error)
}
type DefaultStatStore struct {
}
func NewDefaultStatStore() *DefaultStatStore {
return &DefaultStatStore{}
}
func (store *DefaultStatStore) LookupInt(name string, duration int, unit string) (int, error) {
switch name {
case "postCount":
return store.countTable("replies", duration, unit)
}
return 0, errors.New("The requested stat doesn't exist")
}
func (store *DefaultStatStore) countTable(table string, duration int, unit string) (stat int, err error) {
/*acc := qgen.Builder.Accumulator()
counter := acc.Count("replies").DateCutoff("createdAt", 1, "day").Prepare()
if acc.FirstError() != nil {
return 0, acc.FirstError()
}
err := counter.QueryRow().Scan(&stat)*/
return stat, err
}
//stmts.todaysPostCount, err = db.Prepare("select count(*) from replies where createdAt BETWEEN (utc_timestamp() - interval 1 day) and utc_timestamp()")