fix(types): humidity and temperature with from and till date

This commit is contained in:
Markus Pesch 2019-06-13 22:22:12 +02:00
parent 5220eac16b
commit a8aa7a14c5
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
6 changed files with 39 additions and 32 deletions

View File

@ -52,12 +52,12 @@ func GetTemperaturesBetweenTimeRange(from time.Time, till *time.Time, temperatur
cachedTemperatures := []*types.Temperature{}
for _, temperature := range temperatures {
if till == nil && temperature.TemperatureDate.After(from) {
if temperature.TemperatureFromDate.After(from) && till == nil {
cachedTemperatures = append(cachedTemperatures, temperature)
continue
}
if temperature.TemperatureDate.After(from) && temperature.TemperatureDate.Before(*till) {
if temperature.TemperatureFromDate.After(from) && temperature.TemperatureTillDate.Before(*till) {
cachedTemperatures = append(cachedTemperatures, temperature)
}
}

View File

@ -42,10 +42,11 @@ func (s *DHT11) ReadHumidity() (*types.Humidity, error) {
}
humidity := &types.Humidity{
HumidityID: uuid.NewV4().String(),
HumidityValue: humidityValue,
HumidityDate: time.Now(),
SensorID: s.SensorID,
HumidityID: uuid.NewV4().String(),
HumidityValue: humidityValue,
HumidityFromDate: time.Now(),
HumidityTillDate: time.Now(),
SensorID: s.SensorID,
}
return humidity, nil
@ -74,10 +75,11 @@ func (s *DHT11) ReadTemperature() (*types.Temperature, error) {
}
temperature := &types.Temperature{
TemperatureID: uuid.NewV4().String(),
TemperatureValue: temperatureValue,
TemperatureDate: time.Now(),
SensorID: s.SensorID,
TemperatureID: uuid.NewV4().String(),
TemperatureValue: temperatureValue,
TemperatureFromDate: time.Now(),
TemperatureTillDate: time.Now(),
SensorID: s.SensorID,
}
return temperature, nil

View File

@ -42,10 +42,11 @@ func (s *DHT22) ReadHumidity() (*types.Humidity, error) {
}
humidity := &types.Humidity{
HumidityID: uuid.NewV4().String(),
HumidityValue: humidityValue,
HumidityDate: time.Now(),
SensorID: s.SensorID,
HumidityID: uuid.NewV4().String(),
HumidityValue: humidityValue,
HumidityFromDate: time.Now(),
HumidityTillDate: time.Now(),
SensorID: s.SensorID,
}
return humidity, nil
@ -74,10 +75,11 @@ func (s *DHT22) ReadTemperature() (*types.Temperature, error) {
}
temperature := &types.Temperature{
TemperatureID: uuid.NewV4().String(),
TemperatureValue: temperatureValue,
TemperatureDate: time.Now(),
SensorID: s.SensorID,
TemperatureID: uuid.NewV4().String(),
TemperatureValue: temperatureValue,
TemperatureFromDate: time.Now(),
TemperatureTillDate: time.Now(),
SensorID: s.SensorID,
}
return temperature, nil

View File

@ -33,10 +33,11 @@ func (s *DS18B20) ReadTemperature() (*types.Temperature, error) {
}
temperature := &types.Temperature{
TemperatureID: uuid.NewV4().String(),
TemperatureValue: t,
TemperatureDate: time.Now(),
SensorID: s.SensorID,
TemperatureID: uuid.NewV4().String(),
TemperatureValue: t,
TemperatureFromDate: time.Now(),
TemperatureTillDate: time.Now(),
SensorID: s.SensorID,
}
return temperature, nil

View File

@ -4,9 +4,10 @@ import "time"
// Humidity ...
type Humidity struct {
HumidityID string `json:"humidity_id"`
HumidityValue float64 `json:"humidity_value,string"`
HumidityDate time.Time `json:"humidity_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
HumidityID string `json:"humidity_id"`
HumidityValue float64 `json:"humidity_value,string"`
HumidityFromDate time.Time `json:"humidity_from_date"`
HumidityTillDate time.Time `json:"humidity_till_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
}

View File

@ -4,9 +4,10 @@ import "time"
// Temperature ...
type Temperature struct {
TemperatureID string `json:"temperature_id"`
TemperatureValue float64 `json:"temperature_value,string"`
TemperatureDate time.Time `json:"temperature_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
TemperatureID string `json:"temperature_id"`
TemperatureValue float64 `json:"temperature_value,string"`
TemperatureFromDate time.Time `json:"temperature_from_date"`
TemperatureTillDate time.Time `json:"temperature_till_date"`
SensorID string `json:"sensor_id"`
CreationDate time.Time `json:"creation_date"`
}