← All repositories

reportage

A life-logging app for iPhone

git clone https://code.inqk.net/reportage.git


commit 543b89ea9839d98fc0883d7f8380ee8e5eddd22b
parent 9fd0157185c163e0bfe9cba9a7cb5f18f8f5377e
Author: Michael Camilleri <[email protected]>
Date:   Wed, 21 Oct 2026 12:12:20 +0900

Move Health and address upgrades to a Historical Data screen

The Data section of Settings held two actions that improve reports
already filed, and explaining either beneath its button made the top
level of Settings hard to scan. This commit moves them to a Historical
Data screen.

Upgrade Address Format also no longer gives an address to a report that
did not have an address.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

Diffstat

MNotes/Design.md | 8++++----
MReportage.xcodeproj/project.pbxproj | 4++++
MReportage/Services/Places/AddressFill.swift | 13+++++++------
MReportage/Views/Settings/DataSection.swift | 73++++++++++---------------------------------------------------------------
AReportage/Views/Settings/HistoricalDataView.swift | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MTests/Unit/AddressFillTests.swift | 17++++++++++-------

6 files changed, 132 insertions(+), 80 deletions(-)

diff --git a/Notes/Design.md b/Notes/Design.md

@@ -742,7 +742,7 @@ once more, so it can ask.
 Reports filed after Health was first asked for are filled in automatically:
 as soon as they're saved if the iPhone is unlocked, and otherwise the next
 time the app comes to the foreground. Earlier reports, the imported archive included, are filled in only when the
-user asks, with **Backfill Health Data** in Settings' Data section. It works
+user asks, with **Import Health Data**, on the Historical Data screen in Settings' Data section. It works
 newest first and in batches, and can be stopped and run again; it skips
 reports already settled.
 
@@ -925,7 +925,7 @@ Source: Reporter's JSON export, which has two top-level arrays, `questions` and
 - **Addresses are updated to MapKit's form afterwards.** Reporter's
   addresses came from the geocoder of their day, in whatever language the
   device used, without the country code or city with its region that
-  MapKit gives. **Upgrade Address Format** in Settings' Data section looks each
+  MapKit gives. **Upgrade Address Format**, on the Historical Data screen in Settings' Data section, looks each
   one up again as capture does, in the user's first language and the
   place's own, and replaces it. Reports
   within 25 m of each other share a lookup, since a fix is rarely better
@@ -933,8 +933,8 @@ Source: Reporter's JSON export, which has two top-level arrays, `questions` and
   waits out MapKit's throttling, keeps the screen on while it runs, and
   skips reports whose address is already MapKit's (it records its
   language), so stopping and starting again carries on. A spot MapKit has
-  no address for keeps the old one. It also covers new reports filed
-  before their address was found.
+  no address for keeps the old one. A report without an address has
+  nothing to upgrade, so it's left without one.
 - **The export file is the original.** Reportage keeps what it models and
   drops the rest: imperial duplicates of metric readings, weather and
   altitude fields it doesn't show, Reporter's own flags and sub-record IDs,

diff --git a/Reportage.xcodeproj/project.pbxproj b/Reportage.xcodeproj/project.pbxproj

@@ -83,6 +83,7 @@
 		BD1AA0F75635BF9C68DFA12A /* NarrativeRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = E67FAC24A684AA62ED63441A /* NarrativeRule.swift */; };
 		BD8D81CBF8C3DE544BB7540C /* DefaultQuestions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94DB0CA378AEF82B3CB27B67 /* DefaultQuestions.swift */; };
 		BDEB83CDBA9E0B4DB7712491 /* LogPassiveReportIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 90F9BD4EA70DCB46924CF9B8 /* LogPassiveReportIntent.swift */; };
+		C53A1010AF7D720A71E63C5D /* HistoricalDataView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EC45BA4E4F82AC5DC8FBDE2 /* HistoricalDataView.swift */; };
 		C5D94FEC4507054E6497E85B /* PersistenceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61C0B5BB02ECDBE84F5F73FA /* PersistenceController.swift */; };
 		C71E99843CC3D9DE4468B36B /* Environment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 878CE0FF7A2598F4197E8E61 /* Environment.swift */; };
 		C87E1C0465FE7B2917F92846 /* PromptSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB87A3E922FA7AE98B93DF1E /* PromptSettings.swift */; };
@@ -151,6 +152,7 @@
 		0A246867F8FAC9D3FFABD61D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
 		0B35602A218BE4EE399835FD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
 		0E6B536B922A8468136815CD /* QuestionListTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionListTests.swift; sourceTree = "<group>"; };
+		0EC45BA4E4F82AC5DC8FBDE2 /* HistoricalDataView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoricalDataView.swift; sourceTree = "<group>"; };
 		1458729667512D1B7E04D92F /* QuestionEditor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionEditor.swift; sourceTree = "<group>"; };
 		1AD7CB7E9FF6D01BF4CE8617 /* AboutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutView.swift; sourceTree = "<group>"; };
 		1B5C26C38B8B25086810CAB1 /* HealthReader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthReader.swift; sourceTree = "<group>"; };
@@ -522,6 +524,7 @@
 				1AD7CB7E9FF6D01BF4CE8617 /* AboutView.swift */,
 				CA2E66BAB2463FD51EFE9F52 /* DataSection.swift */,
 				87545A7909A370C668314DFF /* DiagnosticsSection.swift */,
+				0EC45BA4E4F82AC5DC8FBDE2 /* HistoricalDataView.swift */,
 				F832E0B277D5BF5BC3B6E5D1 /* NotificationsView.swift */,
 				1458729667512D1B7E04D92F /* QuestionEditor.swift */,
 				7F9A0A87A54F3E96E079F52D /* QuestionsView.swift */,
@@ -778,6 +781,7 @@
 				19FD732027A16A84552DFD0E /* HealthContext.swift in Sources */,
 				6E6EAFD0C182B2482F6B6FBD /* HealthFill.swift in Sources */,
 				D7E440B08D6F133B8DD9B5C9 /* HealthReader.swift in Sources */,
+				C53A1010AF7D720A71E63C5D /* HistoricalDataView.swift in Sources */,
 				83E954F0DAC9719D2AA02111 /* HomeView.swift in Sources */,
 				6E21E729F89178EBD019980E /* InlineCasing.swift in Sources */,
 				275A9497C40065F5C77AE473 /* InstantReportLogger.swift in Sources */,

diff --git a/Reportage/Services/Places/AddressFill.swift b/Reportage/Services/Places/AddressFill.swift

@@ -4,9 +4,9 @@ import Foundation
 import MapKit
 import UIKit
 
-/// A report with a location whose address isn't in the form MapKit gives
-/// new reports: one imported from Reporter, whose address came from the
-/// geocoder of its day, or one captured before its address was found.
+/// A report whose address isn't in the form MapKit gives new reports, such
+/// as one imported from Reporter, whose address came from the geocoder of
+/// its day.
 struct AddressTarget: Equatable, Sendable {
     var id: UUID
     var coordinate: Coordinate
@@ -166,8 +166,9 @@ struct AddressFill: Sendable {
 }
 
 extension ReportStore {
-    /// Reports with a location whose address isn't in MapKit's form, newest
-    /// first. MapKit's addresses record their language; older ones don't.
+    /// Reports with an address that isn't in MapKit's form, newest first.
+    /// MapKit's addresses record their language; older ones don't. A report
+    /// without an address has nothing to upgrade, and is left without one.
     func addressTargets() async throws -> [AddressTarget] {
         let context = persistence.newBackgroundContext()
         return try await context.perform {
@@ -179,7 +180,7 @@ extension ReportStore {
             for entity in try context.fetch(request) {
                 guard let id = entity.id, let data = entity.context,
                     let location = try ModelCoding.decode(Context.self, from: data).location,
-                    location.placemark?.language == nil
+                    let placemark = location.placemark, placemark.language == nil
                 else { continue }
                 targets.append(AddressTarget(id: id, coordinate: location.coordinate))
                 // Decoded contexts aren't needed once read.

diff --git a/Reportage/Views/Settings/DataSection.swift b/Reportage/Views/Settings/DataSection.swift

@@ -3,8 +3,8 @@ import OSLog
 import SwiftUI
 import UniformTypeIdentifiers
 
-/// Importing a Reporter export, exporting the store as JSON, filling in
-/// Health data for earlier reports, and updating older addresses.
+/// Importing a Reporter export, exporting the store as JSON, improving
+/// earlier reports on the Historical Data screen, and deleting everything.
 struct DataSection: View {
     @Environment(\.reportStore) private var store
     @Environment(HealthFiller.self) private var healthFiller: HealthFiller?
@@ -45,42 +45,16 @@ struct DataSection: View {
             }
             .disabled(task != nil || store == nil)
             .settingsRow()
-            if let healthFiller {
-                Button {
-                    if healthFiller.isFillingPast {
-                        healthFiller.stopPast()
-                    } else {
-                        healthFiller.fillPast()
-                    }
-                } label: {
-                    TaskLabel(
-                        healthFiller.isFillingPast ? "Stop Backfilling Health Data" : "Backfill Health Data",
-                        isRunning: healthFiller.isFillingPast)
-                }
-                .disabled(task != nil || store == nil)
-                .settingsRow()
-                if let count = healthFiller.pastCount {
-                    SettingsNote {
-                        Text("Filled in \(count) reports so far. Keep Reportage open until it finishes.")
-                    }
-                }
-            }
-            if let addressUpdater {
-                Button {
-                    if addressUpdater.isUpdating {
-                        addressUpdater.stop()
-                    } else {
-                        addressUpdater.start()
+            NavigationLink {
+                HistoricalDataView(isBlocked: task == .importing || task == .deleting)
+            } label: {
+                LabeledContent("Historical Data") {
+                    if healthFiller?.isFillingPast == true || addressUpdater?.isUpdating == true {
+                        ProgressView()
                     }
-                } label: {
-                    TaskLabel(
-                        addressUpdater.isUpdating ? "Stop Upgrading Address Format" : "Upgrade Address Format",
-                        isRunning: addressUpdater.isUpdating)
                 }
-                .disabled(task == .importing || task == .deleting || store == nil)
-                .settingsRow()
-                AddressNote(updater: addressUpdater)
             }
+            .settingsRow()
             Button(role: .destructive) {
                 isConfirmingDelete = true
             } label: {
@@ -245,35 +219,8 @@ struct DataSection: View {
     }
 }
 
-/// How far upgrading addresses has got, or how it ended.
-private struct AddressNote: View {
-    let updater: AddressUpdater
-
-    var body: some View {
-        if let text {
-            SettingsNote { text }
-        }
-    }
-
-    private var text: Text? {
-        if let progress = updater.progress {
-            return progress.isWaiting
-                ? Text("Upgraded \(progress.updated) of \(progress.total) reports. Waiting for Apple Maps, which limits how often addresses can be looked up…")
-                : Text("Upgraded \(progress.updated) of \(progress.total) reports. Keep Reportage open until it finishes; the screen stays on meanwhile.")
-        }
-        guard let outcome = updater.outcome else { return nil }
-        if outcome.updated + outcome.unfound < outcome.total {
-            return Text("Upgraded \(outcome.updated) of \(outcome.total) reports before stopping. Upgrade again to carry on.")
-        }
-        if outcome.unfound > 0 {
-            return Text("Upgraded ^[\(outcome.updated) report](inflect: true). Apple Maps had no address for ^[\(outcome.unfound) report](inflect: true), which kept the one it had.")
-        }
-        return Text("Upgraded ^[\(outcome.updated) report](inflect: true).")
-    }
-}
-
 /// A button's title, with a spinner while its task runs.
-private struct TaskLabel: View {
+struct TaskLabel: View {
     let title: LocalizedStringKey
     let isRunning: Bool
 

diff --git a/Reportage/Views/Settings/HistoricalDataView.swift b/Reportage/Views/Settings/HistoricalDataView.swift

@@ -0,0 +1,97 @@
+import SwiftUI
+
+/// Improving reports already filed: reading Health for those from before
+/// it was asked for, and giving older addresses MapKit's form. Each says
+/// what it does, which would crowd the Data section.
+struct HistoricalDataView: View {
+    /// Whether an import or a delete is under way, which these wait for.
+    let isBlocked: Bool
+
+    @Environment(\.reportStore) private var store
+    @Environment(HealthFiller.self) private var healthFiller: HealthFiller?
+    @Environment(AddressUpdater.self) private var addressUpdater: AddressUpdater?
+
+    var body: some View {
+        List {
+            if let healthFiller {
+                Section {
+                    Button {
+                        if healthFiller.isFillingPast {
+                            healthFiller.stopPast()
+                        } else {
+                            healthFiller.fillPast()
+                        }
+                    } label: {
+                        TaskLabel(
+                            healthFiller.isFillingPast ? "Stop Importing Health Data" : "Import Health Data",
+                            isRunning: healthFiller.isFillingPast)
+                    }
+                    .disabled(isBlocked || store == nil)
+                    .settingsRow()
+                    .listRowSeparator(.hidden, edges: .top)
+                    SettingsNote {
+                        if let count = healthFiller.pastCount {
+                            Text("Imported Health data for \(count) reports so far. Keep Reportage open until it finishes.")
+                        } else {
+                            Text(
+                                "Read historical data from your iPhone's Health app for steps, distance, flights climbed and sleep. This information is used to enrich previously filed reports."
+                            )
+                        }
+                    }
+                }
+            }
+            if let addressUpdater {
+                Section {
+                    Button {
+                        if addressUpdater.isUpdating {
+                            addressUpdater.stop()
+                        } else {
+                            addressUpdater.start()
+                        }
+                    } label: {
+                        TaskLabel(
+                            addressUpdater.isUpdating ? "Stop Upgrading Address Format" : "Upgrade Address Format",
+                            isRunning: addressUpdater.isUpdating)
+                    }
+                    .disabled(isBlocked || store == nil)
+                    .settingsRow()
+                    .listRowSeparator(.hidden, edges: .top)
+                    SettingsNote { AddressNote(updater: addressUpdater) }
+                }
+            }
+        }
+        .listStyle(.plain)
+        .scrollContentBackground(.hidden)
+        .tabBarClearance()
+        .background(Theme.paper)
+        .foregroundStyle(Theme.ink)
+        .navigationTitle("Historical Data")
+        .navigationBarTitleDisplayMode(.inline)
+        .toolbar(.visible, for: .navigationBar)
+    }
+}
+
+/// What upgrading addresses does, how far it has got, or how it ended.
+private struct AddressNote: View {
+    let updater: AddressUpdater
+
+    var body: some View {
+        if let progress = updater.progress {
+            if progress.isWaiting {
+                Text("Upgraded \(progress.updated) of \(progress.total) reports. Waiting for Apple Maps, which limits how often addresses can be looked up…")
+            } else {
+                Text("Upgraded \(progress.updated) of \(progress.total) reports. Keep Reportage open until it finishes; the screen stays on meanwhile.")
+            }
+        } else if let outcome = updater.outcome {
+            if outcome.updated + outcome.unfound < outcome.total {
+                Text("Upgraded \(outcome.updated) of \(outcome.total) reports before stopping. Upgrade again to carry on.")
+            } else if outcome.unfound > 0 {
+                Text("Upgraded ^[\(outcome.updated) report](inflect: true). Apple Maps had no address for ^[\(outcome.unfound) report](inflect: true), which kept the one it had.")
+            } else {
+                Text("Upgraded ^[\(outcome.updated) report](inflect: true).")
+            }
+        } else {
+            Text("Upgrade the format of addresses for previously filed reports.")
+        }
+    }
+}

diff --git a/Tests/Unit/AddressFillTests.swift b/Tests/Unit/AddressFillTests.swift

@@ -49,14 +49,15 @@ struct AddressFillTests {
         #expect(abs(AddressSpots.distance(targets[0].coordinate, targets[1].coordinate) - 500) < 0.01)
     }
 
-    @Test("Older addresses are replaced with MapKit's, and reports already in MapKit's form are left alone")
+    @Test("Older addresses are replaced with MapKit's, and others are left alone")
     func fill() async throws {
         let store = ReportStore(persistence: makeTestPersistence())
         let imported = Self.report(latitude: 35, placemark: Placemark(name: "Old", locality: "杉並区"))
-        let missing = Self.report(latitude: 35.0001, placemark: nil)
+        let nearby = Self.report(latitude: 35.0001, placemark: Placemark(name: "Old"))
+        let missing = Self.report(latitude: 35.0002, placemark: nil)
         let current = Self.report(latitude: 36, placemark: Placemark(name: "New", language: "en"))
         let nowhere = Self.report(latitude: -10, placemark: Placemark(name: "Sea"))
-        for report in [imported, missing, current, nowhere] {
+        for report in [imported, nearby, missing, current, nowhere] {
             try await store.insert(report)
         }
 
@@ -67,16 +68,18 @@ struct AddressFillTests {
         // Two reports 11 m apart share a lookup, retried once after throttling.
         #expect(await lookup.lookups.count == 2)
 
-        let updated = try #require(try await store.report(id: missing.id))
+        let updated = try #require(try await store.report(id: imported.id))
         #expect(updated.context.location?.placemark?.cityWithContext == "City")
         #expect(updated.context.location?.localisedPlacemarks?.map(\.language) == ["ja"])
         #expect(updated.modifiedAt > imported.modifiedAt)
-        let replaced = try #require(try await store.report(id: imported.id))
-        #expect(replaced.context.location?.placemark == updated.context.location?.placemark)
+        let shared = try #require(try await store.report(id: nearby.id))
+        #expect(shared.context.location?.placemark == updated.context.location?.placemark)
+        // Without an address, there's nothing to upgrade.
+        #expect(try await store.report(id: missing.id)?.context == missing.context)
         #expect(try await store.report(id: current.id)?.context == current.context)
         #expect(try await store.report(id: nowhere.id)?.context == nowhere.context)
 
-        // Run again, only the report without an address is looked up.
+        // Run again, only the report Apple Maps had no address for is looked up.
         let again = try await fill.fill()
         #expect(again == AddressFillProgress(total: 1, updated: 0, unfound: 1))
     }