Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Time Index To HealthKit Sample Uploads #34

Merged

Conversation

mjoerke
Copy link
Collaborator

@mjoerke mjoerke commented Feb 28, 2024

Adding Time Index To HealthKit Sample Uploads

♻️ Current situation & Problem

As we are transitioning the backend to an architecture that doesn't depend on cloud functions and periodic featurization, we are working on efficient data fetching queries in Firebase. Many HealthKit data types are associated with a time range, not a timestamp. This complicates Firebase queries since queries like

collection.where(filter=("timeRange.start", "<=", queryEnd)
          .where(filter=FieldFilter("timeRange.end", ">=", queryStart))

are not permitted due to inequality filters on multiple properties.

Instead, I am proposing adding the following fields to each HealthKit upload:

time.range: bool // whether the sample is a time range or time stamp type
                 // if time.range = false, not .end properties are set
time.year.start, time.year.end: int
time.month.start, time.month.end: int
time.day.start, time.day.end: int
time.hour.start, time.hour.end: int
time.minute.start, time.minute.end: int
time.second.start, time.second.end: int
time.dayMin.start, time.dayMin.end: int // how many total minutes have elapsed, between [0, 1439]
time.15minBucket.start, time.15minBucket.end // which 15 min bucket the sample falls into, between [0,95]

in addition, we will also have ranges for each time index component, such as

time.15minBucket.range = [45, 46, 47] // sample falls between 11:15-12:00

which will allow us to make efficient Firebase array membership queries

⚙️ Release Notes

  • Added a function constructTimeIndex in a new PrismaStandard+TimeIndex.swift that computes the necessary time fields

📚 Documentation

N/A

✅ Testing

N/A

📝 Code of Conduct & Contributing Guidelines

By submitting creating this pull request, you agree to follow our Code of Conduct and Contributing Guidelines:

Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 0% with 108 lines in your changes are missing coverage. Please review.

Project coverage is 34.39%. Comparing base (b549eed) to head (135c568).

Additional details and impacted files

Impacted file tree graph

@@                        Coverage Diff                         @@
##           feature/add-sleep-and-workouts      #34      +/-   ##
==================================================================
- Coverage                           35.97%   34.39%   -1.58%     
==================================================================
  Files                                  40       41       +1     
  Lines                                1418     1521     +103     
==================================================================
+ Hits                                  510      523      +13     
- Misses                                908      998      +90     
Files Coverage Δ
Prisma/Standard/PrismaStandard+HealthKit.swift 0.00% <0.00%> (ø)
Prisma/Standard/PrismaStandard+TimeIndex.swift 0.00% <0.00%> (ø)

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b549eed...135c568. Read the comment docs.

@mjoerke mjoerke merged commit 01bd84d into feature/add-sleep-and-workouts Mar 9, 2024
7 checks passed
@mjoerke mjoerke deleted the feature/healthkit-timestamps branch March 9, 2024 20:06
mjoerke added a commit that referenced this pull request Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant