Skip to content

Commit

Permalink
tutor peers rating range using gaussian distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 15, 2023
1 parent 5f6529b commit fb4bae5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ lazy val importer = module("importer",

lazy val insight = module("insight",
Seq(common, game, user, analyse, relation, pref, socket, round, security),
Seq(scalatags) ++ reactivemongo.bundle
Seq(scalatags, breeze) ++ reactivemongo.bundle
)

lazy val tutor = module("tutor",
Expand Down
17 changes: 14 additions & 3 deletions modules/insight/src/main/Question.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,22 @@ case class Question[X](

object Question:

private val peerDistribution = {
// based on https://lichess.org/stat/rating/distribution/blitz
// https://hq.lichess.ovh/#narrow/stream/1-general/topic/tutor.2C.20let's.20build.20it.20together/near/2159478
import breeze.stats.distributions.*
Gaussian(1465d, 394d)(using Rand)
}

case class Peers(rating: MeanRating):
def ratingRange: Range =
// based on https://lichess.org/stat/rating/distribution/blitz
val diff = Math.ceil(0.0002647 * Math.pow(rating.value, 2) - 0.80735 * rating.value + 635.4411).toInt
Range(rating.value - diff, rating.value + diff)
val cdf = peerDistribution.cdf(rating.value) // percentile of player given rating
val proportion = 0.03 // probability density function, i.e. proportion of players
val (lower, upper) = (cdf - proportion, cdf + proportion)
Range(
peerDistribution.inverseCdf(lower atLeast 0).toInt atLeast 0,
peerDistribution.inverseCdf(upper atMost 1).toInt atMost 4000
)
def showRatingRange =
val rr = ratingRange
s"${rr.min}-${rr.max}"
Expand Down
1 change: 1 addition & 0 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ object Dependencies {
val uaparser = "org.uaparser" %% "uap-scala" % "0.14.0"
val apacheText = "org.apache.commons" % "commons-text" % "1.10.0"
val bloomFilter = "com.github.alexandrnikitin" %% "bloom-filter" % "0.13.1_lila-1"
val breeze = "org.scalanlp" %% "breeze" % "2.1.0"

object specs2 {
val version = "5.2.0"
Expand Down

0 comments on commit fb4bae5

Please sign in to comment.