-
Notifications
You must be signed in to change notification settings - Fork 113
/
home_state.go
53 lines (44 loc) · 1.07 KB
/
home_state.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
43
44
45
46
47
48
49
50
51
52
53
package iot
import (
. "github.com/influxdata/influxdb-comparisons/bulk_data_gen/common"
"math/rand"
"time"
)
var HomeStates = [][]byte{
[]byte("Empty"),
[]byte("Half"),
[]byte("Full"),
}
var (
HomeStateByteString = []byte("home_state") // heap optimization
)
var (
// Field keys for 'air condition indoor' points.
HomeStateFieldKeys = [][]byte{
[]byte("state"),
[]byte("state_string"),
}
)
type HomeStateMeasurement struct {
sensorId []byte
timestamp time.Time
state int64
}
func NewHomeStateMeasurement(start time.Time, id []byte) *HomeStateMeasurement {
return &HomeStateMeasurement{
timestamp: start,
sensorId: id,
}
}
func (m *HomeStateMeasurement) Tick(d time.Duration) {
m.timestamp = m.timestamp.Add(d)
m.state = rand.Int63n(int64(len(HomeStates)))
}
func (m *HomeStateMeasurement) ToPoint(p *Point) bool {
p.SetMeasurementName(HomeStateByteString)
p.SetTimestamp(&m.timestamp)
p.AppendTag(SensorHomeTagKeys[0], m.sensorId)
p.AppendField(HomeStateFieldKeys[0], m.state)
p.AppendField(HomeStateFieldKeys[1], HomeStates[m.state])
return true
}