LoopStatsView.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import SwiftDate
  2. import SwiftUI
  3. /// A SwiftUI view displaying statistics about the looping process in an Automated Insulin Delivery (AID) system.
  4. struct LoopStatsView: View {
  5. /// The list of loop statistics records used to generate the statistics.
  6. let statsData: [LoopStatsProcessedData]
  7. /// The main body of the `LoopStatsView`, displaying loop statistics.
  8. var body: some View {
  9. if let successfulStats = statsData.first(where: { $0.category == .successfulLoop }) {
  10. HStack {
  11. StatChartUtils.statView(
  12. title: String(localized: "Loops"),
  13. value: successfulStats.count.formatted()
  14. )
  15. Spacer()
  16. StatChartUtils.statView(
  17. title: String(localized: "Interval"),
  18. value: (successfulStats.medianInterval / 60)
  19. .formatted(.number.grouping(.never).rounded().precision(.fractionLength(1))) + "m"
  20. )
  21. Spacer()
  22. StatChartUtils.statView(
  23. title: String(localized: "Duration"),
  24. value: successfulStats.medianDuration
  25. .formatted(.number.grouping(.never).rounded().precision(.fractionLength(1))) + "s"
  26. )
  27. Spacer()
  28. StatChartUtils.statView(
  29. title: String(localized: "Success"),
  30. value: (successfulStats.percentage / 100)
  31. .formatted(.percent.grouping(.never).rounded().precision(.fractionLength(1)))
  32. )
  33. Spacer()
  34. StatChartUtils.statView(
  35. title: String(localized: "Days"),
  36. value: successfulStats.totalDays.description
  37. )
  38. }
  39. .padding()
  40. }
  41. }
  42. }