Skip to content

LOOP-4665 Functional Algorithm#542

Merged
ps2 merged 37 commits into
devfrom
ps2/LOOP-4665/functional-algorithm
Sep 7, 2023
Merged

LOOP-4665 Functional Algorithm#542
ps2 merged 37 commits into
devfrom
ps2/LOOP-4665/functional-algorithm

Conversation

@ps2
Copy link
Copy Markdown

@ps2 ps2 commented Sep 6, 2023

https://tidepool.atlassian.net/browse/LOOP-4665

Adding a functional version of the Loop algorithm, to simplify testing, and simplify running of exploratory forecasts, like in the bolus calculator, without mucking with LoopDataManager state.

The new functional version is not used in any user facing code yet; it is simply run in a test to verify that it produces the same forecast as the existing LoopDataManager does for the same input data.

The input data is stored in a single file that contains all the diabetes data and Loop Algorithm settings needed to produce one forecast, and the expected output prediction is also stored in a fixture. Both the LoopDataManager and the functional LoopAlgorithm tests use the same fixtures.

  • LoopAlgorithm.swift contains the new functional version of the prediction part of the Loop algorithm.
  • New LoopAlgorithmInput type, which contains everything needed to run a prediction and dosing recommendation in the Loop Algorithm.
  • Generic GlucosePredictionAlgorithm type added. Not currently used; just an illustration of how future alternate algorithms could conform to a common prototype.

Additional changes included (brought in to sync with DIY):

  • CarbValue refactored to hold double, instead of HKQuantity, as we don't actually support any other units than grams.
  • StoredCarbEntry refactored to allow some fields to be optional, which simplifies the fixtures that encode this type. Also, the non-optional fields were moved to the beginning of the constructor.
  • A few translations (not used in Tidepool Loop)
  • Fix for time change crash. https://tidepool.atlassian.net/browse/LOOP-4723
  • Fixes for favorite foods (not part of Tidepool Loop yet).

ps2 and others added 30 commits August 15, 2023 16:52
Carb entry & favorite foods textfield fix
Updated translations from Lokalise on Sat Aug 19 14:25:48 CDT 2023
Prevent negative duration doses.
Copy link
Copy Markdown

@nhamming nhamming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +80 to +85
// let effectDates = input.glucoseHistory.map { $0.startDate }
// let insulinEffectsAtGlucoseTimestamps = annotatedDoses.glucoseEffects(
// insulinModelProvider: insulinModelProvider,
// longestEffectDuration: input.insulinActivityDuration,
// insulinSensitivityTimeline: input.sensitivity,
// effectDates: effectDates)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Copy link
Copy Markdown
Author

@ps2 ps2 Sep 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. added https://tidepool.atlassian.net/browse/LOOP-4727 to keep track and will remove this commented code.

Comment on lines +174 to +176
// // TODO: Generate recommendation from a prediction
// public static func generateRecommendation(prediction: LoopPrediction) throws -> LoopDosingRecommendation {
// }
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove?

Comment thread LoopKit/GlucoseKit/GlucoseMath.swift Outdated

public struct GlucoseMath {
public static let momentumDataInterval: TimeInterval = .minutes(15)
public static let momentumDataInterval: TimeInterval = .minutes(16)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this update intentional?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, going to revert this. This does change some behavior unintentionally.

@ps2 ps2 merged commit 1fbf710 into dev Sep 7, 2023
@ps2 ps2 deleted the ps2/LOOP-4665/functional-algorithm branch September 7, 2023 20:00
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

Successfully merging this pull request may close these issues.

4 participants