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

add a couple new things #19

Merged
merged 12 commits into from
Jan 19, 2025
Merged

add a couple new things #19

merged 12 commits into from
Jan 19, 2025

Conversation

lukaskollmer
Copy link
Member

@lukaskollmer lukaskollmer commented Jan 11, 2025

add a couple new things

♻️ Current situation & Problem

This PR adds several new types and functions to the SpeziFoundations package:

  • OrderedArray, which allows for efficient collection operations in situations where you are working with sorted (immutable) data. This is intended primarily for the SpeziHealthKit module, but since it might also be useful for other modules i decided to add it in here.
  • Generic result builders for RangeReplaceableCollection types (e.g., Array), and Set. Intended to be used by other packages, e.g. when building up Array or Set-based configurations. Will be used in SpeziHealthKit for that purpose.
  • Extensions on the Calendar type, for working with Dates; e.g., computation of date ranges, relative offsets, DST handling.
  • Ability to catch Objective-C NSException exceptions. Required for proper error handling when working with some Objective-C APIs that don't use the inout NSError** pattern and therefore aren't imported as throwing into Swift. (This is the case with some HealthKit APIs.)

⚙️ Release Notes

  • Added OrderedArray
  • Added RangeReplaceableCollectionBuilder, ArrayBuilder, and SetBuilder
  • Added Calendar extensions for Date operations
  • Added catchingNSException function

📚 Documentation

All new code is fully documented, as checked for by SwiftLint.

✅ Testing

All new code is tested.

📝 Code of Conduct & Contributing Guidelines

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

@lukaskollmer
Copy link
Member Author

lukaskollmer commented Jan 11, 2025

Some of the calendar-related tests seem to be failing on the CI, which is unexpected since all tests work fine for me locally. My guess is that this is probably time-zone related. I will have a look into that.

(this is now fixed; the tests are run for multiple time zones (LA and Berlin, currently) and check against different expected values where needed.)

Copy link

codecov bot commented Jan 12, 2025

Codecov Report

Attention: Patch coverage is 95.11719% with 25 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@502937d). Learn more about missing BASE report.
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/SpeziFoundation/Misc/ObjCExceptionHandling.swift 66.67% 10 Missing ⚠️
Sources/SpeziFoundation/Misc/Calendar.swift 96.13% 9 Missing ⚠️
Sources/SpeziFoundation/Misc/OrderedArray.swift 95.17% 6 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #19   +/-   ##
=======================================
  Coverage        ?   92.67%           
=======================================
  Files           ?       22           
  Lines           ?     1118           
  Branches        ?        0           
=======================================
  Hits            ?     1036           
  Misses          ?       82           
  Partials        ?        0           
Files with missing lines Coverage Δ
...iFoundation/Collection Builders/ArrayBuilder.swift 100.00% <100.00%> (ø)
...n Builders/RangeReplaceableCollectionBuilder.swift 100.00% <100.00%> (ø)
...eziFoundation/Collection Builders/SetBuilder.swift 100.00% <100.00%> (ø)
Sources/SpeziFoundation/Misc/AnyArray.swift 0.00% <ø> (ø)
Sources/SpeziFoundation/Misc/BinarySearch.swift 100.00% <100.00%> (ø)
...rces/SpeziFoundation/Misc/SequenceExtensions.swift 100.00% <100.00%> (ø)
Sources/SpeziFoundation/Misc/TimeoutError.swift 57.15% <ø> (ø)
Sources/SpeziFoundation/Misc/OrderedArray.swift 95.17% <95.17%> (ø)
Sources/SpeziFoundation/Misc/Calendar.swift 96.13% <96.13%> (ø)
...s/SpeziFoundation/Misc/ObjCExceptionHandling.swift 66.67% <66.67%> (ø)

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 502937d...630478e. Read the comment docs.

Copy link
Member

@PSchmiedmayer PSchmiedmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool additions, I can see them becoming useful across a lot of different apps and Spezi components!

It would be amazing if we can extend the current DocC MD file with a few sections for these new additions to properly sort and classify the elements. Apart from this PR looks great and I am happy to see it merged 👍

CONTRIBUTORS.md Show resolved Hide resolved
Package.swift Outdated Show resolved Hide resolved
Sources/SpeziFoundation/Misc/Calendar.swift Outdated Show resolved Hide resolved
Sources/SpeziFoundation/Misc/BinarySearch.swift Outdated Show resolved Hide resolved
Tests/SpeziFoundationTests/CalendarExtensionsTests.swift Outdated Show resolved Hide resolved
@PSchmiedmayer PSchmiedmayer added the enhancement New feature or request label Jan 19, 2025
@lukaskollmer lukaskollmer merged commit c844b98 into main Jan 19, 2025
10 checks passed
@lukaskollmer lukaskollmer deleted the lukas/new-stuff branch January 19, 2025 16:03
Copy link
Member

@philippzagar philippzagar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the large addition @lukaskollmer, sorry I wasn't able to review the PR earlier, looks great, thank you! 🚀

PSchmiedmayer pushed a commit to StanfordSpezi/SpeziHealthKit that referenced this pull request Jan 28, 2025
# query property wrappers, HealthChart, other refactoring

## ♻️ Current situation & Problem
The HealthKit module currently only provides access to HealthKit data
via long-running anchor queries that deliver information about
new/deleted objects to the app's Standard.
It does not provide any facilities for querying for past samples, or
accessing health data from SwiftUI. This PR attempts to address these
issues.

Furthermore, the HealthKit module is lacking an API allowing spezi users
to integrate custom HealthKit permission requests into the module's
permission handling (i.e., you currently can only request HealthKit
access for some specific sample type by actively defining a long-running
observer for that sample type).

Furthermore, this PR attempts to implement a `HealthChart` view, which
can display various types of queried HealthKit data as a chart.

resolves #8 
requires StanfordSpezi/SpeziFoundation#19
requires StanfordBDHG/XCTestExtensions#28


## ⚙️ Release Notes 
- Added `HealthKitQuery` property wrapper
- Added `HealthKitStatisticsQuery` property wrapper
- Added `HealthKitCharacteristicQuery` property wrapper
- Added `HealthChart` view
- Extended `HealthKit` configuration API to allow users to specify
sample types the system should request read and/or write access to
- Removed `CollectSamples`. The same functionality can be achieved using
a `for` loop creating individual `CollectSample` instances.


## 📚 Documentation
All added new and changed existing APIs are documented. The DocC
structure was reworked and some key aspects of SpeziHealthKit now have
dedicated article/extension pages.


## ✅ Testing
The new and changed APIs are tested using both "normal" unit tests and
UI tests. Existing tests were kept and adapted where possible


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants