calc

package
v0.0.0-...-d8ac9bd Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewParser

func NewParser() util.Parser[Script]

Types

type Builder

type Builder[T any] interface {
	location.LocationBuilder[T]
	Calculation(func(CalcVisitor[T], *Calculation) error) Builder[T]
	CronTab(func(CalcVisitor[T], *time.CronTab) error) Builder[T]
	Current(func(CalcVisitor[T], *Current) error) Builder[T]
	Expression(func(CalcVisitor[T], *Expression) error) Builder[T]
	Function(func(CalcVisitor[T], *Function) error) Builder[T]
	Load(f func(CalcVisitor[T], *Load) error) Builder[T]
	Metric(func(CalcVisitor[T], *Metric) error) Builder[T]
	Script(func(CalcVisitor[T], *Script) error) Builder[T]
	Unit(f func(CalcVisitor[T], *units.Unit) error) Builder[T]
	UseFirst(f func(CalcVisitor[T], *UseFirst) error) Builder[T]
	Build() CalcVisitor[T]
}

func NewBuilder

func NewBuilder[T any]() Builder[T]

type CalcVisitor

type CalcVisitor[T any] interface {
	data.DataVisitor[T]
	location.LocationVisitor[T]
	Clone() CalcVisitor[T]
	Calculation(*Calculation) error
	CronTab(tab *time.CronTab) error
	Current(*Current) error
	Expression(*Expression) error
	Function(*Function) error
	Load(b *Load) error
	Metric(*Metric) error
	Script(*Script) error
	Unit(b *units.Unit) error
	UseFirst(b *UseFirst) error
}

type Calculation

type Calculation struct {
	Pos        lexer.Position
	Target     string        `parser:"'calculate' @String"`   // Name of metric to calculate
	At         string        `parser:"('at' @String)?"`       // If set the Location to use
	Every      *time.CronTab `parser:"('every' @@)?"`         // Calculate at specified intervals
	ResetEvery *time.CronTab `parser:"('reset' 'every' @@)?"` // Crontab to reset the value
	Load       *Load         `parser:"(@@)?"`                 // Load from the DB on startup
	UseFirst   *UseFirst     `parser:"(@@)?"`                 // If set and no value use this expression
	Expression *Expression   `parser:"('as' @@)?"`            // Expression to perform calculation
}

Calculation defines a metric to calculate

type Current

type Current struct {
	Pos     lexer.Position
	Current bool `parser:"@'current'"`
}

Current returns the current value of the calculation being performed

type Expression

type Expression struct {
	Pos      lexer.Position
	Current  *Current    `parser:"( @@"`   // Get the current value of calculation
	Function *Function   `parser:"| @@"`   // Generic Function Call
	Metric   *Metric     `parser:"| @@ )"` // Metric reference
	Using    *units.Unit `parser:"(@@)?"`  // Optional target Unit
}

type Function

type Function struct {
	Pos         lexer.Position
	Name        string        `parser:"@Ident"`
	Expressions []*Expression `parser:"'(' (@@ (',' @@)*)? ')'"`
}

Function handles function calls

type Load

type Load struct {
	Pos  lexer.Position
	When string `parser:"'load' @String"` // When to load from
	With string `parser:"'with' @String"` // Query to perform
}

type Metric

type Metric struct {
	Pos    lexer.Position
	Metric []string `parser:"@Ident ( '.' @Ident )*"`
	Name   string
}

Metric handles a metric reference

type Script

type Script struct {
	Pos          lexer.Position
	Locations    []*location.Location `parser:"(@@)*"`
	Calculations []*Calculation       `parser:"(@@)+"`
	State        *State
}

func (*Script) Merge

func (s *Script) Merge(b *Script) (*Script, error)

type State

type State struct {
	location2.MapContainer
	// contains filtered or unexported fields
}

func (*State) GetCalculation

func (s *State) GetCalculation(n string) *Calculation

func (*State) GetCalculations

func (s *State) GetCalculations() []*Calculation

type UseFirst

type UseFirst struct {
	Pos    lexer.Position
	Metric *Metric `parser:"'usefirst' @@"`
}

Jump to

Keyboard shortcuts

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