Skip to content

Commit

Permalink
Merge pull request #251 from USACE/fix/computed-timeseries-nan-inf-re…
Browse files Browse the repository at this point in the history
…gression

fix: computed timeseries NAN/INF regression
  • Loading branch information
dennisgsmith authored Jan 25, 2025
2 parents e71c5b1 + 00a6a3a commit cbde5c8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions api/internal/db/timeseries_process.manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"math"
"strconv"
"strings"
Expand Down Expand Up @@ -215,28 +216,32 @@ func (q *Queries) ProcessMeasurementListDynamicEXPERIMENTAL(ctx context.Context,
func collectAggregate(tss *ProcessTimeseriesResponseCollection) *btree.BTreeG[BTreeNode] {
// Get unique set of all measurement times of timeseries dependencies for non-regularized values
btm := btree.NewBTreeG(func(a, b BTreeNode) bool { return a.Key.Before(b.Key) })
if tss == nil {
log.Print("cannot collectAggregate: timeseries slice is nil")
return btm
}
for _, ts := range *tss {
if ts.NextMeasurementLow != nil {
if item, exists := btm.Get(BTreeNode{Key: ts.NextMeasurementLow.Time}); !exists {
btm.Set(BTreeNode{Key: ts.NextMeasurementLow.Time, Value: map[string]interface{}{ts.Variable: ts.NextMeasurementLow.Value}})
btm.Set(BTreeNode{Key: ts.NextMeasurementLow.Time, Value: map[string]interface{}{ts.Variable: float64(ts.NextMeasurementLow.Value)}})
} else {
item.Value[ts.Variable] = ts.NextMeasurementLow.Value
item.Value[ts.Variable] = float64(ts.NextMeasurementLow.Value)
btm.Set(item)
}
}
for _, m := range ts.Measurements {
if item, exists := btm.Get(BTreeNode{Key: m.Time}); !exists {
btm.Set(BTreeNode{Key: m.Time, Value: map[string]interface{}{ts.Variable: m.Value}})
btm.Set(BTreeNode{Key: m.Time, Value: map[string]interface{}{ts.Variable: float64(m.Value)}})
} else {
item.Value[ts.Variable] = m.Value
item.Value[ts.Variable] = float64(m.Value)
btm.Set(item)
}
}
if ts.NextMeasurementHigh != nil {
if item, exists := btm.Get(BTreeNode{Key: ts.NextMeasurementHigh.Time}); !exists {
btm.Set(BTreeNode{Key: ts.NextMeasurementHigh.Time, Value: map[string]interface{}{ts.Variable: ts.NextMeasurementHigh.Value}})
btm.Set(BTreeNode{Key: ts.NextMeasurementHigh.Time, Value: map[string]interface{}{ts.Variable: float64(ts.NextMeasurementHigh.Value)}})
} else {
item.Value[ts.Variable] = ts.NextMeasurementHigh.Value
item.Value[ts.Variable] = float64(ts.NextMeasurementHigh.Value)
btm.Set(item)
}
}
Expand Down Expand Up @@ -280,6 +285,9 @@ func processLOCF(tss ProcessTimeseriesResponseCollection) (ProcessTimeseriesResp
continue
}

if ts.Formula == nil {
continue
}
// By now, all of the stored timeseries have been processed;
// the query is ordered in a way that priortizes stored timeseries
expr, err := govaluate.NewEvaluableExpression(*ts.Formula)
Expand Down

0 comments on commit cbde5c8

Please sign in to comment.