Skip to content

Commit

Permalink
add CalcBounce
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 12, 2024
1 parent 738a80d commit ff5fb51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
12 changes: 0 additions & 12 deletions stats/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"strings"
"time"

"github.com/apache/arrow/go/v15/arrow/array"
"github.com/apache/arrow/go/v15/arrow/bitutil"
v1 "github.com/vinceanalytics/vince/gen/go/staples/v1"
"github.com/vinceanalytics/vince/logger"
"github.com/vinceanalytics/vince/timeutil"
Expand Down Expand Up @@ -209,13 +207,3 @@ func sep(f string) (key, value string, op v1.Filter_OP, ok bool) {
}
return
}

// We store sessions as boolean. True for new sessions and false otherwise.
// Visits is the same as the number of set bits.
func CalVisits(a *array.Boolean) int {
vals := a.Data().Buffers()[1]
if vals != nil {
return bitutil.CountSetBits(vals.Bytes(), 0, a.Len())
}
return 0
}
29 changes: 29 additions & 0 deletions stats/compute.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package stats

import (
"cmp"
"context"
"sort"

"github.com/apache/arrow/go/v15/arrow"
"github.com/apache/arrow/go/v15/arrow/array"
"github.com/apache/arrow/go/v15/arrow/bitutil"
"github.com/apache/arrow/go/v15/arrow/compute"
"github.com/apache/arrow/go/v15/arrow/math"
"github.com/vinceanalytics/vince/columns"
Expand Down Expand Up @@ -174,3 +176,30 @@ func metricsToProjection(f *v1.Filters, me []v1.Metric, props ...v1.Property) []
sort.Strings(cols)
return cols
}

// We store sessions as boolean. True for new sessions and false otherwise.
// Visits is the same as the number of set bits.
func CalVisits(a *array.Boolean) int {
return countSetBits(a)
}

func countSetBits(a *array.Boolean) int {
vals := a.Data().Buffers()[1]
if vals != nil {
return bitutil.CountSetBits(vals.Bytes(), 0, a.Len())
}
return 0
}

func CalcBounce(a *array.Boolean) int {
nulls := a.NullN()
set := countSetBits(a)
switch cmp.Compare(set, nulls) {
case -1:
return 0
case 1:
return set - nulls
default:
return 0
}
}

0 comments on commit ff5fb51

Please sign in to comment.