connection quality: count connections after retries
This commit is contained in:
parent
7826c41834
commit
59c7955126
4 changed files with 16 additions and 13 deletions
|
@ -243,7 +243,6 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
val stop = CountDownLatch(1)
|
||||
stopConnecting = stop
|
||||
}
|
||||
podStateManager.incrementConnectionAttemptsWithRetries()
|
||||
thread(
|
||||
start = true,
|
||||
name = "ConnectionThread",
|
||||
|
@ -252,6 +251,9 @@ class OmnipodDashPumpPlugin @Inject constructor(
|
|||
stopConnecting?.let {
|
||||
val error = omnipodManager.connect(it).ignoreElements().blockingGet()
|
||||
aapsLogger.info(LTag.PUMPCOMM, "connect error=$error")
|
||||
if (error == null) {
|
||||
podStateManager.incrementSuccessfulConnectionAttemptsAfterRetries()
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
synchronized(this) {
|
||||
|
|
|
@ -33,7 +33,7 @@ interface OmnipodDashPodStateManager {
|
|||
var bluetoothConnectionState: BluetoothConnectionState
|
||||
var connectionAttempts: Int
|
||||
var successfulConnections: Int
|
||||
val connectionAttemptsWithRetries: Int
|
||||
val successfulConnectionAttemptsAfterRetries: Int
|
||||
val failedConnectionsAfterRetries: Int
|
||||
|
||||
var timeZone: TimeZone
|
||||
|
@ -87,7 +87,7 @@ interface OmnipodDashPodStateManager {
|
|||
fun updateFromPairing(uniqueId: Id, pairResult: PairResult)
|
||||
fun reset()
|
||||
fun connectionSuccessRatio(): Float
|
||||
fun incrementConnectionAttemptsWithRetries()
|
||||
fun incrementSuccessfulConnectionAttemptsAfterRetries()
|
||||
fun incrementFailedConnectionsAfterRetries()
|
||||
|
||||
fun createActiveCommand(
|
||||
|
|
|
@ -114,13 +114,13 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
podState.successfulConnections = value
|
||||
}
|
||||
|
||||
override val connectionAttemptsWithRetries: Int
|
||||
override val successfulConnectionAttemptsAfterRetries: Int
|
||||
@Synchronized
|
||||
get() = podState.connectionAttemptsWithRetries
|
||||
get() = podState.successfulConnectionAttemptsAfterRetries
|
||||
|
||||
@Synchronized
|
||||
override fun incrementConnectionAttemptsWithRetries() {
|
||||
podState.connectionAttemptsWithRetries++
|
||||
override fun incrementSuccessfulConnectionAttemptsAfterRetries() {
|
||||
podState.successfulConnectionAttemptsAfterRetries++
|
||||
}
|
||||
|
||||
override val failedConnectionsAfterRetries: Int
|
||||
|
@ -646,10 +646,10 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
}
|
||||
|
||||
override fun connectionSuccessRatio(): Float {
|
||||
if (connectionAttemptsWithRetries == 0) {
|
||||
if (failedConnectionsAfterRetries + successfulConnectionAttemptsAfterRetries == 0) {
|
||||
return 0.0F
|
||||
}
|
||||
return 1 - (failedConnectionsAfterRetries.toFloat() / connectionAttemptsWithRetries)
|
||||
return successfulConnectionAttemptsAfterRetries.toFloat() / (successfulConnectionAttemptsAfterRetries + failedConnectionsAfterRetries)
|
||||
}
|
||||
|
||||
override fun reset() {
|
||||
|
@ -691,7 +691,7 @@ class OmnipodDashPodStateManagerImpl @Inject constructor(
|
|||
OmnipodDashPodStateManager.BluetoothConnectionState.DISCONNECTED
|
||||
var connectionAttempts = 0
|
||||
var successfulConnections = 0
|
||||
var connectionAttemptsWithRetries = 0
|
||||
var successfulConnectionAttemptsAfterRetries = 0
|
||||
var failedConnectionsAfterRetries = 0
|
||||
var messageSequenceNumber: Short = 0
|
||||
var sequenceNumberOfLastProgrammingCommand: Short? = null
|
||||
|
|
|
@ -256,14 +256,15 @@ class OmnipodDashOverviewFragment : DaggerFragment() {
|
|||
?: PLACEHOLDER
|
||||
|
||||
val connectionSuccessPercentage = podStateManager.connectionSuccessRatio() * 100
|
||||
val connectionAttempts = podStateManager.failedConnectionsAfterRetries + podStateManager.successfulConnectionAttemptsAfterRetries
|
||||
val successPercentageString = String.format("%.2f %%", connectionSuccessPercentage)
|
||||
val quality =
|
||||
"${podStateManager.connectionAttemptsWithRetries - podStateManager.failedConnectionsAfterRetries}/${podStateManager.connectionAttemptsWithRetries} :: $successPercentageString"
|
||||
"${podStateManager.successfulConnectionAttemptsAfterRetries}/$connectionAttempts :: $successPercentageString"
|
||||
bluetoothStatusBinding.omnipodDashBluetoothConnectionQuality.text = quality
|
||||
val connectionStatsColor = when {
|
||||
connectionSuccessPercentage < 70 && podStateManager.connectionAttemptsWithRetries > 50 ->
|
||||
connectionSuccessPercentage < 70 && podStateManager.successfulConnectionAttemptsAfterRetries > 50 ->
|
||||
Color.RED
|
||||
connectionSuccessPercentage < 90 && podStateManager.connectionAttemptsWithRetries > 50 ->
|
||||
connectionSuccessPercentage < 90 && podStateManager.successfulConnectionAttemptsAfterRetries > 50 ->
|
||||
Color.YELLOW
|
||||
else ->
|
||||
Color.WHITE
|
||||
|
|
Loading…
Reference in a new issue