OpenAPSSwift.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import Foundation
  2. import OpenAPSKit
  3. struct OpenAPSSwift {
  4. static func makeProfile(
  5. preferences: JSON,
  6. pumpSettings: JSON,
  7. bgTargets: JSON,
  8. basalProfile: JSON,
  9. isf: JSON,
  10. carbRatio: JSON,
  11. tempTargets: JSON,
  12. model: JSON,
  13. autotune: JSON,
  14. freeaps: JSON
  15. ) -> RawJSON {
  16. do {
  17. let preferences = try JSONBridge.preferences(from: preferences)
  18. let pumpSettings = try JSONBridge.pumpSettings(from: pumpSettings)
  19. let bgTargets = try JSONBridge.bgTargets(from: bgTargets)
  20. let basalProfile = try JSONBridge.basalProfile(from: basalProfile)
  21. let isf = try JSONBridge.insulinSensitivities(from: isf)
  22. let carbRatio = try JSONBridge.carbRatios(from: carbRatio)
  23. let tempTargets = try JSONBridge.tempTargets(from: tempTargets)
  24. let model = JSONBridge.model(from: model)
  25. let autotune = try JSONBridge.autotune(from: autotune)
  26. let freeaps = try JSONBridge.freeapsSettings(from: freeaps)
  27. let profile = try OpenAPSKit.ProfileGenerator.generate(
  28. pumpSettings: pumpSettings,
  29. bgTargets: bgTargets,
  30. basalProfile: basalProfile,
  31. isf: isf,
  32. preferences: preferences,
  33. carbRatios: carbRatio,
  34. tempTargets: tempTargets,
  35. model: model,
  36. autotune: autotune,
  37. freeaps: freeaps
  38. )
  39. return try JSONBridge.to(profile)
  40. } catch {
  41. warning(.openAPS, "OpenAPSSwift exception \(error)")
  42. return .null
  43. }
  44. }
  45. }