DBSizeCondition.swift 597 B

12345678910111213141516171819
  1. // LoopFollow
  2. // DBSizeCondition.swift
  3. import Foundation
  4. /// Fires when the Nightscout database has filled **≥ threshold percent**
  5. /// of the size limit configured on the site (`DBSIZE_MAX`).
  6. struct DBSizeCondition: AlarmCondition {
  7. static let type: AlarmType = .dbSize
  8. init() {}
  9. func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
  10. guard let limitPercentage = alarm.threshold, limitPercentage > 0 else { return false }
  11. guard let usedPercentage = data.dbSizePercentage else { return false }
  12. return usedPercentage >= limitPercentage
  13. }
  14. }