Skip to content

Commit d134ad7

Browse files
committed
fix: better handling of ata_sct_temperature_history (upstream PR AnalogJ#825)
2 parents 2d6ffa7 + 12e62bb commit d134ad7

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

webapp/backend/pkg/database/scrutiny_repository_temperature.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ func (sr *scrutinyRepository) SaveSmartTemperature(ctx context.Context, wwn stri
2323
continue
2424
}
2525

26-
minutesOffset := collectorSmartData.AtaSctTemperatureHistory.LoggingIntervalMinutes * int64(ndx) * 60
26+
intervalSec := collectorSmartData.AtaSctTemperatureHistory.LoggingIntervalMinutes * 60
27+
datapointTime := collectorSmartData.LocalTime.TimeT - int64(ndx) * intervalSec
28+
alignedDatapointTime := datapointTime - datapointTime % intervalSec
2729
smartTemp := measurements.SmartTemperature{
28-
Date: time.Unix(collectorSmartData.LocalTime.TimeT-minutesOffset, 0),
30+
Date: time.Unix(alignedDatapointTime, 0),
2931
Temp: temp,
3032
}
3133

@@ -40,23 +42,22 @@ func (sr *scrutinyRepository) SaveSmartTemperature(ctx context.Context, wwn stri
4042
return err
4143
}
4244
}
43-
// also add the current temperature.
44-
} else {
45+
}
4546

46-
smartTemp := measurements.SmartTemperature{
47-
Date: time.Unix(collectorSmartData.LocalTime.TimeT, 0),
48-
Temp: collectorSmartData.Temperature.Current,
49-
}
5047

51-
tags, fields := smartTemp.Flatten()
52-
tags["device_wwn"] = wwn
53-
p := influxdb2.NewPoint("temp",
54-
tags,
55-
fields,
56-
smartTemp.Date)
57-
return sr.influxWriteApi.WritePoint(ctx, p)
48+
// Even if ata_sct_temperature_history is present, also add current temperature. See #824
49+
smartTemp := measurements.SmartTemperature{
50+
Date: time.Unix(collectorSmartData.LocalTime.TimeT, 0),
51+
Temp: collectorSmartData.Temperature.Current,
5852
}
59-
return nil
53+
54+
tags, fields := smartTemp.Flatten()
55+
tags["device_wwn"] = wwn
56+
p := influxdb2.NewPoint("temp",
57+
tags,
58+
fields,
59+
smartTemp.Date)
60+
return sr.influxWriteApi.WritePoint(ctx, p)
6061
}
6162

6263
func (sr *scrutinyRepository) GetSmartTemperatureHistory(ctx context.Context, durationKey string) (map[string][]measurements.SmartTemperature, error) {

0 commit comments

Comments
 (0)