mirror of https://github.com/status-im/fathom.git
godoc improvements
This commit is contained in:
parent
72c2952e15
commit
3b8a884991
|
@ -11,12 +11,14 @@ type aggregator struct {
|
|||
database datastore.Datastore
|
||||
}
|
||||
|
||||
// New returns a new aggregator instance with the database dependency injected.
|
||||
func New(db datastore.Datastore) *aggregator {
|
||||
return &aggregator{
|
||||
database: db,
|
||||
}
|
||||
}
|
||||
|
||||
// Run processes the pageviews which are ready to be processed and adds them to daily aggregation
|
||||
func (agg *aggregator) Run() {
|
||||
// Get unprocessed pageviews
|
||||
pageviews, err := agg.database.GetProcessablePageviews()
|
||||
|
@ -61,9 +63,10 @@ func (agg *aggregator) Run() {
|
|||
}
|
||||
}
|
||||
|
||||
func (agg *aggregator) Process(pageviews []*models.Pageview) *Results {
|
||||
// Process processes the given pageviews and returns the (aggregated) results per metric per day
|
||||
func (agg *aggregator) Process(pageviews []*models.Pageview) *results {
|
||||
log.Debugf("processing %d pageviews", len(pageviews))
|
||||
results := NewResults()
|
||||
results := newResults()
|
||||
|
||||
for _, p := range pageviews {
|
||||
site, err := agg.getSiteStats(results, p.Timestamp)
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"github.com/usefathom/fathom/pkg/models"
|
||||
)
|
||||
|
||||
type Results struct {
|
||||
type results struct {
|
||||
Sites map[string]*models.SiteStats
|
||||
Pages map[string]*models.PageStats
|
||||
Referrers map[string]*models.ReferrerStats
|
||||
}
|
||||
|
||||
func NewResults() *Results {
|
||||
return &Results{
|
||||
func newResults() *results {
|
||||
return &results{
|
||||
Sites: map[string]*models.SiteStats{},
|
||||
Pages: map[string]*models.PageStats{},
|
||||
Referrers: map[string]*models.ReferrerStats{},
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/usefathom/fathom/pkg/models"
|
||||
)
|
||||
|
||||
func (agg *aggregator) getSiteStats(r *Results, t time.Time) (*models.SiteStats, error) {
|
||||
func (agg *aggregator) getSiteStats(r *results, t time.Time) (*models.SiteStats, error) {
|
||||
// get from map
|
||||
date := t.Format("2006-01-02")
|
||||
if stats, ok := r.Sites[date]; ok {
|
||||
|
@ -37,7 +37,7 @@ func (agg *aggregator) getSiteStats(r *Results, t time.Time) (*models.SiteStats,
|
|||
return stats, nil
|
||||
}
|
||||
|
||||
func (agg *aggregator) getPageStats(r *Results, t time.Time, hostname string, pathname string) (*models.PageStats, error) {
|
||||
func (agg *aggregator) getPageStats(r *results, t time.Time, hostname string, pathname string) (*models.PageStats, error) {
|
||||
date := t.Format("2006-01-02")
|
||||
if stats, ok := r.Pages[date+hostname+pathname]; ok {
|
||||
return stats, nil
|
||||
|
@ -64,7 +64,7 @@ func (agg *aggregator) getPageStats(r *Results, t time.Time, hostname string, pa
|
|||
return stats, nil
|
||||
}
|
||||
|
||||
func (agg *aggregator) getReferrerStats(r *Results, t time.Time, url string) (*models.ReferrerStats, error) {
|
||||
func (agg *aggregator) getReferrerStats(r *results, t time.Time, url string) (*models.ReferrerStats, error) {
|
||||
date := t.Format("2006-01-02")
|
||||
if stats, ok := r.Referrers[date+url]; ok {
|
||||
return stats, nil
|
||||
|
|
|
@ -9,12 +9,13 @@ import (
|
|||
"github.com/usefathom/fathom/pkg/datastore/sqlstore"
|
||||
)
|
||||
|
||||
// Config wraps the configuration structs for the various application parts
|
||||
type Config struct {
|
||||
Database *sqlstore.Config
|
||||
|
||||
Secret string
|
||||
Secret string
|
||||
}
|
||||
|
||||
// Parses the supplied file + environment into a Config struct
|
||||
func Parse(file string) *Config {
|
||||
var cfg Config
|
||||
var err error
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"github.com/usefathom/fathom/pkg/models"
|
||||
)
|
||||
|
||||
// ErrNoResults is returned whenever a single-item query returns 0 results
|
||||
var ErrNoResults = sqlstore.ErrNoResults // ???
|
||||
|
||||
type Datastore interface {
|
||||
|
@ -47,9 +48,11 @@ type Datastore interface {
|
|||
GetAggregatedReferrerStats(time.Time, time.Time, int) ([]*models.ReferrerStats, error)
|
||||
GetAggregatedReferrerStatsPageviews(time.Time, time.Time) (int, error)
|
||||
|
||||
// misc
|
||||
Close()
|
||||
}
|
||||
|
||||
// New instantiates a new datastore from the given configuration struct
|
||||
func New(c *sqlstore.Config) Datastore {
|
||||
return sqlstore.New(c)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue