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

percentage of completed tasks #666

Open
ykworld opened this issue Aug 12, 2022 · 3 comments
Open

percentage of completed tasks #666

ykworld opened this issue Aug 12, 2022 · 3 comments

Comments

@ykworld
Copy link

ykworld commented Aug 12, 2022

Screen Shot 2022-08-12 at 12 11 15 AM

I want to get the percentage of completed tasks. How can I implement it?

@ykworld ykworld changed the title How can I get a count of task complection per day? percentage of completed tasks Aug 12, 2022
@shirblc
Copy link

shirblc commented Aug 19, 2022

You can do it using OCKAdherenceQuery. If successful, adherence queries return one of three values: noTasks, if there are no tasks; noEvents, if there are no task events (actual occurrences) scheduled for the given interval; or progress with an associated value between 0 and 1, if there are events. If you multiply that value by a 100, you can get the completion percentage.

For example:

let store = OCKStore("MyStore")

func fetchAdherence(for date: Date) {
    let startOfDay = Calendar.current.startOfDay(for: date)
    let endOfDay = Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: date)!
    var query = OCKAdherenceQuery(
        taskIDs: [],       // If you want adherence for all tasks. You can add task IDs if you want to check adherence for specific tasks
        dateInterval: DateInterval(start: startOfDay, end: endOfDay)
    )
    query.aggregator = OCKAdherenceAggregator.compareTargetValues

    store.fetchAdherence(query: query) { result in
        switch result {
            case .success(let adherence):
                switch adherence[0] {
                case .noTasks:
                    // handle no tasks
                case .noEvents:
                    // handle no events
                case .progress(let double):
                    let percentage = double * 100
                    // handle that
                }
            case .failure(let error):
                // handle the error
            }
        }
    }

Hope this helps!

@ykworld
Copy link
Author

ykworld commented Aug 19, 2022

You can do it using OCKAdherenceQuery. If successful, adherence queries return one of three values: noTasks, if there are no tasks; noEvents, if there are no task events (actual occurrences) scheduled for the given interval; or progress with an associated value between 0 and 1, if there are events. If you multiply that value by a 100, you can get the completion percentage.

For example:

let store = OCKStore("MyStore")

func fetchAdherence(for date: Date) {
    let startOfDay = Calendar.current.startOfDay(for: date)
    let endOfDay = Calendar.current.date(bySettingHour: 23, minute: 59, second: 59, of: date)!
    var query = OCKAdherenceQuery(
        taskIDs: [],       // If you want adherence for all tasks. You can add task IDs if you want to check adherence for specific tasks
        dateInterval: DateInterval(start: startOfDay, end: endOfDay)
    )
    query.aggregator = OCKAdherenceAggregator.compareTargetValues

    store.fetchAdherence(query: query) { result in
        switch result {
            case .success(let adherence):
                switch adherence[0] {
                case .noTasks:
                    // handle no tasks
                case .noEvents:
                    // handle no events
                case .progress(let double):
                    let percentage = double * 100
                    // handle that
                }
            case .failure(let error):
                // handle the error
            }
        }
    }

Hope this helps!

Thanks a lot!

@majidsaleem105
Copy link

Hello @ykworld,

I also want to add the OverView section to my app. Can you please guide me on how you append that section to the view?
How did you change the Completion Ring Shape?

Thanks,

  • Majid S.

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

No branches or pull requests

3 participants