updates for lock screen, foxed graphs on front end
This commit is contained in:
+1
-1
@@ -287,7 +287,7 @@ struct TransferHistoryChart: View {
|
|||||||
|
|
||||||
private var end: Date { updatedAt ?? Date() }
|
private var end: Date { updatedAt ?? Date() }
|
||||||
private var start: Date { end.addingTimeInterval(-Double(minutes * 60)) }
|
private var start: Date { end.addingTimeInterval(-Double(minutes * 60)) }
|
||||||
private var samples: [TransferSample] { history.samples.filter { $0.date >= start && $0.date <= end } }
|
private var samples: [TransferSample] { history.samples(from: start, through: end) }
|
||||||
private var selectedSample: TransferSample? {
|
private var selectedSample: TransferSample? {
|
||||||
guard let selection else { return nil }
|
guard let selection else { return nil }
|
||||||
return samples.min { abs($0.date.timeIntervalSince(selection)) < abs($1.date.timeIntervalSince(selection)) }
|
return samples.min { abs($0.date.timeIntervalSince(selection)) < abs($1.date.timeIntervalSince(selection)) }
|
||||||
|
|||||||
+11
-1
@@ -140,9 +140,19 @@ struct TransferHistory {
|
|||||||
private(set) var samples: [TransferSample] = []
|
private(set) var samples: [TransferSample] = []
|
||||||
private var segment = 0
|
private var segment = 0
|
||||||
|
|
||||||
|
func samples(from start: Date, through end: Date) -> [TransferSample] {
|
||||||
|
let lower = start.timeIntervalSinceReferenceDate
|
||||||
|
let upper = end.timeIntervalSinceReferenceDate
|
||||||
|
// Avoid SDK-new Date >= / <= entry points missing from some iOS betas.
|
||||||
|
return samples.filter {
|
||||||
|
let time = $0.date.timeIntervalSinceReferenceDate
|
||||||
|
return time >= lower && time <= upper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mutating func record(download: Int64, upload: Int64, at date: Date = Date()) {
|
mutating func record(download: Int64, upload: Int64, at date: Date = Date()) {
|
||||||
if let last = samples.last {
|
if let last = samples.last {
|
||||||
guard date >= last.date else { return }
|
guard date.timeIntervalSinceReferenceDate >= last.date.timeIntervalSinceReferenceDate else { return }
|
||||||
if date.timeIntervalSince(last.date) > 10 { segment += 1 }
|
if date.timeIntervalSince(last.date) > 10 { segment += 1 }
|
||||||
// Extra action/manual refreshes must not inflate the history buffer.
|
// Extra action/manual refreshes must not inflate the history buffer.
|
||||||
if date.timeIntervalSince(last.date) < 1 { samples.removeLast() }
|
if date.timeIntervalSince(last.date) < 1 { samples.removeLast() }
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.0</string>
|
<string>1.0</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>5</string>
|
<string>6</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSFaceIDUsageDescription</key>
|
<key>NSFaceIDUsageDescription</key>
|
||||||
|
|||||||
@@ -249,6 +249,10 @@ final class MockProtocol: URLProtocol, @unchecked Sendable {
|
|||||||
check(liveHistory.transferHistory.samples.count == 1, "Failed refresh never fabricates a speed sample")
|
check(liveHistory.transferHistory.samples.count == 1, "Failed refresh never fabricates a speed sample")
|
||||||
liveHistory.disconnect()
|
liveHistory.disconnect()
|
||||||
check(liveHistory.transferHistory.samples.isEmpty, "Disconnect removes actual collected history")
|
check(liveHistory.transferHistory.samples.isEmpty, "Disconnect removes actual collected history")
|
||||||
|
var windowHistory = TransferHistory()
|
||||||
|
for second in [0, 3, 6] { windowHistory.record(download: 1, upload: 2, at: origin.addingTimeInterval(Double(second))) }
|
||||||
|
check(windowHistory.samples(from: origin.addingTimeInterval(3), through: origin.addingTimeInterval(6)).count == 2, "History window includes exact timestamp boundaries without new Date comparison entry points")
|
||||||
|
check(windowHistory.samples(from: origin.addingTimeInterval(7), through: origin.addingTimeInterval(9)).isEmpty, "History window excludes samples outside its numeric time range")
|
||||||
another.close(); transport.close(); print("\(checks) contract checks passed.")
|
another.close(); transport.close(); print("\(checks) contract checks passed.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user