github.com/m3db/m3@v1.5.0/src/query/block/series.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package block
    22  
    23  import (
    24  	"time"
    25  
    26  	"github.com/m3db/m3/src/query/ts"
    27  )
    28  
    29  // Series is a single series within a block.
    30  type Series struct {
    31  	values []float64
    32  	Meta   SeriesMeta
    33  }
    34  
    35  // NewSeries creates a new series.
    36  func NewSeries(values []float64, meta SeriesMeta) Series {
    37  	return Series{values: values, Meta: meta}
    38  }
    39  
    40  // ValueAtStep returns the datapoint value at a step index.
    41  func (s Series) ValueAtStep(idx int) float64 {
    42  	return s.values[idx]
    43  }
    44  
    45  // Values returns the internal values slice.
    46  func (s Series) Values() []float64 {
    47  	return s.values
    48  }
    49  
    50  // Len returns the number of datapoints in the series.
    51  func (s Series) Len() int {
    52  	return len(s.values)
    53  }
    54  
    55  // UnconsolidatedSeries is the series with raw datapoints.
    56  type UnconsolidatedSeries struct {
    57  	datapoints ts.Datapoints
    58  	Meta       SeriesMeta
    59  	stats      UnconsolidatedSeriesStats
    60  }
    61  
    62  // UnconsolidatedSeriesStats is stats about an unconsolidated series.
    63  type UnconsolidatedSeriesStats struct {
    64  	Enabled        bool
    65  	DecodeDuration time.Duration
    66  }
    67  
    68  // NewUnconsolidatedSeries creates a new series with raw datapoints.
    69  func NewUnconsolidatedSeries(
    70  	datapoints ts.Datapoints,
    71  	meta SeriesMeta,
    72  	stats UnconsolidatedSeriesStats,
    73  ) UnconsolidatedSeries {
    74  	return UnconsolidatedSeries{
    75  		datapoints: datapoints,
    76  		Meta:       meta,
    77  		stats:      stats,
    78  	}
    79  }
    80  
    81  // Datapoints returns the internal datapoints slice.
    82  func (s UnconsolidatedSeries) Datapoints() ts.Datapoints {
    83  	return s.datapoints
    84  }
    85  
    86  // Len returns the number of datapoints slices in the series.
    87  func (s UnconsolidatedSeries) Len() int {
    88  	return len(s.datapoints)
    89  }
    90  
    91  // Stats returns statistics about the unconsolidated series if they were supplied.
    92  func (s UnconsolidatedSeries) Stats() UnconsolidatedSeriesStats {
    93  	return s.stats
    94  }