Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add time fields #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions pkg/datagen/datagen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"strconv"
"time"
)

var (
Expand Down Expand Up @@ -204,6 +205,7 @@ type Doc struct {
// For edges only, the Label of the from vertex
FromLabel string `json:"fromId,omitempty"`
// For edges only, the Label of the to vertex

ToLabel string `json:"toId,omitempty"`
Payload0 string `json:"payload0"`
Payload1 string `json:"payload1,omitempty"`
Expand All @@ -223,6 +225,9 @@ type Doc struct {
Payloadf string `json:"payloadf,omitempty"`
Geo *Poly `Json:"geo,omitempty"`
Words string `json:"words,omitempty"`

Created int64 `json:"created,omitempty"`
Expired int64 `json:"expired,omitempty"`
}

// makeRandomPolygon makes a random GeoJson polygon.
Expand Down Expand Up @@ -318,17 +323,23 @@ type DocumentConfig struct {
}

func (doc *Doc) FillData(docConfig *DocumentConfig, source *rand.Rand) {
rand.Seed(time.Now().UnixNano())
min := 3600
max := 604800

if docConfig.NumberFields > 16 {
docConfig.NumberFields = 16
} else if docConfig.NumberFields < 1 {
docConfig.NumberFields = 1
}
payloadSize := (docConfig.SizePerDoc - docConfig.KeySize - 106 - 11*docConfig.WithWords) / docConfig.NumberFields
payloadSize := (docConfig.SizePerDoc - docConfig.KeySize - 106 - 11*docConfig.WithWords + 34) / docConfig.NumberFields
// 106 is the approximate overhead for _id, _rev and structures
if payloadSize < 0 {
payloadSize = int64(5)
payloadSize = int64(16)
}
doc.Payload0 = MakeRandomStringWithSpaces(int(payloadSize), source)
doc.Created = time.Now().Unix() - int64(rand.Intn(max-min+1)+min)
doc.Expired = doc.Created + 3600
if docConfig.WithGeo {
doc.Geo = makeRandomPolygon(source)
}
Expand Down