StanfordSpezi / SpeziScheduler

Scheduler Module for the Stanford Spezi Ecosystem
https://swiftpackageindex.com/StanfordSpezi/SpeziScheduler/documentation/
MIT License
4 stars 3 forks source link

New Task model using SwiftData and Schedule creation using Calendar Recurrence Rule #44

Closed Supereg closed 1 month ago

Supereg commented 3 months ago

New Task model using SwiftData and Schedule creation using Calendar Recurrence Rule

:recycle: Current situation & Problem

This PR completely rethinks the Scheduler package. We introduce an updated Task model that is completely backed by SwiftData. Further, we provide a new Schedule model that provides greater flexibility for formulating recurring events. Instead of formulating events based on intervals using DateComponents, we use the new RecurrenceRule infrastructure introduced with iOS 18.

Using a Schedule, you can generate a potentially infinite list of Occurrences. A Task uses the occurrences of its Schedule to generate Events. When events are marked as completed, they are associated with an Outcome. Both a Task and an Outcome can be extended with arbitrary data. This is enabled using the @Property macro, that allows to define custom properties on tasks and outcomes using a SharedRepository-backed storage implementation.

Task are stored in an versioned, append-only store. Modifying the contents of a Task (e.g., instructions, schedules, ...), appends a new Task version and marks it as effective for the specified date. This allows to modify tasks without changing previous events or occurrences. Something that was impossible with the previous implementation.

Lastly, the updated Scheduler provides additional support for UI components out of the box. We provide the new @EventQuery property wrapper that you can use in your SwiftUI views. It allows to easily and efficiently query Events directly in SwiftUI. Additionally, we provide several, reusable UI components out of the box to visualize events in your application.

Notifications are currently no longer supported with this version of SpeziScheduler: https://github.com/StanfordSpezi/SpeziScheduler/issues/45 (This is now tackled in https://github.com/StanfordSpezi/SpeziScheduler/pull/49 which will most likely be merged alongside this PR).

An example of how to configure tasks with this new model is depicted below:

import Spezi
import SpeziScheduler

class MySchedulerModule: Module {
    @Dependency(Scheduler.self)
    private var scheduler

    init() {}

    func configure() {
        do {
            try scheduler.createOrUpdateTask(
                id: "my-daily-task",
                title: "Daily Questionnaire",
                instructions: "Please fill out the Questionnaire every day.",
                category: Task.Category("Questionnaire", systemName: "list.clipboard.fill"),
                schedule: .daily(hour: 9, minute: 0, startingAt: .today)
            )
        } catch {
            // handle error (e.g., visualize in your UI)
        }
    }
}

:gear: Release Notes

Breaking Changes

:books: Documentation

The documentation catalog was completely restructured, highlighting all the new API and functionality.

:white_check_mark: Testing

New unit and UI tests have been written to verify functionality. We aimed to set a focus on unit tests for fastest possible test execution.

:pencil: Code of Conduct & Contributing Guidelines

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

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 62.63191% with 602 lines in your changes missing coverage. Please review.

Project coverage is 63.11%. Comparing base (896eb44) to head (19139c5). Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...s/SpeziSchedulerMacros/UserStorageEntryMacro.swift 0.00% 122 Missing :warning:
Sources/SpeziSchedulerUI/EventScheduleList.swift 0.00% 113 Missing :warning:
Sources/SpeziScheduler/Task/Task.swift 68.33% 51 Missing :warning:
Sources/SpeziScheduler/Schedule/Schedule.swift 71.01% 49 Missing :warning:
Sources/SpeziScheduler/Scheduler.swift 86.22% 39 Missing :warning:
...es/SpeziScheduler/Schedule/Schedule+Duration.swift 52.31% 31 Missing :warning:
Sources/SpeziScheduler/Task/Outcome.swift 20.52% 31 Missing :warning:
.../SpeziScheduler/Task/AllowedCompletionPolicy.swift 46.67% 24 Missing :warning:
Sources/SpeziSchedulerUI/InstructionsTile.swift 80.84% 23 Missing :warning:
...rces/SpeziScheduler/UserInfo/UserInfoStorage.swift 64.41% 21 Missing :warning:
... and 11 more
Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44/graphs/tree.svg?width=650&height=150&src=pr&token=0VQNE0E1Wp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi)](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) ```diff @@ Coverage Diff @@ ## main #44 +/- ## ========================================= + Coverage 0 63.11% +63.11% ========================================= Files 0 24 +24 Lines 0 1648 +1648 ========================================= + Hits 0 1040 +1040 - Misses 0 608 +608 ``` | [Files with missing lines](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | Coverage Δ | | |---|---|---| | [...iScheduler/Task/Task+LocalizedStringResource.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziScheduler%2FTask%2FTask%2BLocalizedStringResource.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlci9UYXNrL1Rhc2srTG9jYWxpemVkU3RyaW5nUmVzb3VyY2Uuc3dpZnQ=) | `100.00% <100.00%> (ø)` | | | [...SchedulerUI/Category/TaskCategoryAppearances.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziSchedulerUI%2FCategory%2FTaskCategoryAppearances.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlclVJL0NhdGVnb3J5L1Rhc2tDYXRlZ29yeUFwcGVhcmFuY2VzLnN3aWZ0) | `100.00% <100.00%> (ø)` | | | [...rUI/Category/TaskCategoryAppearancesModifier.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziSchedulerUI%2FCategory%2FTaskCategoryAppearancesModifier.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlclVJL0NhdGVnb3J5L1Rhc2tDYXRlZ29yeUFwcGVhcmFuY2VzTW9kaWZpZXIuc3dpZnQ=) | `100.00% <100.00%> (ø)` | | | [...es/SpeziSchedulerMacros/SpeziSchedulerMacros.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziSchedulerMacros%2FSpeziSchedulerMacros.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlck1hY3Jvcy9TcGV6aVNjaGVkdWxlck1hY3Jvcy5zd2lmdA==) | `0.00% <0.00%> (ø)` | | | [...rces/SpeziScheduler/Schedule/Date+Extensions.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziScheduler%2FSchedule%2FDate%2BExtensions.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlci9TY2hlZHVsZS9EYXRlK0V4dGVuc2lvbnMuc3dpZnQ=) | `86.67% <86.67%> (ø)` | | | [Sources/SpeziScheduler/EventQuery.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziScheduler%2FEventQuery.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlci9FdmVudFF1ZXJ5LnN3aWZ0) | `96.43% <96.43%> (ø)` | | | [Sources/SpeziScheduler/UserInfo/UserInfoKey.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziScheduler%2FUserInfo%2FUserInfoKey.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlci9Vc2VySW5mby9Vc2VySW5mb0tleS5zd2lmdA==) | `0.00% <0.00%> (ø)` | | | [Sources/SpeziScheduler/Schedule/Occurence.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziScheduler%2FSchedule%2FOccurence.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlci9TY2hlZHVsZS9PY2N1cmVuY2Uuc3dpZnQ=) | `61.91% <61.91%> (ø)` | | | [Sources/SpeziSchedulerUI/DefaultTileHeader.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziSchedulerUI%2FDefaultTileHeader.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlclVJL0RlZmF1bHRUaWxlSGVhZGVyLnN3aWZ0) | `89.34% <89.34%> (ø)` | | | [Sources/SpeziScheduler/Task/Task+Category.swift](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree&filepath=Sources%2FSpeziScheduler%2FTask%2FTask%2BCategory.swift&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi#diff-U291cmNlcy9TcGV6aVNjaGVkdWxlci9UYXNrL1Rhc2srQ2F0ZWdvcnkuc3dpZnQ=) | `33.34% <33.34%> (ø)` | | | ... and [14 more](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) | | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Last update [896eb44...19139c5](https://app.codecov.io/gh/StanfordSpezi/SpeziScheduler/pull/44?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=StanfordSpezi).