Store datapoint values with the problems
This commit is contained in:
parent
865f1ee184
commit
aa368c0b0d
3 changed files with 26 additions and 22 deletions
17
trigger.go
17
trigger.go
|
|
@ -14,11 +14,12 @@ import (
|
|||
)
|
||||
|
||||
type Trigger struct {
|
||||
ID int
|
||||
Name string
|
||||
SectionID int `db:"section_id"`
|
||||
Expression string
|
||||
Datapoints []string
|
||||
ID int
|
||||
Name string
|
||||
SectionID int `db:"section_id"`
|
||||
Expression string
|
||||
Datapoints []string
|
||||
DatapointValues map[string]any
|
||||
}
|
||||
|
||||
func TriggerCreate(sectionID int, name string) (t Trigger, err error) { // {{{
|
||||
|
|
@ -231,9 +232,9 @@ func (t *Trigger) Run() (output any, err error) { // {{{
|
|||
datapoints[dpname] = dp
|
||||
}
|
||||
|
||||
env := make(map[string]any)
|
||||
t.DatapointValues = make(map[string]any)
|
||||
for dpName, dp := range datapoints {
|
||||
env[dpName] = dp.LastDatapointValue.Value()
|
||||
t.DatapointValues[dpName] = dp.LastDatapointValue.Value()
|
||||
}
|
||||
|
||||
program, err := expr.Compile(t.Expression)
|
||||
|
|
@ -241,7 +242,7 @@ func (t *Trigger) Run() (output any, err error) { // {{{
|
|||
return
|
||||
}
|
||||
|
||||
output, err = expr.Run(program, env)
|
||||
output, err = expr.Run(program, t.DatapointValues)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue