53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package types
|
|
|
|
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"`
|
|
CreationDate time.Time `json:"creation_date" xml:"creation_date"`
|
|
UpdateDate *time.Time `json:"update_date" xml:"update_date"`
|
|
}
|
|
|
|
type MeasuredValueType string
|
|
|
|
const (
|
|
MeasuredValueTypeHumidity MeasuredValueType = "humidity"
|
|
MeasuredValueTypePressure MeasuredValueType = "pressure"
|
|
MeasuredValueTypeTemperature MeasuredValueType = "temperature"
|
|
)
|
|
|
|
var MeasuredValueTypes = []MeasuredValueType{
|
|
MeasuredValueTypeHumidity,
|
|
MeasuredValueTypePressure,
|
|
MeasuredValueTypeTemperature,
|
|
}
|
|
|
|
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)
|
|
}
|