SampleData.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // SampleData.swift
  3. // FreeAPSCharts
  4. //
  5. // Created by Яков Карпов on 08.03.2021.
  6. //
  7. import Foundation
  8. enum SampleData {
  9. static private var baseComponents: DateComponents = {
  10. var dateComponents = DateComponents()
  11. dateComponents.year = 2021
  12. dateComponents.month = 3
  13. dateComponents.day = 8
  14. dateComponents.timeZone = TimeZone(abbreviation: "MSK")
  15. dateComponents.hour = 8
  16. return dateComponents
  17. }()
  18. static private func generateDate(baseDateComponents: DateComponents, minutes: Int) -> Date {
  19. var localComponents = baseDateComponents
  20. localComponents.minute = minutes
  21. let userCalendar = Calendar(identifier: .gregorian)
  22. return userCalendar.date(from: localComponents)!
  23. }
  24. static private func generateGlucoseStream(startingPoint: Int, length: Int, amount: Int, direction: Int) -> [Int] {
  25. // Downwards
  26. if direction == 0 {
  27. return (1 ... length).map { startingPoint - $0 * amount }
  28. }
  29. return (1 ... length).map { startingPoint + $0 * amount }
  30. }
  31. static var sampleData: [BloodGlucose] {
  32. let mediumUp = generateGlucoseStream(startingPoint: 77, length: 80, amount: 2, direction: 1)
  33. let fastUp = generateGlucoseStream(startingPoint: mediumUp.last!, length: 20, amount: 5, direction: 1)
  34. let fastDown = generateGlucoseStream(startingPoint: fastUp.last!, length: 12, amount: 13, direction: 0)
  35. let mediumDown = generateGlucoseStream(startingPoint: fastDown.last!, length: 33, amount: 3, direction: 0)
  36. let slowUp = generateGlucoseStream(startingPoint: mediumDown.last!, length: 144, amount: 1, direction: 1)
  37. let glucose = mediumUp + fastUp + fastDown + mediumDown + slowUp
  38. let normalTime = (0 ... 278).map{ generateDate(baseDateComponents: baseComponents, minutes: $0 * 5) }
  39. let tenMinutes = (279 ... 288).map{ generateDate(baseDateComponents: baseComponents, minutes: $0 * 10) }
  40. let time = normalTime + tenMinutes
  41. return zip(glucose, time).map { BloodGlucose(sgv: $0, direction: nil, date: UInt64($1.timeIntervalSince1970), dateString: $1, filtered: nil, noise: nil, glucose: nil) }
  42. }
  43. }