Compare commits
1 Commits
master
...
feature/nt
| Author | SHA1 | Date |
|---|---|---|
|
|
7a659cc044 |
|
|
@ -61,7 +61,7 @@ func unitToSeconds(unit string) float64 {
|
|||
}
|
||||
|
||||
func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error {
|
||||
condition := map[string]any{}
|
||||
condition := map[string]interface{}{}
|
||||
err := json.Unmarshal([]byte(alert.Condition), &condition)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -86,7 +86,7 @@ func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error {
|
|||
|
||||
sensorId = int64(sensorValueCondition.SensorId)
|
||||
|
||||
value, err := s.ctx.Services.SensorValues.GetLatestToNow(sensorValueCondition.SensorId)
|
||||
value, err := s.ctx.Services.SensorValues.GetLatest(sensorValueCondition.SensorId, time.Now().Unix())
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
lastValue = float64(0)
|
||||
|
|
@ -112,7 +112,7 @@ func (s *AlertsEvaluatorService) EvaluateAlert(alert *models.AlertItem) error {
|
|||
|
||||
sensorId = sensorLastContactCondition.SensorId
|
||||
|
||||
value, err := s.ctx.Services.SensorValues.GetLatestToNow(sensorLastContactCondition.SensorId)
|
||||
value, err := s.ctx.Services.SensorValues.GetLatest(sensorLastContactCondition.SensorId, time.Now().Unix())
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
|
|
|
|||
|
|
@ -48,19 +48,6 @@ func (s *SensorValuesService) GetLatest(sensorId int64, to int64) (*sensorValue,
|
|||
return &value, nil
|
||||
}
|
||||
|
||||
func (s *SensorValuesService) GetLatestToNow(sensorId int64) (*sensorValue, error) {
|
||||
var value = sensorValue{}
|
||||
|
||||
row := s.ctx.DB.QueryRow("SELECT timestamp, value FROM sensor_values WHERE sensor_id = ? ORDER BY timestamp DESC LIMIT 1", sensorId)
|
||||
|
||||
err := row.Scan(&value.Timestamp, &value.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &value, nil
|
||||
}
|
||||
|
||||
func (s *SensorValuesService) Cleanup(retentionInDays int64) error {
|
||||
if retentionInDays <= 0 {
|
||||
return fmt.Errorf("retentionInDays must be greater than 0")
|
||||
|
|
|
|||
Loading…
Reference in New Issue