本文整理汇总了Golang中github.com/influxdb/influxdb/tsdb.RawQueryDerivativeProcessor类的典型用法代码示例。如果您正苦于以下问题:Golang RawQueryDerivativeProcessor类的具体用法?Golang RawQueryDerivativeProcessor怎么用?Golang RawQueryDerivativeProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RawQueryDerivativeProcessor类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestRawQueryDerivative_Process_Empty
func TestRawQueryDerivative_Process_Empty(t *testing.T) {
p := tsdb.RawQueryDerivativeProcessor{
IsNonNegative: false,
DerivativeInterval: 24 * time.Hour,
}
results := p.Process([]*tsdb.MapperValue{})
if !reflect.DeepEqual(results, []*tsdb.MapperValue{}) {
t.Fatalf("unexpected results: %s", spew.Sdump(results))
}
}
示例2: TestRawQueryDerivative_Process_Negative_NonNegative
func TestRawQueryDerivative_Process_Negative_NonNegative(t *testing.T) {
p := tsdb.RawQueryDerivativeProcessor{
IsNonNegative: true,
DerivativeInterval: 24 * time.Hour,
}
results := p.Process([]*tsdb.MapperValue{
{Time: time.Unix(0, 0).Unix(), Value: 1.0},
{Time: time.Unix(0, 0).Add(24 * time.Hour).UnixNano(), Value: 2.0},
{Time: time.Unix(0, 0).Add(48 * time.Hour).UnixNano(), Value: 0.0},
{Time: time.Unix(0, 0).Add(72 * time.Hour).UnixNano(), Value: 4.0},
})
if !reflect.DeepEqual(results, []*tsdb.MapperValue{
{Time: time.Unix(0, 0).Add(24 * time.Hour).UnixNano(), Value: 1.0},
{Time: time.Unix(0, 0).Add(72 * time.Hour).UnixNano(), Value: 4.0},
}) {
t.Fatalf("unexpected results: %s", spew.Sdump(results))
}
}
示例3: TestProcessRawQueryDerivative
//.........这里部分代码省略.........
},
},
exp: []*tsdb.MapperValue{
{
Time: time.Unix(0, 0).Add(24 * time.Hour).UnixNano(),
Value: 1.0,
},
{
Time: time.Unix(0, 0).Add(48 * time.Hour).UnixNano(),
Value: -2.0,
},
{
Time: time.Unix(0, 0).Add(72 * time.Hour).UnixNano(),
Value: 4.0,
},
},
},
{
name: "negative derivatives",
fn: "non_negative_derivative",
interval: 24 * time.Hour,
in: []*tsdb.MapperValue{
{
Time: time.Unix(0, 0).Unix(),
Value: 1.0,
},
{
Time: time.Unix(0, 0).Add(24 * time.Hour).UnixNano(),
Value: 2.0,
},
// should go negative
{
Time: time.Unix(0, 0).Add(48 * time.Hour).UnixNano(),
Value: 0.0,
},
{
Time: time.Unix(0, 0).Add(72 * time.Hour).UnixNano(),
Value: 4.0,
},
},
exp: []*tsdb.MapperValue{
{
Time: time.Unix(0, 0).Add(24 * time.Hour).UnixNano(),
Value: 1.0,
},
{
Time: time.Unix(0, 0).Add(72 * time.Hour).UnixNano(),
Value: 4.0,
},
},
},
{
name: "string derivatives",
fn: "derivative",
interval: 24 * time.Hour,
in: []*tsdb.MapperValue{
{
Time: time.Unix(0, 0).Unix(),
Value: "1.0",
},
{
Time: time.Unix(0, 0).Add(24 * time.Hour).UnixNano(),
Value: "2.0",
},
{
Time: time.Unix(0, 0).Add(48 * time.Hour).UnixNano(),
Value: "3.0",
},
{
Time: time.Unix(0, 0).Add(72 * time.Hour).UnixNano(),
Value: "4.0",
},
},
exp: []*tsdb.MapperValue{
{
Time: time.Unix(0, 0).Unix(),
Value: 0.0,
},
},
},
}
for _, test := range tests {
p := tsdb.RawQueryDerivativeProcessor{
IsNonNegative: test.fn == "non_negative_derivative",
DerivativeInterval: test.interval,
}
got := p.Process(test.in)
if len(got) != len(test.exp) {
t.Fatalf("RawQueryDerivativeProcessor(%s) - %s\nlen mismatch: got %d, exp %d", test.fn, test.name, len(got), len(test.exp))
}
for i := 0; i < len(test.exp); i++ {
if test.exp[i].Time != got[i].Time || math.Abs((test.exp[i].Value.(float64)-got[i].Value.(float64))) > 0.0000001 {
t.Fatalf("RawQueryDerivativeProcessor - %s results mismatch:\ngot %v\nexp %v", test.name, got, test.exp)
}
}
}
}