Giter Site home page Giter Site logo

Comments (9)

chiar15 avatar chiar15 commented on June 2, 2024 1

Hi, actually my solution included the kind property using the same identifiers of the steps for the outcomes too.

from carekit.

InfuriatingYetti avatar InfuriatingYetti commented on June 2, 2024

Hi @chiar15, I am still learning but wanted to try to help! :)

I am wondering, you said that "every time i close the app and reopen it the chart changes showing the wrong results"....prior to closing and reopening the app was the bar chart correct? Like do you mean if you go through the two finger tapping test and then to the bar chart, the bar chart shows the correct data and only after closing and reopening it is incorrect; or is it incorrect from the start??

Depending on your answer you could try adding a print() at various points of the process to see if the data collected and passed is accurate and what you're expecting in the first place...it would show you in the console. At the very least you could verify that the data looks right to begin with, have you tried this yet?

from carekit.

chiar15 avatar chiar15 commented on June 2, 2024

Hi @InfuriatingYetti ,
Yes i mean that after going through the test the bar chart is correct, and only after closing the app the result is wrong.
I've already tried using some print and it seems that at some point, when the event aggregator retrieves the events, the outcomes of the left and right hand are swapped and i really can't understand why.
Thanks for your help though

from carekit.

InfuriatingYetti avatar InfuriatingYetti commented on June 2, 2024

That's wild! I don't know either, I thought that if you're using charts with ResearchKit data and CareKit (like insights with bar, line, scatter charts) that the data was updated in real-time. Which it sound like it is doing correctly at first until you close and reopen it...so like you said, how is it messing it up?! lol

I have seen other posts where others have mentioned their apps act up sometimes and cleaning the build folder under Product and/or delete the app from the simulator and re-building/re-running it, restarting Xcode and/or the Mac itself can sometimes fix glitchy things...have you tried any of these things?

from carekit.

chiar15 avatar chiar15 commented on June 2, 2024

Yes, i've tried but there's clearly some problem in the code because i've written this code also on another mac and it doesn't work. I don't really know, i thought that maybe there is something i'm not doing right in the event aggregator or in the use of the store

from carekit.

InfuriatingYetti avatar InfuriatingYetti commented on June 2, 2024

I'm trying something, no promises, but does something like this help?

var countsRight = OCKOutcomeValue(Double(tappingResultRight.samples!.count)/tappingResultRight.stepViewDuration)
var countsLeft = OCKOutcomeValue(Double(tappingResultLeft.samples!.count)/tappingResultLeft.stepViewDuration)

and for left and right change:

eventAggregator: .last

from carekit.

chiar15 avatar chiar15 commented on June 2, 2024

I tried, but it gives me the following errors:
Value of type 'ORKTappingIntervalResult' has no member 'stepViewDuration';
Type 'OCKEventAggregator' has no member 'last'.

from carekit.

InfuriatingYetti avatar InfuriatingYetti commented on June 2, 2024

Make sure to back it up first (remember, still learning) before changing it around too much (see below)! I'm tagging some of the awesome pros that helped me before too lol @Pariecemckinney-apple or @gavirawson-apple or others are you able to help?

I think it has something to do with either how the tapping data is being stored in OCK core data and persisted when the app is reopening, how the code is interpreting the order in which the taps are occurring (maybe storing or reading them out of order or perhaps only using some of the tapping data), or maybe it isn't correctly calculating the taps per minute...that's all I've got, I tried using a little AI help here too (curious to see if it would work) lol - thank you for letting me try to help you! Trying to give back for all the great help I have received :)

Let us know if this happens to work!

static func extractTappingOutcome(_ result: ORKTaskResult) -> [OCKOutcomeValue]? {

    guard let tappingResultRight = result.results?
        .compactMap({ $0 as? ORKStepResult })
        .compactMap({ $0.result(forIdentifier: "tapping.right") })
        .compactMap({ $0 })
        .compactMap({ $0 as? ORKTappingIntervalResult })
        .first else {

        assertionFailure("Failed to parse a tapping interval result")
                return nil
    }
    

    guard let tappingResultLeft = result.results?
        .compactMap({ $0 as? ORKStepResult })
        .compactMap({ $0.result(forIdentifier: "tapping.left") })
        .compactMap({ $0 })
        .compactMap({ $0 as? ORKTappingIntervalResult })
        .first else {

        assertionFailure("Failed to parse a tapping interval result")
                return nil
    }

    let countsRight = tappingResultRight.samples?.count ?? 0
    let countsLeft = tappingResultLeft.samples?.count ?? 0
    let duration = tappingResultRight.duration

    let tappingRateRight = Double(countsRight) / duration
    let tappingRateLeft = Double(countsLeft) / duration

    let outcomeRight = OCKOutcomeValue(tappingRateRight)
    let outcomeLeft = OCKOutcomeValue(tappingRateLeft)

    return [outcomeRight, outcomeLeft]
}

Also:

let intervalSeriesLeft = OCKDataSeriesConfiguration(
    taskID: TaskIDs.tappingCheck,
    legendTitle: "Left Hand",
    gradientStartColor: .systemOrange,
    gradientEndColor: .systemOrange,
    markerSize: 10,
    eventAggregator: .custom({ events -> Double in
        let values = events.compactMap { $0.outcome?.values.first?.integerValue }
        let lastValue = Double(values.last ?? 0) / 10.0
        return lastValue
    })
)

With sorting the tapping events first:

let intervalSeriesRight = OCKDataSeriesConfiguration(
    taskID: TaskIDs.tappingCheck,
    legendTitle: "Right Hand",
    gradientStartColor: #colorLiteral(red: 0.2910306752, green: 0.3830310106, blue: 0.6710438132, alpha: 1),
    gradientEndColor: #colorLiteral(red: 0.3036136925, green: 0.3746574819, blue: 0.6712816954, alpha: 1),
    markerSize: 10,
    eventAggregator: .custom({ dailyEvents -> Double in
        let sortedEvents = dailyEvents.sorted { $0.scheduleEvent.occurrenceDate > $1.scheduleEvent.occurrenceDate }
        let values = sortedEvents.flatMap { $0.outcome?.values.map { $0.integerValue ?? 0 } ?? [] }
        let currentValue = Double(values.first ?? 0 )/10.0
        return currentValue
    })
)

let intervalSeriesLeft = OCKDataSeriesConfiguration(
    taskID: TaskIDs.tappingCheck,
    legendTitle: "Left Hand",
    gradientStartColor: .systemOrange,
    gradientEndColor: .systemOrange,
    markerSize: 10,
    eventAggregator: .custom({ dailyEvents -> Double in
        let sortedEvents = dailyEvents.sorted { $0.scheduleEvent.occurrenceDate > $1.scheduleEvent.occurrenceDate }
        let values = sortedEvents.flatMap { $0.outcome?.values.map { $0.integerValue ?? 0 } ?? [] }
        let currentValue = Double(values.first ?? 0)/10.0
        return currentValue
    })
)

let barChart = OCKCartesianChartViewController(
    plotType: .bar,
    selectedDate: Date(),
    configurations: [intervalSeriesRight, intervalSeriesLeft],
    storeManager: storeManager
)

barChart.chartView.headerView.titleLabel.text = "Number Of Taps Between Per Second"
appendViewController(barChart, animated: false)

from carekit.

gavirawson-apple avatar gavirawson-apple commented on June 2, 2024

Hey folks, looks like there's been a lot of good discussion on the topic. Thanks for helping out here @InfuriatingYetti.

What was your solution @chiar15? Ideally the framework should maintain the sort order of the outcome values, but I'll have to check if that's guaranteed. Alternatively, you can use the kind or units property on the outcome value to tag each value with the orientation (left vs right sides). You can later read that tag to extract the desired outcome in the aggregator block.

from carekit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.