file upload rework; HealthKit stats (WIP) - #197
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PSchmiedmayer
left a comment
There was a problem hiding this comment.
Happy to see merged once the things we discussed are incorporated + more tests. Good to drive the statistics based on the Firebase setup in the short term + ensure that we have the structure alignment document in place 🚀
| ) | ||
| managedFileUpload.scheduleForUpload(results.compactMap { $0 }, category: .historicalHealthUpload) | ||
| let exportedFileUrls = results.compactMap { $0 } | ||
| Task { [managedFileUpload, logger] in |
There was a problem hiding this comment.
Should we keep track of the task and/or have some checks to not run them in parallel?
| for descriptor in descriptors { | ||
| taskGroup.addTask { | ||
| do { | ||
| try await self._run(descriptor, lastNMonths: 1, accountDoc: accountDoc) |
There was a problem hiding this comment.
Should probably from enrollment on.
There was a problem hiding this comment.
the current local-HealthKit-query-based implementation of the dashboard doesn't take the enrollment date into acount and instead simply fetches e.g. the last 2 weeks, without capping this based on the enrollment date.
IMO we should still compute a full year of stats; the app can then decide how much (and which sub-range) of that it wants to query...
| extension HealthKitStatsCalculator { | ||
| fileprivate struct MonthlyStatsDocument: Codable { | ||
| // A single sum or min/max/avg entry in the single-month stats document | ||
| struct StatEntry: Codable { |
There was a problem hiding this comment.
TODO to sync with the main outline of how we want to define this & discuss with @pauljohanneskraft @eldcn @PaulGoldschmidt 👍
| // fileprivate static let statsIntervalHourly = Self(stringValue: "hourly") | ||
| // fileprivate static let statsIntervalDaily = Self(stringValue: "daily") |
| // (Moved aside, not deleted, so that the previously-pending uploads at least remain recoverable.) | ||
| for filename in ["db.sqlite", "db.sqlite-shm", "db.sqlite-wal"] { | ||
| let url = Self.databaseDirectory.appending(component: filename, directoryHint: .notDirectory) | ||
| let brokenUrl = Self.databaseDirectory.appending(component: "broken-\(filename)", directoryHint: .notDirectory) |
There was a problem hiding this comment.
Probably would override? So might be good to append a date or something there?
| let validNames = Set(uploads.map { $0.id.uuidString }) | ||
| for url in (try? fileManager.contents(of: Self.stagingDirectory)) ?? [] where !validNames.contains(url.lastPathComponent) { | ||
| logger.notice("Deleting orphaned staging file at \(url.path)") | ||
| try? fileManager.removeItem(at: url) |
There was a problem hiding this comment.
We should probably somehow keep track how often that happens and be very sure that that's only when there was un very unfortunate things that it crashed between db removal and file removal.
| let container = try decoder.container(keyedBy: CodingKey.self) | ||
| version = try container.decode(Int.self, forKey: .version) | ||
| metric = try container.decode(String.self, forKey: .metric) | ||
| let hmmm: [StatsTimeInterval: [String: [StatEntry]]] = try StatsTimeInterval.allCases.reduce(into: [:]) { result, timeInterval in |
| let now = Date() | ||
| let startDate = cal.date(byAdding: .month, value: -numMonths, to: cal.startOfMonth(for: now))! | ||
| let months: some Sequence<Range<Date>> = cal | ||
| .dates(byAdding: .month, value: 1, startingAt: startDate, in: startDate..<cal.startOfNextMonth(for: now)) |
There was a problem hiding this comment.
we'll have to ensure that this sequence will properly contain the first occurrence (i.e., the startDate)
♻️ Current situation & Problem
see #180, #190, #191
⚙️ Release Notes
QuantitySample.valueproperty private (to force callers to explicitly specify a unit each time)📚 Documentation
n/a
✅ Testing
not yet
Code of Conduct & Contributing Guidelines
By creating and submitting this pull request, you agree to follow our Code of Conduct and Contributing Guidelines: