OpenAPSSwift.swift 1.6 KB

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