OpenAPSSwift.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. freeaps: JSON
  13. ) -> RawJSON {
  14. do {
  15. let preferences = try JSONBridge.preferences(from: preferences)
  16. let pumpSettings = try JSONBridge.pumpSettings(from: pumpSettings)
  17. let bgTargets = try JSONBridge.bgTargets(from: bgTargets)
  18. let basalProfile = try JSONBridge.basalProfile(from: basalProfile)
  19. let isf = try JSONBridge.insulinSensitivities(from: isf)
  20. let carbRatio = try JSONBridge.carbRatios(from: carbRatio)
  21. let tempTargets = try JSONBridge.tempTargets(from: tempTargets)
  22. let model = JSONBridge.model(from: model)
  23. let freeaps = try JSONBridge.freeapsSettings(from: freeaps)
  24. let profile = try ProfileGenerator.generate(
  25. pumpSettings: pumpSettings,
  26. bgTargets: bgTargets,
  27. basalProfile: basalProfile,
  28. isf: isf,
  29. preferences: preferences,
  30. carbRatios: carbRatio,
  31. tempTargets: tempTargets,
  32. model: model,
  33. freeaps: freeaps
  34. )
  35. return try JSONBridge.to(profile)
  36. } catch {
  37. warning(.openAPS, "OpenAPSSwift exception \(error)")
  38. return .null
  39. }
  40. }
  41. }