Improve temperature accuracy and layout

This commit is contained in:
Christoph Hagen 2023-08-09 17:13:53 +02:00
parent d1a24b581d
commit dfa9f716d4
6 changed files with 16 additions and 10 deletions

View File

@ -167,9 +167,12 @@ final class PersistentStorage: ObservableObject {
} }
func removeMeasurements(for dateIndex: Int) { func removeMeasurements(for dateIndex: Int) {
defer { saveDailyCounts() }
let fileUrl = fileUrl(for: dateIndex) let fileUrl = fileUrl(for: dateIndex)
guard fm.fileExists(atPath: fileUrl.path) else { guard fm.fileExists(atPath: fileUrl.path) else {
log.warning("No measurements for \(fileUrl.lastPathComponent)") log.warning("No measurements for \(fileUrl.lastPathComponent)")
dailyMeasurementCounts = dailyMeasurementCounts.filter { $0.dateIndex != dateIndex }
recentMeasurements = recentMeasurements.filter { $0.date.dateIndex != dateIndex }
return return
} }
do { do {

View File

@ -53,10 +53,7 @@ struct TemperatureMeasurement: Identifiable {
} }
var displayText: String { var displayText: String {
guard let averageValue else { "\(sensor0.text) / \(sensor1.text)"
return "-"
}
return String(format: "%.1f °C", averageValue)
} }
} }

View File

@ -23,7 +23,7 @@ enum TemperatureValue {
case .invalidMeasurement: case .invalidMeasurement:
return 1 return 1
case .value(let double): case .value(let double):
let value = Int(double + 40) * 2 let value = (double * 2).roundedInt + 80
return UInt8(clamping: value) return UInt8(clamping: value)
} }
} }
@ -45,11 +45,11 @@ enum TemperatureValue {
var text: String { var text: String {
switch self { switch self {
case .notFound: case .notFound:
return "No sensor" return "-"
case .invalidMeasurement: case .invalidMeasurement:
return "Invalid" return "?"
case .value(let value): case .value(let value):
return String(format:"%.1f°C", value) return String(format:"%.1f°", value)
} }
} }
} }

View File

@ -7,6 +7,13 @@ private let df: DateFormatter = {
return df return df
}() }()
private let dateFormatter: DateFormatter = {
let df = DateFormatter()
df.dateStyle = .medium
df.timeStyle = .none
return df
}()
struct DayView: View { struct DayView: View {
let dateIndex: Int let dateIndex: Int

View File

@ -47,7 +47,7 @@ struct TemperatureDayOverview: View {
} }
} }
} }
.aspectRatio(2.6, contentMode: .fit) .aspectRatio(1, contentMode: .fit)
//.chartXScale(domain: pastDateLimit...futureDateLimit) //.chartXScale(domain: pastDateLimit...futureDateLimit)
.chartYScale(domain: lowerTempLimit...upperTempLimit) .chartYScale(domain: lowerTempLimit...upperTempLimit)
.chartXAxis { .chartXAxis {
@ -71,7 +71,6 @@ struct TemperatureDayOverview: View {
AxisGridLine() AxisGridLine()
} }
} }
.padding()
} }
} }