当前位置: 首页>>代码示例>>Golang>>正文


Golang tsdb.RawQueryDerivativeProcessor类代码示例

本文整理汇总了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))
	}
}
开发者ID:kim-racktop,项目名称:influxdb,代码行数:11,代码来源:raw_test.go

示例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))
	}
}
开发者ID:kim-racktop,项目名称:influxdb,代码行数:19,代码来源:raw_test.go

示例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)
			}
		}
	}
}
开发者ID:nooproblem,项目名称:influxdb,代码行数:101,代码来源:executor_test.go


注:本文中的github.com/influxdb/influxdb/tsdb.RawQueryDerivativeProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。