Skip to content

Commit

Permalink
generate sample data
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 23, 2024
1 parent cb8d141 commit d989a6a
Show file tree
Hide file tree
Showing 2 changed files with 237 additions and 0 deletions.
48 changes: 48 additions & 0 deletions internal/closter/events/sample.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package events

import (
_ "embed"
"time"

v1 "github.com/vinceanalytics/vince/gen/go/events/v1"
"google.golang.org/protobuf/encoding/protojson"
)

//go:embed testdata/sample.json
var sample []byte

type sampleOptions struct {
now func() time.Time
step time.Duration
}

type SampleOption func(*sampleOptions)

func WithNow(now func() time.Time) SampleOption {
return func(so *sampleOptions) {
so.now = now
}
}

func WithStep(step time.Duration) SampleOption {
return func(so *sampleOptions) {
so.step = step
}
}

func Samples(opts ...SampleOption) *v1.List {
o := &sampleOptions{
now: time.Now,
step: time.Second,
}
for _, v := range opts {
v(o)
}
var ls v1.List
protojson.Unmarshal(sample, &ls)
now := o.now().UTC()
for i, e := range ls.GetItems() {
e.Timestamp = now.Add(time.Duration(i) * o.step).UnixMilli()
}
return &ls
}
189 changes: 189 additions & 0 deletions internal/closter/events/testdata/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"items": [
{
"timestamp": "1708693696665",
"id": "-153093840780285821",
"bounce": true,
"session": true,
"view": true,
"browser": "Chrome Webview",
"browserVersion": "112.0.5615.135",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.eg",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696671",
"id": "7185465862254995008",
"bounce": true,
"session": true,
"view": true,
"browser": "Chrome Mobile",
"browserVersion": "105.0.0.0",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.cy",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696672",
"id": "7185465862254995008",
"bounce": false,
"view": true,
"duration": 0.001,
"browser": "Chrome Mobile",
"browserVersion": "105.0.0.0",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"exitPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.co",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696673",
"id": "7185465862254995008",
"bounce": false,
"view": true,
"duration": 0.001,
"browser": "Chrome Mobile",
"browserVersion": "105.0.0.0",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"exitPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.do",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696678",
"id": "-8846038784045917376",
"bounce": true,
"session": true,
"view": true,
"browser": "Chrome Mobile",
"browserVersion": "95.0.4638.74",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.cy",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696683",
"id": "-7731778067934062273",
"bounce": true,
"session": true,
"view": true,
"browser": "Chrome",
"browserVersion": "103.0.0.0",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.ec",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696684",
"id": "-153093840780285821",
"bounce": false,
"view": true,
"duration": 0.019,
"browser": "Chrome Webview",
"browserVersion": "112.0.5615.135",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"exitPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.bz",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696689",
"id": "-5530366380598135793",
"bounce": true,
"session": true,
"view": true,
"browser": "Chrome Mobile",
"browserVersion": "99.0.4844.88",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.do",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696690",
"id": "-7731778067934062273",
"bounce": false,
"view": true,
"duration": 0.007,
"browser": "Chrome",
"browserVersion": "103.0.0.0",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"exitPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.et",
"source": "Google Blogsearch"
},
{
"timestamp": "1708693696691",
"id": "7185465862254995008",
"bounce": false,
"view": true,
"duration": 0.018,
"browser": "Chrome Mobile",
"browserVersion": "105.0.0.0",
"device": "mobile",
"domain": "vinceanalytics.com",
"entryPage": "/",
"exitPage": "/",
"host": "vinceanalytics.com",
"os": "Android",
"osVersion": "11",
"page": "/",
"referrer": "https://blogsearch.google.com.et",
"source": "Google Blogsearch"
}
]
}

0 comments on commit d989a6a

Please sign in to comment.