fix(types): humidity and temperature with from and till date
This commit is contained in:
parent
5220eac16b
commit
a8aa7a14c5
@ -52,12 +52,12 @@ func GetTemperaturesBetweenTimeRange(from time.Time, till *time.Time, temperatur
|
|||||||
cachedTemperatures := []*types.Temperature{}
|
cachedTemperatures := []*types.Temperature{}
|
||||||
for _, temperature := range temperatures {
|
for _, temperature := range temperatures {
|
||||||
|
|
||||||
if till == nil && temperature.TemperatureDate.After(from) {
|
if temperature.TemperatureFromDate.After(from) && till == nil {
|
||||||
cachedTemperatures = append(cachedTemperatures, temperature)
|
cachedTemperatures = append(cachedTemperatures, temperature)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if temperature.TemperatureDate.After(from) && temperature.TemperatureDate.Before(*till) {
|
if temperature.TemperatureFromDate.After(from) && temperature.TemperatureTillDate.Before(*till) {
|
||||||
cachedTemperatures = append(cachedTemperatures, temperature)
|
cachedTemperatures = append(cachedTemperatures, temperature)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,10 +42,11 @@ func (s *DHT11) ReadHumidity() (*types.Humidity, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
humidity := &types.Humidity{
|
humidity := &types.Humidity{
|
||||||
HumidityID: uuid.NewV4().String(),
|
HumidityID: uuid.NewV4().String(),
|
||||||
HumidityValue: humidityValue,
|
HumidityValue: humidityValue,
|
||||||
HumidityDate: time.Now(),
|
HumidityFromDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
HumidityTillDate: time.Now(),
|
||||||
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return humidity, nil
|
return humidity, nil
|
||||||
@ -74,10 +75,11 @@ func (s *DHT11) ReadTemperature() (*types.Temperature, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
temperature := &types.Temperature{
|
temperature := &types.Temperature{
|
||||||
TemperatureID: uuid.NewV4().String(),
|
TemperatureID: uuid.NewV4().String(),
|
||||||
TemperatureValue: temperatureValue,
|
TemperatureValue: temperatureValue,
|
||||||
TemperatureDate: time.Now(),
|
TemperatureFromDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
TemperatureTillDate: time.Now(),
|
||||||
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return temperature, nil
|
return temperature, nil
|
||||||
|
@ -42,10 +42,11 @@ func (s *DHT22) ReadHumidity() (*types.Humidity, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
humidity := &types.Humidity{
|
humidity := &types.Humidity{
|
||||||
HumidityID: uuid.NewV4().String(),
|
HumidityID: uuid.NewV4().String(),
|
||||||
HumidityValue: humidityValue,
|
HumidityValue: humidityValue,
|
||||||
HumidityDate: time.Now(),
|
HumidityFromDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
HumidityTillDate: time.Now(),
|
||||||
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return humidity, nil
|
return humidity, nil
|
||||||
@ -74,10 +75,11 @@ func (s *DHT22) ReadTemperature() (*types.Temperature, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
temperature := &types.Temperature{
|
temperature := &types.Temperature{
|
||||||
TemperatureID: uuid.NewV4().String(),
|
TemperatureID: uuid.NewV4().String(),
|
||||||
TemperatureValue: temperatureValue,
|
TemperatureValue: temperatureValue,
|
||||||
TemperatureDate: time.Now(),
|
TemperatureFromDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
TemperatureTillDate: time.Now(),
|
||||||
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return temperature, nil
|
return temperature, nil
|
||||||
|
@ -33,10 +33,11 @@ func (s *DS18B20) ReadTemperature() (*types.Temperature, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
temperature := &types.Temperature{
|
temperature := &types.Temperature{
|
||||||
TemperatureID: uuid.NewV4().String(),
|
TemperatureID: uuid.NewV4().String(),
|
||||||
TemperatureValue: t,
|
TemperatureValue: t,
|
||||||
TemperatureDate: time.Now(),
|
TemperatureFromDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
TemperatureTillDate: time.Now(),
|
||||||
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
return temperature, nil
|
return temperature, nil
|
||||||
|
@ -4,9 +4,10 @@ import "time"
|
|||||||
|
|
||||||
// Humidity ...
|
// Humidity ...
|
||||||
type Humidity struct {
|
type Humidity struct {
|
||||||
HumidityID string `json:"humidity_id"`
|
HumidityID string `json:"humidity_id"`
|
||||||
HumidityValue float64 `json:"humidity_value,string"`
|
HumidityValue float64 `json:"humidity_value,string"`
|
||||||
HumidityDate time.Time `json:"humidity_date"`
|
HumidityFromDate time.Time `json:"humidity_from_date"`
|
||||||
SensorID string `json:"sensor_id"`
|
HumidityTillDate time.Time `json:"humidity_till_date"`
|
||||||
CreationDate time.Time `json:"creation_date"`
|
SensorID string `json:"sensor_id"`
|
||||||
|
CreationDate time.Time `json:"creation_date"`
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@ import "time"
|
|||||||
|
|
||||||
// Temperature ...
|
// Temperature ...
|
||||||
type Temperature struct {
|
type Temperature struct {
|
||||||
TemperatureID string `json:"temperature_id"`
|
TemperatureID string `json:"temperature_id"`
|
||||||
TemperatureValue float64 `json:"temperature_value,string"`
|
TemperatureValue float64 `json:"temperature_value,string"`
|
||||||
TemperatureDate time.Time `json:"temperature_date"`
|
TemperatureFromDate time.Time `json:"temperature_from_date"`
|
||||||
SensorID string `json:"sensor_id"`
|
TemperatureTillDate time.Time `json:"temperature_till_date"`
|
||||||
CreationDate time.Time `json:"creation_date"`
|
SensorID string `json:"sensor_id"`
|
||||||
|
CreationDate time.Time `json:"creation_date"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user