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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,8 @@ 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(),
|
||||||
|
HumidityTillDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +77,8 @@ 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(),
|
||||||
|
TemperatureTillDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,8 @@ 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(),
|
||||||
|
HumidityTillDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +77,8 @@ 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(),
|
||||||
|
TemperatureTillDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ 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(),
|
||||||
|
TemperatureTillDate: time.Now(),
|
||||||
SensorID: s.SensorID,
|
SensorID: s.SensorID,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,8 @@ import "time"
|
|||||||
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"`
|
||||||
|
HumidityTillDate time.Time `json:"humidity_till_date"`
|
||||||
SensorID string `json:"sensor_id"`
|
SensorID string `json:"sensor_id"`
|
||||||
CreationDate time.Time `json:"creation_date"`
|
CreationDate time.Time `json:"creation_date"`
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@ import "time"
|
|||||||
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"`
|
||||||
|
TemperatureTillDate time.Time `json:"temperature_till_date"`
|
||||||
SensorID string `json:"sensor_id"`
|
SensorID string `json:"sensor_id"`
|
||||||
CreationDate time.Time `json:"creation_date"`
|
CreationDate time.Time `json:"creation_date"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user