Skip to content

Instantly share code, notes, and snippets.

@Elvis10ten
Created November 7, 2020 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elvis10ten/d22a0654328fd2a1094bd80b4993a53b to your computer and use it in GitHub Desktop.
Save Elvis10ten/d22a0654328fd2a1094bd80b4993a53b to your computer and use it in GitHub Desktop.
val isConnected = bondSteadyState == PeripheralBond.State.CONNECTED
val hasPriority = priority != NO_PRIORITY
private val maxPossibleConnectionAndInteractiveScore = 4 + 2
// Any device with a higher priority should always rank higher.
private val priorityScore = (maxPossibleConnectionAndInteractiveScore + 1.0).pow(priority)
private val connectionScore: Int get() {
// Connection should contribute more if we can't stream
val trueValue = if(canStreamData) 2 else 4
return if(isConnected) trueValue else 1
}
private val interactiveScore = if(owner.isInteractive) 2 else 1
private val timestampScore = log10(timestamp.toDouble())
internal val rank = priorityScore + connectionScore + interactiveScore + timestampScore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment