Show all points for day

This commit is contained in:
Christoph Hagen
2023-06-14 17:52:43 +02:00
parent 2cb94a12be
commit 7cd697fb01
13 changed files with 116 additions and 41 deletions

View File

@ -56,12 +56,16 @@ final class TemperatureDataTransfer {
func add(data: Data, offset: Int, count: Int) {
guard currentByteIndex == offset else {
log.warning("Discarding \(data.count) bytes at offset \(offset), expected \(currentByteIndex)")
log.warning("Transfer: Discarding \(data.count) bytes at offset \(offset), expected \(currentByteIndex)")
return
}
if data.count != count {
log.warning("Transfer: Expected \(count) bytes, received only \(data.count)")
}
dataBuffer.append(data)
currentByteIndex += data.count
processBytes()
log.info("Transfer: \(currentByteIndex) bytes (added \(data.count)), \(measurements.count) points")
}
private func processBytes() {
@ -83,6 +87,10 @@ final class TemperatureDataTransfer {
func completeTransfer() {
processBytes()
if !dataBuffer.isEmpty {
log.warning("\(dataBuffer.count) bytes remaining in transfer buffer")
}
log.info("Transfer: \(currentByteIndex) bytes, \(measurements.count) points")
}
private func addRelative(byte: UInt8) {

View File

@ -27,7 +27,7 @@ struct TemperatureMeasurement: Identifiable {
return sensor1.optionalValue
}
guard let s1 = sensor1.optionalValue else {
return nil
return s0
}
return max(s0, s1)
}
@ -37,10 +37,27 @@ struct TemperatureMeasurement: Identifiable {
return sensor1.optionalValue
}
guard let s1 = sensor1.optionalValue else {
return nil
return s0
}
return min(s0, s1)
}
var averageValue: Double? {
guard let s0 = sensor0.optionalValue else {
return sensor1.optionalValue
}
guard let s1 = sensor1.optionalValue else {
return s0
}
return (s0 + s1) / 2
}
var displayText: String {
guard let averageValue else {
return "-"
}
return String(format: "%.1f °C", averageValue)
}
}
extension TemperatureMeasurement {