2019-06-25 20:22:34 +00:00
|
|
|
package types
|
|
|
|
|
2019-07-02 20:33:01 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MeasuredValue struct {
|
|
|
|
ID string `json:"id" xml:"id"`
|
|
|
|
Value float64 `json:"value,string" xml:"value,string"`
|
|
|
|
ValueType MeasuredValueType `json:"value_type" xml:"value_type"`
|
|
|
|
FromDate time.Time `json:"from_date" xml:"from_date"`
|
|
|
|
TillDate time.Time `json:"till_date" xml:"till_date"`
|
|
|
|
SensorID string `json:"sensor_id" xml:"sensor_id"`
|
2019-10-11 10:36:00 +00:00
|
|
|
CreationDate *time.Time `json:"creation_date" xml:"creation_date"`
|
2019-07-02 20:33:01 +00:00
|
|
|
UpdateDate *time.Time `json:"update_date" xml:"update_date"`
|
2019-06-25 20:22:34 +00:00
|
|
|
}
|
2019-06-27 16:44:26 +00:00
|
|
|
|
|
|
|
type MeasuredValueType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
MeasuredValueTypeHumidity MeasuredValueType = "humidity"
|
2019-06-30 13:06:23 +00:00
|
|
|
MeasuredValueTypePressure MeasuredValueType = "pressure"
|
2019-06-27 16:44:26 +00:00
|
|
|
MeasuredValueTypeTemperature MeasuredValueType = "temperature"
|
|
|
|
)
|
|
|
|
|
|
|
|
var MeasuredValueTypes = []MeasuredValueType{
|
|
|
|
MeasuredValueTypeHumidity,
|
2019-06-30 13:06:23 +00:00
|
|
|
MeasuredValueTypePressure,
|
2019-06-27 16:44:26 +00:00
|
|
|
MeasuredValueTypeTemperature,
|
|
|
|
}
|
2019-07-02 20:33:01 +00:00
|
|
|
|
|
|
|
func SelectMeasuredValues(measuredValueType MeasuredValueType, measuredValues []*MeasuredValue) []*MeasuredValue {
|
|
|
|
cachedMeasuredValues := make([]*MeasuredValue, 0)
|
|
|
|
for _, measuredValue := range measuredValues {
|
|
|
|
if measuredValue.ValueType == measuredValueType {
|
|
|
|
cachedMeasuredValues = append(cachedMeasuredValues, measuredValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cachedMeasuredValues
|
|
|
|
}
|
|
|
|
|
|
|
|
func SelectMeasuredValueType(valueType string) (*MeasuredValueType, error) {
|
|
|
|
for _, measuredValueType := range MeasuredValueTypes {
|
|
|
|
if fmt.Sprint(measuredValueType) == valueType {
|
|
|
|
return &measuredValueType, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("Can not determine value type: %v", valueType)
|
|
|
|
}
|