Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Features/readtimestamps: Read timestamps from FireStore; Pause Upload…
…ing to FireStore and Hide/Unhide Timestamps (#39) # Read timestamps from FireStore; Pause Uploading to FireStore and Hide/Unhide Timestamps ## ♻️ Current situation & Problem Relevant issues:[ UI trigger for changing a flag field to true for data that the user wants redacted ](#28) Currently, the DeleteDataView that allows users to review and “hide” their data uses a hard-coded array of timestamps, so it does not access nor read in timestamps for the specified data type from Firestore. Second, users cannot “unhide” their data after choosing to hide it. Third, DeleteDataView currently does not support hiding data via a custom date range. To address the first issue, we created a function to fetch the10 most recent timestamps from Firestore. In DeleteDataView, we display this list under the “Hide by Timestamp” section. Second, we changed all functionality from “deleting” data to “hiding” data to better represent what is actually happening to user data on the backend. We modified addDeleteFlag to switchHideFlag so that users can “unhide” their data and have this status change reflected in Firestore’s hideFlag field. We also modified the UI so that an open/crossed-out eye is shown signaling which timestamps are hidden/unhidden. Third, we created the “Hide by Custom Range” section in DeleteDataView so users can select a date range to delete data via the date pickers. We created the function fetchCustomRangeTimeStamps() to get a list of all timestamps in the specified date range. Since we want all data in this range to be hidden regardless of the previous hideFlag values, we modified switcHed Flag to take in a third parameter (read below). Lastly, we made modifications to communicate the enable/disable status of sample category uploads between the DeleteDataView, ManageDataView, and PrivacyModule. Saving the toggle value allowed users to pause or unpause uploads of that data type to firestor (see PrismaStandard+HealthKit). ## ⚙️ Release Notes ### PrismaStandard+Healthkit: - Before uploading a HealthKit datapoint to Firestore, check the toggle status in the identifierInfo dictionary in PrivacyModule . If the toggle is disabled, the HealthKit datapoint should not be uploaded to Firestore. - switchHideFlag(): Modified switchHideFlag logic so users can hide/unhide data to update hideFlag in Firestore accordingly. Also modified to take in an extra parameter “alwaysHide” bool. If the user hides by custom range, “alwaysHide” is set to true, meaning the hideFlags are always set to true regardless of original value. Otherwise, the hideFlag is toggled (false set to true and true set to false). - fetchTop10RecentTimeStamps(): Create function which fetches the top 10 most recent timestamps for a given data type (e.g, step count) and returns the populated array. - fetchCustomRangeTimeStamps(): Create function which fetches all timestamps in given date range by start date and end date pickers in “hide by custom range” and returns the populated array. ### PrivacyModule: - identifierInfo dictionary: maps the identifier string (e.g. “stepcount”, “heartrate”) to information needed for the UI and the hideFlag functionality (e.g. enabledBool status). - sortedSampleIdentifiers list: using the sampleTypes list in PrismaDelegate, send a list of the string identifiers for each type with prefixes trimmed – ensures that only the sample types allowed by the Prisma app will be displayed to the user in ManageDataView. Refactoring this allowed us to create a publisher that signaled views to refresh upon changes to the identifierInfo dictionary. - identifierInfoSubject Combine publisher that sent signals to views subscribed – views will refresh upon changes to the sample type toggles (e.g. disabling the upload of step count data points) - updateAndSignalOnChange() function that updates the identifierInfo dictionary with the new toggle boolean and sends out a signal to subscribing views. ### ManageDataView: - Updated to use identifierInfo dictionary and sampleTypes list - Subscribed to the identifierInfoSubject Combine publisher; upon receiving a signal from the publisher, the view refreshes its “Disabled”/”Enabled” status ### DeleteDataView: - In “Hide by Custom Range” section, created date pickers for start and end dates so users can select a date range to hide all data in between dates. Pass the start and end date into fetchCustomRangeTimeStamps() to fetch all timestamps in this range, then call switchHideFlag() with alwaysHide = true to set hideFlags to true. - In “Hide by Timestamps” section, display the timestamp array populated by fetchTop10RecentTimeStamps(). Upon tapping the eye icon, hidden status switches as reflected in the change in icon and graying/un-graying out. Then, call switchHiddenInBackend to hide timestamp in Firestore. - Updated to use identifierInfo dictionary - When a new value is set for the toggle, it calls updateAndSignalOnChange() to update the dictionary and send out signals to subscribing views. ### Next Steps: Write unit tests for implemented features. ## 📚 Documentation N/A ## ✅ Testing - In featureFlags.swift, switch set useFirebaseEmulator to false. - Replace the appropriate GoogleService-Info.plist - Erase all content and settings from the simulator device. - Run the app and login using personal account and password (corresponding to account on FireStore) ## Roles *Evelyn:* - Create switchHideFlag() function in PrismaStandard+Healthkit to switch hideFlag from false to true and vice versa in Firestore to reflect hide/unhide timestamp changes by user in DeleteDataView. - Create fetchTop10RecentTimeStamps() function which fetches the top 10 most recent timestamps for a given data type (e.g, step count), stores the timestamps into an array, and returns the array (which will be called in DeleteDataView). - Create fetchCustomRangeTimeStamps() function which fetches all timestamps in given date range by date picker in “Hide by custom range” - Modify switchHideFlag() function to take in an additional parameter alwaysHide bool. alwaysHide is set to true if the user hides by custom range, otherwise it’s set to false. - Create UI for hide by custom range using date pickers (calendar view) in DeleteDataView to allow users to hide data in a specified date range - Create UI for displaying 10 recent timestamps for the data category item, showing each timestamp’s Firestore hideFlag status via an open/crossed-out eye. - Create switchHiddenInBackend() function inside DeleteDataView that calls switchHideFlag in PrismaStandard+HealthKit to switch hideFlag status *Caroline:* - Refactored data communication between the PrivacyModule, ManageDataView, and DeleteDataView to reference and use only the HKSampleTypes from the PrismaDelegate by creating sortedSampleIdentifiers list. SortedSampleIdentifiers list alphabetized the sample types to display for the user. This list kept all UI information within the dictionary in PrivacyModule and passed on as few parameters as possible. The refactoring of this was necessary to ensure that the app’s HKSampleTypes were the only ones shown to the user (allowed the app to be flexible and modular to future app-wide modifications). The new structure also allowed for the publisher addition mentioned in the next point. - Created the Combine publisher in the PrivacyModule to signal all subscribing views to refresh their pages with new identifierInfo dictionary values. - Debugging: An issue we ran into during this PR was how different devices and different types of samples had different effectiveDateTime/effectivePeriod fields. With Matt’s help, the timestamps were intended to be sorted by “time.datetime.start” but in swift, the “datetime.start” field was not recognizable so we resorted to using the “issued” time. *Dhruv:* - writeToFirestore(): took Evelyn and Caroline’s code for writing to firestore and put it into its own function for sake of modularity - add(): included functionality in the PrismaStandard to not write to Firestore if the HKSample has an off toggle - PrivacyModule(): refactored a majority of the PrivacyModule class to include initialization with a list of HKSampleTypes, and used this to map each corresponding identifier to a bool for representation in ManageDataView and DeleteDataView ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md): - I agree to follow the [Code of Conduct](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md). <img src="https://github.com/CS342/2024-Prisma/assets/89322465/13335700-9070-4de1-8a33-0afc9960a4c7" width="100" height="225"> <img src="https://github.com/CS342/2024-Prisma/assets/89322465/de60dd50-25c8-4188-9b75-f12064fbac50" width="100" height="225"> <img src="https://github.com/CS342/2024-Prisma/assets/89322465/2d18cc38-98d0-4919-a067-e04e7f69df5c" width="100" height="225"> --------- Co-authored-by: Evelyn <[email protected]> Co-authored-by: dhruvna1k <[email protected]>
- Loading branch information