Skip to content

Commit

Permalink
aggregate Progress across data sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mjoerke committed Apr 10, 2024
1 parent 805f0ed commit dd43234
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class BulkUploadSampleDataSource: HealthKitDataSource {
}
}

var progress: Progress {
public var progress: Progress {

Check failure on line 42 in Sources/SpeziHealthKit/BulkUpload/BulkUploadSampleDataSource.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint / SwiftLint

Lower ACL than Parent Violation: Ensure declarations have a lower access control level than their enclosing parent (lower_acl_than_parent)
let progress = Progress(totalUnitCount: Int64(totalSamples))
progress.completedUnitCount = Int64(processedSamples)
return progress
Expand Down
15 changes: 15 additions & 0 deletions Sources/SpeziHealthKit/HealthKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ public final class HealthKit: Module, EnvironmentAccessible, DefaultInitializabl
private var healthKitDataSourceDescriptions: [HealthKitDataSourceDescription] = []
@ObservationIgnored private var healthKitComponents: [any HealthKitDataSource] = []

public var progress: Progress {
var totalUnitCount: Int64 = 0
var completedUnitCount: Int64 = 0
for dataSource in healthKitComponents {
if let bulkDataSource = dataSource as? BulkUploadSampleDataSource {
let individualProgress = bulkDataSource.progress
totalUnitCount += individualProgress.totalUnitCount
completedUnitCount += individualProgress.completedUnitCount
}
}
let macroProgress = Progress(totalUnitCount: totalUnitCount)
macroProgress.completedUnitCount = completedUnitCount
return macroProgress
}


private var healthKitSampleTypes: Set<HKSampleType> {
(initialHealthKitDataSourceDescriptions + healthKitDataSourceDescriptions).reduce(into: Set()) {
Expand Down

0 comments on commit dd43234

Please sign in to comment.