-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseries.go
42 lines (34 loc) · 1.02 KB
/
series.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package muse
import (
"github.com/google/uuid"
)
// Series is the general representation of timeseries containing only values.
type Series struct {
y []float64
labels *Labels
}
// NewSeries creates a new Series with a set of labels. If not labels are
// specified a unique ID is automatically generated
func NewSeries(y []float64, labels *Labels) *Series {
if labels == nil || labels.Len() == 0 {
labels = NewLabels(LabelMap{DefaultLabel: uuid.New().String()})
}
return &Series{y: y, labels: labels}
}
// Length returns the length of the timeseries
func (s *Series) Length() int {
return len(s.y)
}
// Values returns the y or series values
func (s *Series) Values() []float64 {
return s.y
}
// Labels returns the map of label to values for the timeseries
func (s *Series) Labels() *Labels {
return s.labels
}
// UID generates the unique identifier string that represents this particular
// timeseries. This must be unique within a timeseries Group
func (s *Series) UID() string {
return s.labels.ID(s.labels.Keys())
}