timeseries

package
v0.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2023 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const BaseKey = "__root__"
View Source
const SessionTime = time.Minute * 10

Variables

This section is empty.

Functions

func DropSite

func DropSite(ctx context.Context, uid, sid uint64)

func GetMike

func GetMike(ctx context.Context) *badger.DB

func GetUnique

func GetUnique(ctx context.Context) *badger.DB

func Open

func Save

func Save(ctx context.Context, b *Buffer)

func SetMap

func SetMap(ctx context.Context, m *Map) context.Context

func Time

func Time(id []byte) uint64

Types

type Aggregate

type Aggregate map[string]AggregateMetricsStatValue

type AggregateMetricsStatValue added in v0.0.8

type AggregateMetricsStatValue map[string]StatList

type AggregateValue added in v0.0.8

type AggregateValue map[string]FloatValue

AggregateValue maps keys to value for a specific metric

type BaseQuery

type BaseQuery struct {
	Start   time.Time     `json:"start,omitempty"`
	Offset  time.Duration `json:"offset,omitempty"`
	Step    time.Duration `json:"step,omitempty"`
	Window  time.Duration `json:"window,omitempty"`
	Metrics []Metric      `json:"metrics"`
	Filters FilterList    `json:"filters"`
}

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func NewBuffer

func NewBuffer(uid, sid uint64, ttl time.Duration) *Buffer

func (*Buffer) AddEntry

func (b *Buffer) AddEntry(e ...*entry.Entry)

func (*Buffer) Build

func (b *Buffer) Build(ctx context.Context, f func(p Property, key string, sum *Sum) error) error

func (*Buffer) Init

func (b *Buffer) Init(uid, sid uint64, ttl time.Duration) *Buffer

func (*Buffer) Register

func (b *Buffer) Register(ctx context.Context, e *entry.Entry, prevUserId uint64)

func (*Buffer) Release

func (b *Buffer) Release()

func (*Buffer) Reset

func (b *Buffer) Reset() *Buffer

func (*Buffer) SID

func (b *Buffer) SID() uint64

func (*Buffer) UID

func (b *Buffer) UID() uint64

type Filter

type Filter struct {
	Property Property   `json:"prop"`
	Omit     []Metric   `json:"omitMetrics,omitempty"`
	Expr     FilterExpr `json:"expr"`
}

func (*Filter) Accept

func (f *Filter) Accept(m Metric) bool

type FilterAnd

type FilterAnd []*FilterExpr

func (FilterAnd) Match

func (f FilterAnd) Match(txt []byte) bool

type FilterExpr

type FilterExpr struct {
	Property Property       `json:"prop"`
	And      FilterAnd      `json:"and,omitempty"`
	Or       FilterAnd      `json:"or,omitempty"`
	Text     string         `json:"text,omitempty"`
	IsRe     bool           `json:"isRe,omitempty"`
	IsGlob   bool           `json:"isGlob,omitempty"`
	Re       *regexp.Regexp `json:"-"`
}

func (*FilterExpr) Compile

func (m *FilterExpr) Compile() error

func (*FilterExpr) ExactMatch

func (m *FilterExpr) ExactMatch() bool

func (*FilterExpr) Match

func (m *FilterExpr) Match(txt []byte) bool

func (*FilterExpr) Validate

func (m *FilterExpr) Validate() error

type FilterList

type FilterList []*Filter

func (FilterList) Validate

func (f FilterList) Validate() error

type FilterOr

type FilterOr []*FilterExpr

func (FilterOr) Match

func (f FilterOr) Match(txt []byte) bool

type FloatValue

type FloatValue float64

func (FloatValue) String

func (v FloatValue) String() string

type Key

type Key [keyOffset]byte

func (*Key) Release

func (id *Key) Release()

type Map

type Map struct {
	// contains filtered or unexported fields
}

Maps user ID to *Buffer.

func GetMap

func GetMap(ctx context.Context) *Map

func NewMap

func NewMap() *Map

func (*Map) Delete

func (m *Map) Delete(sid uint64)

Removes the buffer associated with sid

func (*Map) Get

func (m *Map) Get(uid, sid uint64) *Buffer

Get returns a *Buffer belonging to a user with uid who owns site with id sid.

func (*Map) Save

func (m *Map) Save(ctx context.Context)

type Metric

type Metric uint8
const (
	Visitors       Metric = 0
	Views          Metric = 1
	Events         Metric = 2
	Visits         Metric = 3
	BounceRates    Metric = 4
	VisitDurations Metric = 5
)

func (Metric) MarshalJSON

func (m Metric) MarshalJSON() ([]byte, error)

func (Metric) String

func (m Metric) String() string

func (*Metric) UnmarshalJSON

func (m *Metric) UnmarshalJSON(b []byte) error

type MetricResult

type MetricResult map[string]OutValue

type MultiEntry

type MultiEntry struct {
	UtmMedium              []string
	Referrer               []string
	Domain                 []string
	ExitPage               []string
	EntryPage              []string
	Hostname               []string
	Pathname               []string
	UtmSource              []string
	ReferrerSource         []string
	CountryCode            []string
	Region                 []string
	Subdivision2Code       []string
	TransferredFrom        []string
	UtmCampaign            []string
	OperatingSystem        []string
	Browser                []string
	UtmTerm                []string
	Name                   []string
	ScreenSize             []string
	BrowserVersion         []string
	OperatingSystemVersion []string
	UtmContent             []string
	UserId                 []uint64
	SessionId              []uint64
	Timestamp              []int64
	Duration               []time.Duration
	Start                  []int64
	City                   []string
	PageViews              []int32
	Events                 []int32
	Sign                   []int32
	IsBounce               []bool
	// contains filtered or unexported fields
}

type OutValue

type OutValue map[string][]float64

type PropertiesResult

type PropertiesResult map[string]MetricResult

type Property

type Property uint8
const (
	Base           Property = 0
	Event          Property = 1
	Page           Property = 2
	EntryPage      Property = 3
	ExitPage       Property = 4
	Referrer       Property = 5
	UtmMedium      Property = 6
	UtmSource      Property = 7
	UtmCampaign    Property = 8
	UtmContent     Property = 9
	UtmTerm        Property = 10
	UtmDevice      Property = 11
	UtmBrowser     Property = 12
	BrowserVersion Property = 13
	Os             Property = 14
	OsVersion      Property = 15
	Country        Property = 16
	Region         Property = 17
	City           Property = 18
)

func ParseProperty added in v0.0.8

func ParseProperty(k string) Property

func (Property) MarshalJSON

func (p Property) MarshalJSON() ([]byte, error)

func (Property) String

func (p Property) String() string

func (*Property) UnmarshalJSON

func (p *Property) UnmarshalJSON(b []byte) error

type QueryRequest

type QueryRequest struct {
	UserID uint64
	SiteID uint64
	BaseQuery
}

type QueryResult

type QueryResult struct {
	ELapsed    time.Duration    `json:"elapsed"`
	Start      time.Time        `json:"start"`
	End        time.Time        `json:"end"`
	Timestamps []int64          `json:"timestamps"`
	Result     PropertiesResult `json:"result"`
}

func Query

func Query(ctx context.Context, r QueryRequest) (result QueryResult)

type RootOptions

type RootOptions struct {
	Metric Metric        `json:"metric,omitempty"`
	Prop   Property      `json:"prop,omitempty"`
	Key    string        `json:"key,omitempty"`
	Start  time.Time     `json:"start,omitempty"`
	Window time.Duration `json:"window,omitempty"`
	Offset time.Duration `json:"offset,omitempty"`
	// When set to true and Prop is Base, other props will not be queried. This is
	// useful to query only base aggregates . Like the one used on sites
	// index.
	NoProps bool `json:"noProps,omitempty"`
}

type StatList added in v0.0.8

type StatList []StatValue

func (StatList) Len added in v0.0.8

func (s StatList) Len() int

func (StatList) Less added in v0.0.8

func (s StatList) Less(i, j int) bool

func (StatList) Swap added in v0.0.8

func (s StatList) Swap(i, j int)

type StatValue

type StatValue struct {
	Key   string
	Value FloatValue
}

type Stats

type Stats struct {
	Start, End time.Time
	Period     timex.Duration
	Domain     string
	Key        string
	Prop       Property
	Timestamps []int64
	Aggregate  Aggregate
	Timeseries PropertiesResult
}

func Root

func Root(ctx context.Context, uid, sid uint64, opts RootOptions) (o Stats)

func (*Stats) PlotTime added in v0.0.8

func (s *Stats) PlotTime() (string, error)

func (*Stats) PlotValue added in v0.0.8

func (s *Stats) PlotValue(metric string) (string, error)

func (*Stats) QueryPeriod added in v0.0.8

func (s *Stats) QueryPeriod(period timex.Duration) string

type Sum

type Sum struct {
	Visitors      float64
	Views         float64
	Events        float64
	Visits        float64
	BounceRate    float64
	VisitDuration float64
}

type Value

type Value struct {
	Timestamp []int64   `json:"timestamp"`
	Value     []float64 `json:"value"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL