Skip to content

Commit

Permalink
feat: use *array.Boolean to store page views
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 12, 2024
1 parent 75ba4cc commit fda198d
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 75 deletions.
1 change: 1 addition & 0 deletions columns/columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ var Session = camel.Case(v1.Filters_Session.String())
var Bounce = camel.Case(v1.Filters_Bounce.String())
var Duration = camel.Case(v1.Filters_Duration.String())
var Timestamp = camel.Case(v1.Filters_Timestamp.String())
var View = camel.Case(v1.Filters_View.String())
101 changes: 52 additions & 49 deletions gen/go/staples/v1/scan.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/staples/v1/scan.proto
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ message Filters {
Bounce = 2;
Session = 3;
Duration = 4;
View = 26;

Browser = 5;
BrowserVersion = 6;
Expand Down
7 changes: 7 additions & 0 deletions staples/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Event struct {
// stayed and browsed the website.
Bounce *bool
Session bool
View bool
Duration float64

Browser string
Expand Down Expand Up @@ -100,10 +101,16 @@ func (e *Event) Release() {

func (e *Event) TS() int64 { return e.Timestamp }

const pageView = "pageview"

func (e *Event) Hit() {
e.EntryPage = e.Path
e.Bounce = True
e.Session = true
if e.Event == pageView {
e.Event = ""
e.View = true
}
}

func (s *Event) Update(e *Event) {
Expand Down
14 changes: 7 additions & 7 deletions staples/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import (
"github.com/RoaringBitmap/roaring"
"github.com/apache/arrow/go/v15/arrow"
"github.com/apache/arrow/go/v15/arrow/array"
"github.com/vinceanalytics/vince/camel"
"github.com/vinceanalytics/vince/columns"
"github.com/vinceanalytics/vince/db"
"github.com/vinceanalytics/vince/filters"
v1 "github.com/vinceanalytics/vince/gen/go/staples/v1"
"github.com/vinceanalytics/vince/index"
"github.com/vinceanalytics/vince/logger"
)
Expand All @@ -24,11 +23,12 @@ func NewIndex() *Index {
var _ index.Index = (*Index)(nil)

var skip = map[string]bool{
camel.Case(v1.Filters_Timestamp.String()): true,
camel.Case(v1.Filters_ID.String()): true,
camel.Case(v1.Filters_Session.String()): true,
camel.Case(v1.Filters_Bounce.String()): true,
camel.Case(v1.Filters_Duration.String()): true,
columns.Timestamp: true,
columns.ID: true,
columns.Session: true,
columns.Bounce: true,
columns.Duration: true,
columns.View: true,
}

func (idx *Index) Index(r arrow.Record) (index.Full, error) {
Expand Down
26 changes: 7 additions & 19 deletions stats/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ func (c *Compute) Metric(ctx context.Context, m v1.Metric) (float64, error) {
func (c *Compute) Events() float64 {
return float64(c.mapping[columns.Event].Len())
}

func (c *Compute) ViewsPerVisits() float64 {
views := c.PageView()
visits := c.Visits()
Expand Down Expand Up @@ -121,27 +122,11 @@ func (c *Compute) PageView() float64 {
if c.view != nil {
return *c.view
}
view := calcPageViews(c.mapping[columns.Event])
view := float64(countSetBits(c.mapping[columns.View].(*array.Boolean)))
c.view = &view
return view
}

const viewStr = "pageview"

func calcPageViews(a arrow.Array) (n float64) {
d := a.(*array.Dictionary)
x := d.Dictionary().(*array.String)
for i := 0; i < d.Len(); i++ {
if d.IsNull(i) {
continue
}
if x.Value(d.GetValueIndex(i)) == viewStr {
n++
}
}
return
}

func metricsToProjection(f *v1.Filters, me []v1.Metric, props ...v1.Property) []string {
m := make(map[v1.Filters_Projection]struct{})
m[v1.Filters_Timestamp] = struct{}{}
Expand All @@ -151,7 +136,7 @@ func metricsToProjection(f *v1.Filters, me []v1.Metric, props ...v1.Property) []
for _, v := range me {
switch v {
case v1.Metric_pageviews:
m[v1.Filters_Event] = struct{}{}
m[v1.Filters_View] = struct{}{}
case v1.Metric_visitors:
m[v1.Filters_ID] = struct{}{}
case v1.Metric_visits:
Expand All @@ -160,10 +145,13 @@ func metricsToProjection(f *v1.Filters, me []v1.Metric, props ...v1.Property) []
m[v1.Filters_Session] = struct{}{}
m[v1.Filters_Bounce] = struct{}{}
case v1.Metric_visit_duration:
m[v1.Filters_Session] = struct{}{}
m[v1.Filters_Duration] = struct{}{}
case v1.Metric_views_per_visit:
m[v1.Filters_Event] = struct{}{}
m[v1.Filters_View] = struct{}{}
m[v1.Filters_Duration] = struct{}{}
case v1.Metric_events:
m[v1.Filters_Event] = struct{}{}
}
}
cols := make([]string, 0, len(m))
Expand Down

0 comments on commit fda198d

Please sign in to comment.