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

Merge TimeIndex + Sleep/Workouts #37

Merged
merged 5 commits into from
Mar 9, 2024
Merged

Conversation

mjoerke
Copy link
Collaborator

@mjoerke mjoerke commented Mar 9, 2024

No description provided.

# *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](https://firebase.google.com/docs/firestore/query-data/queries#array_membership)

## ⚙️ 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](https://github.com/CS342/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/CS342/.github/blob/main/CONTRIBUTING.md):
- [x] 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).
Copy link

codecov bot commented Mar 9, 2024

Codecov Report

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

Project coverage is 35.85%. Comparing base (f41a4ce) to head (b48a744).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
- Coverage   36.19%   35.85%   -0.34%     
==========================================
  Files          43       44       +1     
  Lines        1622     1699      +77     
==========================================
+ Hits          587      609      +22     
- Misses       1035     1090      +55     
Files Coverage Δ
Prisma/Standard/PrismaStandard+HealthKit.swift 8.43% <0.00%> (+1.76%) ⬆️
Prisma/Standard/PrismaStandard+TimeIndex.swift 0.00% <0.00%> (ø)

... and 2 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 f41a4ce...b48a744. Read the comment docs.

@mjoerke mjoerke merged commit 7747b85 into main Mar 9, 2024
7 checks passed
@mjoerke mjoerke deleted the feature/add-sleep-and-workouts branch March 9, 2024 20:40
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