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

Create monthly charts #685

Open
egiafra opened this issue Mar 28, 2023 · 3 comments
Open

Create monthly charts #685

egiafra opened this issue Mar 28, 2023 · 3 comments

Comments

@egiafra
Copy link

egiafra commented Mar 28, 2023

Hi,
I want to create a charts that shows the results of a researchkit task for a whole month instead of a single week. I've already managed to modify the view of the charts, but I'm having some problems in figuring out how to fetch the results of the events of the whole month. I hope someone can help me.

@gavirawson-apple
Copy link
Collaborator

Hello! Which version of CareKit are you using, and are you building out your view in SwiftUI or UIKit? If you're interested in trying out the 3.0 beta release, we've introduced some new SwiftUI APIs that will make it really easy to map event data to a chart -

struct MonthlyChartView: View {

    private static var query: OCKEventQuery {
        let monthInterval = Calendar.current.dateInterval(of: .month, for: Date())!
        let query = OCKEventQuery(dateInterval: monthInterval)
    }

    @CareStoreFetchRequest(query: Self.query)
    private var events

    var body: some View {
        buildChartView(using: events)
    }
}

Alongside that, you can also make use of the CareTaskProgress API to aggregate the progress for multiple events and display the resulting value in the chart.

@drdavec
Copy link
Contributor

drdavec commented Apr 25, 2023 via email

@gavirawson-apple
Copy link
Collaborator

Hey Dave apologies for the late response here.

You can also stream outcomes over a date range. The CareStoreFetchRequest can be initialized with each type of care store query:

@CareStoreFetchRequest(query: OCKOutcomeQuery(dateInterval: someInterval))
private var outcomes

The decision between querying for outcomes or events will depend on what you plan to do with the data. Querying for just outcomes is probably a little bit faster, but is missing some perhaps useful information (task, event start, event end, etc.). You also won't have access to the progress computation methods available on an event. Though, it might be useful for us to provide that progress method on the outcome level as well one day.

Does that help clear up the differences?

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