コード例 #1
0
ファイル: gadget_test.go プロジェクト: cswank/quimby
		Expect(p2.Time.Format(time.RFC3339)).To(Equal(ts2.Format(time.RFC3339)))
		Expect(p2.Value).To(Equal(0.0))

		p3 := points[2]
		Expect(p3.Time.Format(time.RFC3339)).To(Equal(ts2.Format(time.RFC3339)))
		Expect(p3.Value).To(Equal(1.0))
	})

	It("gets summarized datapoints", func() {
		l := 100

		points := make([]quimby.DataPoint, l)
		ts := time.Date(2016, 2, 2, 8, 12, 0, 0, time.UTC)
		var ts2 time.Time
		for i := 0; i < l; i++ {
			ts2 = ts.Add(time.Duration(i) * time.Minute)
			g.SaveDataPoint("kitchen temperature", quimby.DataPoint{Time: ts2, Value: float64(i)})
		}

		span := time.Duration(10 * time.Minute)
		points, err := g.GetDataPoints("kitchen temperature", ts, ts2, span, false)
		Expect(err).To(BeNil())
		Expect(len(points)).To(Equal(10))

		p1 := points[0]
		Expect(p1.Time.Format(time.RFC3339)).To(Equal("2016-02-02T08:22:00Z"))
		Expect(p1.Value).To(Equal(5.0))

		p2 := points[8]
		Expect(p2.Time.Format(time.RFC3339)).To(Equal("2016-02-02T09:50:00Z"))
		expected := (98.0 + 97.0 + 96.0 + 95.0 + 94.0 + 93.0 + 92.0 + 91.0 + 90.0 + 89.0 + 88.0) / 11.0