Skip to content

Commit

Permalink
removed all streaking from framework
Browse files Browse the repository at this point in the history
  • Loading branch information
lmillan1 committed Jul 19, 2024
1 parent 87fe319 commit aeee7db
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import CareKitStore
import Foundation

// swiftlint:disable line_length

public extension CareTaskProgressStrategy {

/// Computes the average outcome values for a given event
Expand Down Expand Up @@ -47,19 +45,4 @@ public extension CareTaskProgressStrategy {
LinearCareTaskProgress.computeProgressByMedianOutcomeValues(for: event, kind: kind)
}
}

/// Computes the streak of outcome values for a given event
///
/// Function use ``LinearCareTaskProgress.computeProgressByStreakOutcomeValues`` method to compute the steak of outcome values given an evnet. The event is passed to the ``computeProgressByStreakOutcomeValues`` method as an argument
///
/// Parameter kind: An optional ``String`` that specifies the kind of an event. Defaults to ``nil``
///
/// Returns: A ``CareTaskProgressStrategy<LinearCareTaskProgress>`` that's the strategy for compting the progress of a care task
///
///
static func streak(kind: String? = nil) -> CareTaskProgressStrategy<LinearCareTaskProgress> {
CareTaskProgressStrategy<LinearCareTaskProgress> { event in
LinearCareTaskProgress.computeProgressByStreakOutcomeValues(for: event, kind: kind)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,30 +124,4 @@ public extension LinearCareTaskProgress {

return progress
}

static func computeProgressByStreakOutcomeValues(
for event: OCKAnyEvent,
kind: String? = nil
) -> LinearCareTaskProgress {

let outcomeValues = event.outcome?.values ?? []
let filteredOutcomeValues = outcomeValues.filter { $0.kind == kind }
let summedOutcomesValue = filteredOutcomeValues
.map(accumulableDoubleValue)
.reduce(0, +)

let targetValues = event.scheduleEvent.element.targetValues
let summedTargetValue = targetValues
.map(accumulableDoubleValue)
.reduce(nil) { partialResult, nextTarget -> Double? in
sum(partialResult, nextTarget)
}

let progress = LinearCareTaskProgress(
value: summedOutcomesValue,
goal: summedTargetValue
)

return progress
}
}
23 changes: 0 additions & 23 deletions Tests/CareKitEssentialsTests/CareTaskProgressStrategyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,4 @@ final class CareTaskProgressStrategyTests: XCTestCase {

XCTAssertEqual(progress.value, expectedValue, accuracy: 0.0001)
}

func testStreakOutcomeValues() async throws {
let ten = 10.0
let twenty = 20.0
let thirty = 30.0

let outcomeValues = [
OCKOutcomeValue(ten),
OCKOutcomeValue(twenty)
]

let event = OCKAnyEvent.mock(
taskUUID: UUID(),
occurrence: 0,
hasOutcome: true,
values: outcomeValues
)

let progress = event.computeProgress(by: .streak())
let expectedValue = thirty

XCTAssertEqual(progress.value, expectedValue, accuracy: 0.0001)
}
}
68 changes: 0 additions & 68 deletions Tests/CareKitEssentialsTests/LinearCareTaskProgressTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -388,72 +388,4 @@ final class LinearCareTaskProgressTests: XCTestCase {
XCTAssertEqual(progress.value, expectedvalue, accuracy: 0.0001)
}

func testProgressByStreakOutcomeValuesNoOutcomeNoTarget() async throws {
let event = OCKAnyEvent.mock(
taskUUID: UUID(),
occurrence: 0,
hasOutcome: false
)
let progress = LinearCareTaskProgress
.computeProgressByStreakOutcomeValues(for: event)

XCTAssertEqual(progress.value, 0.0, accuracy: 0.0001)
XCTAssertNil(progress.goal)
}

func testProgressByStreakOutcomeValuesSingleOutcomeSingleTarget() async throws {
let outcomeValues = [OCKOutcomeValue(10.0)]
let targetValues = [OCKOutcomeValue(15.0)]
let event = OCKAnyEvent.mock(
taskUUID: UUID(),
occurrence: 0,
hasOutcome: true,
values: outcomeValues,
targetValues: targetValues
)
let progress = LinearCareTaskProgress
.computeProgressByStreakOutcomeValues(for: event)
let expectedValue = outcomeValues
.map { $0.doubleValue ?? 0.0 }
.reduce(0, +) / Double(outcomeValues.count)
let expectedGoal = targetValues
.map { $0.doubleValue ?? 0.0 }
.reduce(0, +)
let goal = try XCTUnwrap(progress.goal)

XCTAssertEqual(progress.value, expectedValue, accuracy: 0.0001)
XCTAssertEqual(goal, expectedGoal, accuracy: 0.0001)
}

func testProgressByStreakOutcomeValuesMultipleOutcomesMultipleTargets() async throws {
let outcomeValues = [
OCKOutcomeValue(10.0),
OCKOutcomeValue(20.0),
OCKOutcomeValue(30.0)
]
let targetValues = [
OCKOutcomeValue(15.0),
OCKOutcomeValue(25.0),
OCKOutcomeValue(35.0)
]
let event = OCKAnyEvent.mock(
taskUUID: UUID(),
occurrence: 0,
hasOutcome: true,
values: outcomeValues,
targetValues: targetValues
)
let progress = LinearCareTaskProgress
.computeProgressByStreakOutcomeValues(for: event)
let expectedValue = outcomeValues
.compactMap { $0.doubleValue }
.reduce(0, +)
let expectedGoal = targetValues
.compactMap { $0.doubleValue }
.reduce(0, +)
let goal = try XCTUnwrap(progress.goal)

XCTAssertEqual(progress.value, expectedValue, accuracy: 0.0001)
XCTAssertEqual(goal, expectedGoal, accuracy: 0.0001)
}
}

0 comments on commit aeee7db

Please sign in to comment.