carbBolusArrays.swift 821 B

123456789101112131415161718192021222324252627282930
  1. //
  2. // carbBolusArrays.swift
  3. // LoopFollow
  4. //
  5. // Created by Jon Fawcett on 6/17/20.
  6. // Copyright © 2020 Jon Fawcett. All rights reserved.
  7. //
  8. import Foundation
  9. extension MainViewController {
  10. func findNearestBGbyTime(needle: TimeInterval, haystack: [DataStructs.sgvData], startingIndex: Int) -> (sgv: Double, foundIndex: Int) {
  11. // If we can't find a match or things fail, put it at 100 BG
  12. for i in startingIndex..<haystack.count {
  13. // i has reached the end without a result. Put the dot at 100
  14. if i == haystack.count - 1 { return (100.00, 0) }
  15. if needle >= haystack[i].date && needle < haystack[i + 1].date {
  16. return (Double(haystack[i].sgv), i)
  17. }
  18. }
  19. return (100.00, 0)
  20. }
  21. }