truedl 0.1.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/true_dl.rb +24 -8
  3. data/lib/truedl/version.rb +1 -1
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f3ad337cf9453198d285c7f9f464dccc2e3732c0e35d629f987c7baebe440f2
4
- data.tar.gz: af5e0ce7949612b006b9f4d5f3c7079df1ff3750de639900a4d7f39ceaea6b05
3
+ metadata.gz: aecc2e0ead4e5c843753ebdf1ef19adf1a8680027fdad13c80f1b30968ce6142
4
+ data.tar.gz: 4ada3663006bea004fea06308b22a92392a939c17acce63745ec027a25281217
5
5
  SHA512:
6
- metadata.gz: e6ff70385412821d64dfb9a06f91cb1fa6b5bb7dd1f4ca16f986874e474d7c68dcb5d49320372d2fbce706fa78782d5fe7b52ffa024c61aabe048d68e0d7e0a9
7
- data.tar.gz: c345c8997bdc514a9fa3f6430109b72d697bb0bd855765ed4777fbbb89af09e150f9447ead4b4f5414d578993c1be48af7d8793ae817a4ddbdd4eb9f8471384e
6
+ metadata.gz: d9ed6a9069c26eda75caac0a90d587f9beaf59ea44eeebd47c7a37132679c75ae1df91b79fa1a0166b07aa7b4194d927a48859b5d1974ddc1aca5febb231c787
7
+ data.tar.gz: d82bd1fe4568ffe5f42dea6869c9ea50b638ed227ac48d8904a797084df0af1b453a83ddc0b45e02adbe45400b9b791ba2a51ce2ee4da25fcf273cc904eb00e8
data/lib/true_dl.rb CHANGED
@@ -2,10 +2,14 @@
2
2
 
3
3
  require_relative "truedl/version"
4
4
 
5
+ # Formula for TrueDL is described in this post: https://pecheny.me/blog/truedl/
5
6
  module TrueDL
6
- ##
7
- # Formula for TrueDL is described in this post: https://pecheny.me/blog/truedl/
8
- #
7
+ TeamDL = Data.define(:id, :dl) do
8
+ def ==(other)
9
+ id == other.id && (dl - other.dl).abs < 0.001
10
+ end
11
+ end
12
+
9
13
  # @param [Integer, Float] place
10
14
  # @return [Float, nil]
11
15
  def self.coefficient_for_place(place)
@@ -35,19 +39,31 @@ module TrueDL
35
39
  (1 - [team_points / coefficient_for_place(team_ranking), number_of_questions].min / number_of_questions) * 10
36
40
  end
37
41
 
42
+ # Returns an array of TrueDL values for all teams
43
+ #
44
+ # @param [Array] teams: list of hashes with `id`, `points` and `ranking`: `{ id: 1, points: 28, ranking: 22 }`
45
+ # @param [Integer] number_of_questions
46
+ # @return [Array<TeamTrueDl>]
47
+ def self.true_dls_for_tournament(teams:, number_of_questions:)
48
+ teams.map do |team|
49
+ dl = truedl_for_team(team_points: team[:points], team_ranking: team[:ranking], number_of_questions:)
50
+ next if dl.nil?
51
+
52
+ TeamDL.new(id: team[:id], dl:)
53
+ end.compact
54
+ end
55
+
38
56
  # Calculates TrueDL for a tournament: an average of all non-nil team TrueDLs.
39
57
  # Might be nil for tournaments where all teams are ranked below top 5000.
40
58
  #
41
- # @param [Array] teams: list of hashes with `points` and `ranking`, e.g., `{ points: 28, ranking: 22 }`
59
+ # @param [Array] teams: list of hashes with `id`, `points` and `ranking`: `{ id: 1, points: 28, ranking: 22 }`
42
60
  # @param [Integer] number_of_questions
43
61
  # @return [Float, nil]
44
62
  def self.true_dl_for_tournament(teams:, number_of_questions:)
45
- dls = teams.map do |team|
46
- truedl_for_team(team_points: team[:points], team_ranking: team[:ranking], number_of_questions:)
47
- end.compact
63
+ dls = true_dls_for_tournament(teams:, number_of_questions:)
48
64
 
49
65
  return if dls.empty?
50
66
 
51
- dls.sum / dls.size
67
+ dls.map(&:dl).sum / dls.size
52
68
  end
53
69
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TrueDL
4
- VERSION = "0.1.3"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truedl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jury Razumau
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-08 00:00:00.000000000 Z
11
+ date: 2024-10-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -36,7 +36,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '3.0'
39
+ version: '3.1'
40
40
  required_rubygems_version: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ">="