Documentation ¶
Overview ¶
Package senulator generates realistic, random data, and outputs it in the form of SenML.
Special Thanks ¶
A special thanks is owed to Ashley Troggio who, without her help, this package would not have been possible. She taught me distributions and gave me the idea for categorizing generated data. The rest is just an abstraction.
Example ¶
// Create a new request. // At least Start, End, and 1 unit are required or New() will return an error request := Request{ Name: "test:meter:1", Start: time.Now().Unix(), End: time.Now().Add(time.Hour * 24).Unix(), Units: []Unit{ { Name: "Volume", Symbol: "L", Probability: []float64{.7, .2, .1}, Categories: map[int][]float64{ 0: {0.0, 0.0}, 1: {0.1, 19}, 2: {19.1, 56.7812}, }, Reading: 0, Interval: 900, }, }, } meter, err := New(request) if err != nil { fmt.Println("Error occurred!") } records, err := meter.Generate() if err != nil { fmt.Println("Error generating records!") } pack := senml.SenML{ Records: records, } options := senml.OutputOptions{ PrettyPrint: true, } jsonData, err := senml.Encode(pack, senml.JSON, options) if err != nil { fmt.Println("Error: Unable to encode JSON") } fmt.Printf("data: %s\n", jsonData)
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Request ¶
type Request struct { Name string Start int64 End int64 Duration int64 Version int Debug bool RecordCount int64 Records []senml.SenMLRecord Units []Unit }
Request is the base struct that contains parameter for generating data that are applicable across all units.
type Unit ¶
type Unit struct { Name string Symbol string UseFloor bool UseCeiling bool Floor float64 Ceiling float64 Probability []float64 Categories map[int][]float64 Reading float64 Interval int64 }
Unit represents an individual measureable unit with configurable fields to control things such as Ceiling and Floor.
Click to show internal directories.
Click to hide internal directories.