Skip to content

Commit

Permalink
Upload Indicator (#59)
Browse files Browse the repository at this point in the history
# Upload Indicator

## ♻️ Current situation & Problem
Some of the ECG uploads are a little flaky. Even when the app shows that
new samples have been read, not all of them are making it to Firebase as
one would expect. The first step in solving this problem is identifying
which samples are not making it to Firebase.


## ⚙️ Release Notes 
- Added a checkmark icon to indicate which recordings have been
successfully uploaded. Those that have not been successfully uploaded
will have a spinning animation.


## ✅ Testing
Upload status comes from the `isUploaded` function in `ECGModule`.


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).

---------

Co-authored-by: Paul Schmiedmayer <[email protected]>
  • Loading branch information
MatthewTurk247 and PSchmiedmayer authored Apr 30, 2024
1 parent f21cfc9 commit 1afb3fb
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
13 changes: 11 additions & 2 deletions PAWS/ECGRecordings/ECGModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ECGModule: Module, DefaultInitializable, EnvironmentAccessible {


@ObservationIgnored @Dependency var localStorage: LocalStorage
@ObservationIgnored @StandardActor var standard: PAWSStandard

private(set) var electrocardiograms: [HKElectrocardiogram] = []
private var uploadedElectrocardiograms: Set<HKElectrocardiogram.ID> = []
Expand All @@ -33,8 +34,16 @@ class ECGModule: Module, DefaultInitializable, EnvironmentAccessible {
}


func isUploaded(_ electrocardiogram: HKElectrocardiogram) -> Bool {
uploadedElectrocardiograms.contains(where: { $0 == electrocardiogram.uuid })
func isUploaded(_ electrocardiogram: HKElectrocardiogram, reuploadIfNeeded: Bool = false) -> Bool {
let uploaded = uploadedElectrocardiograms.contains(where: { $0 == electrocardiogram.uuid })

if reuploadIfNeeded {
Task {
await standard.add(sample: electrocardiogram)
}
}

return uploaded
}

func markAsUploaded(_ electrocardiogram: HKElectrocardiogram) {
Expand Down
24 changes: 19 additions & 5 deletions PAWS/ECGRecordings/ECGRecording.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,30 @@ import SwiftUI
struct ECGRecording: View {
let electrocardiogram: HKElectrocardiogram
@State var symptoms: HKElectrocardiogram.Symptoms = [:]
@Environment(ECGModule.self) var ecgModule


var body: some View {
PAWSCard {
VStack(alignment: .leading) {
Text("ECG Recording")
.font(.title)
Text(electrocardiogram.endDate.formatted())
.font(.subheadline)
.foregroundStyle(.secondary)
VStack(alignment: .leading, spacing: 0) {
Text("ECG Recording")
.font(.title)
HStack {
Text(electrocardiogram.endDate.formatted())
.font(.subheadline)
.foregroundStyle(.secondary)
if ecgModule.isUploaded(electrocardiogram, reuploadIfNeeded: true) {
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(.green)
.accessibilityLabel("Checkmark: ECG has been successfully uploaded")
} else {
ProgressView()
.controlSize(.small)
.padding(.horizontal, 1)
}
}
}
Divider()
if symptoms.isEmpty {
Text("Recorded no symptoms")
Expand Down
8 changes: 2 additions & 6 deletions PAWS/PAWSStandard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,9 @@ actor PAWSStandard: Standard, EnvironmentAccessible, HealthKitConstraint, Onboar
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
let jsonRepresentation = (try? String(data: encoder.encode(resource), encoding: .utf8)) ?? ""
try? await mockWebService.upload(path: "healthkit/\(sample.uuid.uuidString)", body: jsonRepresentation)
try await mockWebService.upload(path: "healthkit/\(sample.uuid.uuidString)", body: jsonRepresentation)
} else {
do {
try await healthKitDocument(id: sample.id).setData(from: resource)
} catch {
logger.error("Could not store HealthKit sample: \(error)")
}
try await healthKitDocument(id: sample.id).setData(from: resource)
}

if let electrocardiogram = sample as? HKElectrocardiogram {
Expand Down
3 changes: 3 additions & 0 deletions PAWS/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@
}
}
}
},
"Checkmark: ECG has been successfully uploaded" : {

},
"CLOSE" : {
"localizations" : {
Expand Down

0 comments on commit 1afb3fb

Please sign in to comment.