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

@ -44,7 +44,8 @@ func (s *DHT11) ReadHumidity() (*types.Humidity, error) {
humidity := &types.Humidity{
HumidityID: uuid.NewV4().String(),
HumidityValue: humidityValue,
HumidityDate: time.Now(),
HumidityFromDate: time.Now(),
HumidityTillDate: time.Now(),
SensorID: s.SensorID,
}
@ -76,7 +77,8 @@ func (s *DHT11) ReadTemperature() (*types.Temperature, error) {
temperature := &types.Temperature{
TemperatureID: uuid.NewV4().String(),
TemperatureValue: temperatureValue,
TemperatureDate: time.Now(),
TemperatureFromDate: time.Now(),
TemperatureTillDate: time.Now(),
SensorID: s.SensorID,
}

View File

@ -44,7 +44,8 @@ func (s *DHT22) ReadHumidity() (*types.Humidity, error) {
humidity := &types.Humidity{
HumidityID: uuid.NewV4().String(),
HumidityValue: humidityValue,
HumidityDate: time.Now(),
HumidityFromDate: time.Now(),
HumidityTillDate: time.Now(),
SensorID: s.SensorID,
}
@ -76,7 +77,8 @@ func (s *DHT22) ReadTemperature() (*types.Temperature, error) {
temperature := &types.Temperature{
TemperatureID: uuid.NewV4().String(),
TemperatureValue: temperatureValue,
TemperatureDate: time.Now(),
TemperatureFromDate: time.Now(),
TemperatureTillDate: time.Now(),
SensorID: s.SensorID,
}

View File

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

View File

@ -6,7 +6,8 @@ import "time"
type Humidity struct {
HumidityID string `json:"humidity_id"`
HumidityValue float64 `json:"humidity_value,string"`
HumidityDate time.Time `json:"humidity_date"`
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

@ -6,7 +6,8 @@ import "time"
type Temperature struct {
TemperatureID string `json:"temperature_id"`
TemperatureValue float64 `json:"temperature_value,string"`
TemperatureDate time.Time `json:"temperature_date"`
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"`
}