Fix data alignment on the backend
This commit is contained in:
@@ -35,6 +35,36 @@ func (ts TimeSeries) Align(interval time.Duration) TimeSeries {
|
||||
return alignedTs
|
||||
}
|
||||
|
||||
// Fill missing points in trend by null values
|
||||
func (ts TimeSeries) FillTrendWithNulls() TimeSeries {
|
||||
if ts.Len() < 2 {
|
||||
return ts
|
||||
}
|
||||
|
||||
interval := time.Hour
|
||||
alignedTs := NewTimeSeries()
|
||||
var frameTs = ts[0].GetTimeFrame(interval)
|
||||
var pointFrameTs time.Time
|
||||
var point TimePoint
|
||||
|
||||
for i := 0; i < ts.Len(); i++ {
|
||||
point = ts[i]
|
||||
pointFrameTs = point.GetTimeFrame(interval)
|
||||
|
||||
if pointFrameTs.After(frameTs) {
|
||||
for frameTs.Before(pointFrameTs) {
|
||||
alignedTs = append(alignedTs, TimePoint{Time: frameTs, Value: nil})
|
||||
frameTs = frameTs.Add(interval)
|
||||
}
|
||||
}
|
||||
|
||||
alignedTs = append(alignedTs, point)
|
||||
frameTs = frameTs.Add(interval)
|
||||
}
|
||||
|
||||
return alignedTs
|
||||
}
|
||||
|
||||
// Detects interval between data points in milliseconds based on median delta between points.
|
||||
func (ts TimeSeries) DetectInterval() time.Duration {
|
||||
if ts.Len() < 2 {
|
||||
|
||||
Reference in New Issue
Block a user