senulator

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2018 License: GPL-3.0 Imports: 6 Imported by: 0

README

Build Status codecov GoDoc Go Report Card

senulator

A package for generating realistic, random data and converting it into SenML for use with IOT devices and testing.

This package is very much a work in progress, however, it works in a basic sense. It is currently in development and used for testing at Capstone Metering.

PR's welcome, we're friendly! :)

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.

func New

func New(request Request) (Request, error)

New creates a new senulator instance.

New also checks for some basic errors, calculates Duration, and RecordCount.

RecordCount is part of a performance enhancing effort to presize the slices for larger data sizes (think a year or more.)

func (*Request) Generate

func (r *Request) Generate() ([]senml.SenMLRecord, error)

Generate kicks off the generation of data given a request.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL