engine

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SaveConfigToFile

func SaveConfigToFile(config *ConfigFile, filename string) error

SaveConfigToFile saves configuration to a JSON file

Types

type BasicSensorFunction

type BasicSensorFunction[T any] struct {
	// contains filtered or unexported fields
}

BasicSensorFunction provides a simple implementation for basic sensor data generation

func NewBasicSensorFunction

func NewBasicSensorFunction[T any](transformFunc func(float64, time.Time) T) *BasicSensorFunction[T]

NewBasicSensorFunction creates a new basic sensor function with a custom transform function

func (*BasicSensorFunction[T]) Generate

func (f *BasicSensorFunction[T]) Generate(input float64, timestamp time.Time) T

Generate creates sensor data using the transform function

type Config

type Config struct {
	ProductionRate time.Duration // How often to generate data
	BatchSize      int           // Number of messages to batch together
	BatchTimeout   time.Duration // How long to wait before publishing a batch
	MaxWorkers     int           // Number of concurrent workers
}

Config holds the engine configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default engine configuration

func HighThroughputConfig

func HighThroughputConfig() Config

HighThroughputConfig returns a configuration optimized for high throughput

func LowLatencyConfig

func LowLatencyConfig() Config

LowLatencyConfig returns a configuration optimized for low latency

type ConfigFile

type ConfigFile struct {
	Engine EngineConfig `json:"engine"`
	Seeder SeederConfig `json:"seeder"`
	Output OutputConfig `json:"output"`
}

ConfigFile represents the JSON configuration file structure

func DefaultConfigFile

func DefaultConfigFile() *ConfigFile

DefaultConfigFile returns a default configuration structure

func LoadConfigFromFile

func LoadConfigFromFile(filename string) (*ConfigFile, error)

LoadConfigFromFile loads configuration from a JSON file

func (*ConfigFile) CreateSeeder

func (c *ConfigFile) CreateSeeder() (Seeder, error)

CreateSeeder creates a seeder from configuration

func (*ConfigFile) ToEngineConfig

func (c *ConfigFile) ToEngineConfig() (Config, error)

ToEngineConfig converts ConfigFile to Engine Config

type CustomSeeder

type CustomSeeder struct {
	// contains filtered or unexported fields
}

CustomSeeder allows for custom generation functions

func NewCustomSeeder

func NewCustomSeeder(generateFunc func() float64) *CustomSeeder

NewCustomSeeder creates a new custom seeder

func (*CustomSeeder) Generate

func (c *CustomSeeder) Generate() float64

Generate generates a value using the custom function

type Engine

type Engine[T any] struct {
	// contains filtered or unexported fields
}

Engine is the generic sensor engine

func CreateEngineFromConfig

func CreateEngineFromConfig[T any](filename string, function SensorFunction[T], publisher Publisher[T]) (*Engine[T], error)

CreateEngineFromConfig creates a complete engine configuration from file

func NewEngine

func NewEngine[T any](
	config Config,
	seeder Seeder,
	function SensorFunction[T],
	publisher Publisher[T],
) *Engine[T]

NewEngine creates a new generic sensor engine

func (*Engine[T]) Start

func (e *Engine[T]) Start(ctx context.Context) error

Start starts the sensor engine and returns an error if any

type EngineConfig

type EngineConfig struct {
	ProductionRate string `json:"production_rate"` // Duration string like "100ms", "1s"
	BatchSize      int    `json:"batch_size"`
	BatchTimeout   string `json:"batch_timeout"` // Duration string
	MaxWorkers     int    `json:"max_workers"`
}

EngineConfig holds engine configuration

type Function

type Function[T any] struct {
	// contains filtered or unexported fields
}

Function allows users to define their own sensor data generation logic

func NewFunction

func NewFunction[T any](generateFunc func(float64, time.Time) T) *Function[T]

NewFunction creates a new user-defined sensor function

func (*Function[T]) Generate

func (f *Function[T]) Generate(input float64, timestamp time.Time) T

Generate creates sensor data using the user-defined function

type FunctionConfig

type FunctionConfig struct {
	Type   string                 `json:"type"`   // "simple", "lambda", "custom"
	Params map[string]interface{} `json:"params"` // Function-specific parameters
}

FunctionConfig represents a simple function configuration

type LambdaSensorFunction

type LambdaSensorFunction[T any] struct {
	// contains filtered or unexported fields
}

LambdaSensorFunction provides a simple function wrapper for inline usage

func NewLambdaSensorFunction

func NewLambdaSensorFunction[T any](lambda func(float64, time.Time) T) *LambdaSensorFunction[T]

NewLambdaSensorFunction creates a sensor function from a lambda/anonymous function

func (*LambdaSensorFunction[T]) Generate

func (l *LambdaSensorFunction[T]) Generate(input float64, timestamp time.Time) T

Generate generates sensor data using the lambda function

type LinearSeeder

type LinearSeeder struct {
	// contains filtered or unexported fields
}

LinearSeeder generates values that increase linearly over time

func NewLinearSeeder

func NewLinearSeeder(slope, offset float64) *LinearSeeder

NewLinearSeeder creates a new linear seeder

func (*LinearSeeder) Generate

func (l *LinearSeeder) Generate() float64

Generate generates a value that increases linearly

type NormalSeeder

type NormalSeeder struct {
	// contains filtered or unexported fields
}

NormalSeeder generates values from a normal distribution

func NewNormalSeeder

func NewNormalSeeder(mean, stdDev float64) *NormalSeeder

NewNormalSeeder creates a new normal distribution seeder

func (*NormalSeeder) Generate

func (n *NormalSeeder) Generate() float64

Generate generates a value from a normal distribution

type OutputConfig

type OutputConfig struct {
	Type     string                 `json:"type"`     // "http", "kafka", "grpc", "console"
	Params   map[string]interface{} `json:"params"`   // Publisher-specific parameters
	Metadata map[string]string      `json:"metadata"` // Optional metadata to include in output
}

OutputConfig holds output configuration

type Publisher

type Publisher[T any] interface {
	Publish(ctx context.Context, data SensorData[T]) error
	PublishBatch(ctx context.Context, data []SensorData[T]) error
	Close() error
}

Publisher defines the interface for publishing sensor data

type Quality

type Quality string

Quality represents the quality of sensor data

const (
	QualityOK      Quality = "OK"
	QualityNoisy   Quality = "NOISY"
	QualityPartial Quality = "PARTIAL"
	QualityCorrupt Quality = "CORRUPT"
)

type RandomSeeder

type RandomSeeder struct {
	// contains filtered or unexported fields
}

RandomSeeder generates random values within a range

func NewRandomSeeder

func NewRandomSeeder(min, max float64) *RandomSeeder

NewRandomSeeder creates a new random seeder

func (*RandomSeeder) Generate

func (r *RandomSeeder) Generate() float64

Generate generates a random value between min and max

type Seeder

type Seeder interface {
	Generate() float64
}

Seeder generates input values for sensor functions

type SeederConfig

type SeederConfig struct {
	Type     string                 `json:"type"`     // "time", "random", "linear", "normal", "custom"
	Params   map[string]interface{} `json:"params"`   // Type-specific parameters
	Function *FunctionConfig        `json:"function"` // Optional inline function definition
}

SeederConfig holds seeder configuration

type SensorData

type SensorData[T any] struct {
	ID        string    `json:"id"`
	Timestamp time.Time `json:"timestamp"`
	Data      T         `json:"data"`
	Quality   Quality   `json:"quality"`
}

SensorData represents any sensor reading with generic data

type SensorFunction

type SensorFunction[T any] interface {
	Generate(input float64, timestamp time.Time) T
}

SensorFunction defines the interface for sensor data generation functions

type TimeSeeder

type TimeSeeder struct {
	// contains filtered or unexported fields
}

TimeSeeder generates values based on time

func NewTimeSeeder

func NewTimeSeeder(amplitude, frequency, offset float64) *TimeSeeder

NewTimeSeeder creates a new time-based seeder

func (*TimeSeeder) Generate

func (t *TimeSeeder) Generate() float64

Generate generates a value based on current time

Jump to

Keyboard shortcuts

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