本文整理汇总了Golang中github.com/datacratic/gotsvis/ts.TimeSeries类的典型用法代码示例。如果您正苦于以下问题:Golang TimeSeries类的具体用法?Golang TimeSeries怎么用?Golang TimeSeries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimeSeries类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: valueString
func valueString(ts *ts.TimeSeries, start, end time.Time) (string, error) {
s := bytes.NewBufferString("[ '")
if _, err := s.WriteString(ts.Key()); err != nil {
return "", err
}
if _, err := s.WriteString("', "); err != nil {
return "", err
}
for cursor, step := start, ts.Step(); cursor.Before(end); cursor = cursor.Add(step) {
v, _ := ts.GetAt(cursor)
if _, err := s.WriteString(strconv.FormatFloat(v, 'E', 2, 64)); err != nil {
return "", err
}
if err := s.WriteByte(','); err != nil {
return "", err
}
if step == 0 {
break
}
}
if s.Len() > 0 {
s.Truncate(s.Len() - 1)
}
if err := s.WriteByte(']'); err != nil {
return "", err
}
return s.String(), nil
}
示例2: timeString
func timeString(ts *ts.TimeSeries) (string, error) {
s := bytes.NewBufferString("[ 'x', ")
cursor := ts.Start()
step := ts.Step()
for _, _ = range ts.Data() {
if err := s.WriteByte('\''); err != nil {
return "", err
}
if _, err := s.WriteString(cursor.Format("20060102 15:04:05")); err != nil {
return "", err
}
if _, err := s.WriteString("',"); err != nil {
return "", err
}
cursor = cursor.Add(step)
}
if s.Len() > 0 {
s.Truncate(s.Len() - 1)
}
if err := s.WriteByte(']'); err != nil {
return "", err
}
return s.String(), nil
}
示例3: Write
func (carbon *Carbon) Write(ts *ts.TimeSeries) {
carbon.Init()
var buffer bytes.Buffer
it := ts.IteratorTimeValue()
for t, v, ok := it.Next(); ok; t, v, ok = it.Next() {
fmt.Fprintf(&buffer, "%s %f %d\n", ts.Key(), v, t.Unix())
}
go func() {
carbon.feed <- buffer
}()
}
示例4: checkTimeSeries
func checkTimeSeries(t *testing.T, got *ts.TimeSeries, exp *TestSeries) {
if got == nil {
t.Errorf("FAIL(TimeSeries): can't be nil")
return
}
if exp == nil {
t.Errorf("FAIL(TimeSeries): can't be nil")
return
}
checkKey(t, got.Key(), exp.Key)
checkStart(t, got.Start(), exp.Start)
checkEnd(t, got.End(), exp.End)
checkStep(t, got.Step(), exp.Step)
checkData(t, got.Data(), exp.Data)
}
示例5: Last
func Last(ts *ts.TimeSeries, predicate func(float64) bool) bool {
if ts == nil {
return false
}
last, ok := ts.Iterator().Last()
if !ok {
return false
}
return predicate(last)
}
示例6: Any
func Any(ts *ts.TimeSeries, predicate func(float64) bool) bool {
if ts == nil {
return false
}
it := ts.Iterator()
for val, ok := it.Next(); ok; val, ok = it.Next() {
if predicate(val) {
return true
}
}
return false
}
示例7: First
func First(ts *ts.TimeSeries, predicate func(float64) bool) (time.Time, float64, bool) {
if ts == nil {
return time.Time{}, NaN, false
}
it := ts.IteratorTimeValue()
for t, v, ok := it.Next(); ok; t, v, ok = it.Next() {
if predicate(v) {
return t, v, true
}
}
return time.Time{}, 0, false
}
示例8: ChartSingle
func ChartSingle(ts *ts.TimeSeries) (template.JS, error) {
if ts == nil {
return template.JS(""), nil
}
t, err := timeString(ts)
if err != nil {
return "", err
}
s := bytes.NewBufferString(t)
if err := s.WriteByte(','); err != nil {
return "", err
}
v, err := valueString(ts, ts.Start(), ts.End())
if err != nil {
return "", err
}
if _, err := s.WriteString(v); err != nil {
return "", err
}
return template.JS(s.String()), nil
}