Module: TrueDL

Defined in:
lib/true_dl.rb,
lib/truedl/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Class Method Summary collapse

Class Method Details

.coefficient_for_place(place) ⇒ Float?

Formula for TrueDL is described in this post: pecheny.me/blog/truedl/

Parameters:

  • place (Integer, Float)

Returns:

  • (Float, nil)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/true_dl.rb', line 11

def self.coefficient_for_place(place)
  case place
  when 1..10 then 1.61
  when 11..25 then 1.52
  when 26..50 then 1.43
  when 51..100 then 1.32
  when 101..250 then 1.16
  when 251..500 then 1.0
  when 501..1000 then 0.81
  when 1001..2000 then 0.6
  when 2001..3000 then 0.43
  when 3001..5000 then 0.31
  end
end

.true_dl_for_tournament(teams:, number_of_questions:) ⇒ Float?

Calculates TrueDL for a tournament: an average of all non-nil team TrueDLs. Might be nil for tournaments where all teams are ranked below top 5000.

Parameters:

  • teams: (Array)

    list of hashes with ‘points` and `ranking`, e.g., `{ points: 28, ranking: 22 }`

  • number_of_questions (Integer)

Returns:

  • (Float, nil)


44
45
46
47
48
49
50
51
52
# File 'lib/true_dl.rb', line 44

def self.true_dl_for_tournament(teams:, number_of_questions:)
  dls = teams.map do |team|
    truedl_for_team(team_points: team[:points], team_ranking: team[:ranking], number_of_questions:)
  end.compact

  return if dls.empty?

  dls.sum / dls.size
end

.truedl_for_team(team_points:, team_ranking:, number_of_questions:) ⇒ Float

Parameters:

  • team_points (Integer)
  • team_ranking (Integer, Float)
  • number_of_questions (Integer)

Returns:

  • (Float)


30
31
32
33
34
35
36
# File 'lib/true_dl.rb', line 30

def self.truedl_for_team(team_points:, team_ranking:, number_of_questions:)
  return if team_points.nil?
  return if number_of_questions.nil? || number_of_questions < 1
  return if team_ranking.nil? || team_ranking > 5000 || team_ranking < 1

  (1 - [team_points / coefficient_for_place(team_ranking), number_of_questions].min / number_of_questions) * 10
end