Refactor: remove unused code

This commit is contained in:
Alexander Zobnin
2021-09-15 16:40:16 +03:00
parent 8fa10bb76b
commit 2f08ed13ff
2 changed files with 5 additions and 81 deletions

View File

@@ -158,71 +158,3 @@ func PrepareForStack(series []*TimeSeriesData) []*TimeSeriesData {
return series
}
// AlignSeriesIntervals aligns series to the same time interval
func AlignSeriesIntervals(series []*TimeSeriesData) []*TimeSeriesData {
if len(series) == 0 {
return series
}
// Skip if interval not defined
for _, s := range series {
if s.Meta.Interval == nil {
return series
}
}
minInterval := *series[0].Meta.Interval
for _, s := range series {
if *s.Meta.Interval < minInterval {
minInterval = *s.Meta.Interval
}
}
// 0 interval means series is not aligned, so it's tricky to align multiple series
if minInterval == 0 {
return series
}
for _, s := range series {
if s.Len() < 2 || *s.Meta.Interval == minInterval {
continue
}
s.TS = s.TS.Interpolate(minInterval)
}
return series
}
func (ts TimeSeries) Interpolate(interval time.Duration) TimeSeries {
if interval <= 0 || ts.Len() < 2 {
return ts
}
alignedTs := NewTimeSeries()
var frameTs = ts[0].Time
var pointFrameTs time.Time
var point TimePoint
var nextPoint TimePoint
for i := 0; i < ts.Len()-1; i++ {
point = ts[i]
nextPoint = ts[i+1]
pointFrameTs = point.Time
if point.Value != nil && nextPoint.Value != nil {
frameTs = pointFrameTs.Add(interval)
for frameTs.Before(nextPoint.Time) {
pointValue := linearInterpolation(frameTs, point, nextPoint)
alignedTs = append(alignedTs, TimePoint{Time: frameTs, Value: &pointValue})
frameTs = frameTs.Add(interval)
}
}
alignedTs = append(alignedTs, TimePoint{Time: pointFrameTs, Value: point.Value})
frameTs = frameTs.Add(interval)
}
return alignedTs
}

View File

@@ -28,6 +28,11 @@ func (tsd *TimeSeriesData) Add(point TimePoint) *TimeSeriesData {
return tsd
}
// Gets point timestamp rounded according to provided interval.
func (p *TimePoint) GetTimeFrame(interval time.Duration) time.Time {
return p.Time.Round(interval)
}
// GroupBy groups points in given interval by applying provided `aggFunc`. Source time series should be sorted by time.
func (ts TimeSeries) GroupBy(interval time.Duration, aggFunc AggFunc) TimeSeries {
if ts.Len() == 0 {
@@ -285,19 +290,6 @@ func findNearestLeft(series TimeSeries, pointIndex int) *TimePoint {
return nil
}
// Gets point timestamp rounded according to provided interval.
func (p *TimePoint) GetTimeFrame(interval time.Duration) time.Time {
return p.Time.Round(interval)
}
func getPointTimeFrame(ts *time.Time, interval time.Duration) *time.Time {
if ts == nil {
return nil
}
timeFrame := ts.Truncate(interval)
return &timeFrame
}
func getTimeFieldIndex(frame *data.Frame) int {
for i := 0; i < len(frame.Fields); i++ {
if frame.Fields[i].Type() == data.FieldTypeTime {