truedl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +15 -0
- data/lib/true_dl.rb +53 -0
- data/lib/truedl/version.rb +5 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: adb89d73bbf1d5bcf9b06aa01c55fbc751c2de80e3f6a766870476b48f522330
|
4
|
+
data.tar.gz: eab42b1989540e3c60df1e47015dc0014b72711c98568f37e2d43f85e5779250
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20afbbb1ad91eae384da119f8e315b38dad67f0614e3aa6e6a0ebd40300972640dc627d08e39b13bd49fb3dcc82037aa8a25cb3e043ece237f320b81fae2a00b
|
7
|
+
data.tar.gz: 841f58f4e5a75a0522f9f862af41f71305f73d709c3e2fe28f249f713129d215f30727801984bfce89175a00003c2bb78d13c3540df01eb518c3b2aa61670991
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Truedl
|
2
|
+
|
3
|
+
Ruby implementation of [the TrueDL formula](https://pecheny.me/blog/truedl/).
|
4
|
+
|
5
|
+
## Contributing
|
6
|
+
|
7
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/razumau/truedl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/truedl/blob/master/CODE_OF_CONDUCT.md).
|
8
|
+
|
9
|
+
## License
|
10
|
+
|
11
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
12
|
+
|
13
|
+
## Code of Conduct
|
14
|
+
|
15
|
+
Everyone interacting in the Truedl project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/truedl/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/true_dl.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "truedl/version"
|
4
|
+
|
5
|
+
module TrueDL
|
6
|
+
##
|
7
|
+
# Formula for TrueDL is described in this post: https://pecheny.me/blog/truedl/
|
8
|
+
#
|
9
|
+
# @param [Integer, Float] place
|
10
|
+
# @return [Float, nil]
|
11
|
+
def self.coefficient_for_place(place)
|
12
|
+
case place
|
13
|
+
when 1..10 then 1.61
|
14
|
+
when 11..25 then 1.52
|
15
|
+
when 26..50 then 1.43
|
16
|
+
when 51..100 then 1.32
|
17
|
+
when 101..250 then 1.16
|
18
|
+
when 251..500 then 1.0
|
19
|
+
when 501..1000 then 0.81
|
20
|
+
when 1001..2000 then 0.6
|
21
|
+
when 2001..3000 then 0.43
|
22
|
+
when 3001..5000 then 0.31
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# @param [Integer] team_points
|
27
|
+
# @param [Integer, Float] team_ranking
|
28
|
+
# @param [Integer] number_of_questions
|
29
|
+
# @return [Float]
|
30
|
+
def self.truedl_for_team(team_points:, team_ranking:, number_of_questions:)
|
31
|
+
return if team_points.nil?
|
32
|
+
return if number_of_questions.nil? || number_of_questions < 1
|
33
|
+
return if team_ranking.nil? || team_ranking > 5000 || team_ranking < 1
|
34
|
+
|
35
|
+
(1 - [team_points / coefficient_for_place(team_ranking), number_of_questions].min / number_of_questions) * 10
|
36
|
+
end
|
37
|
+
|
38
|
+
# Calculates TrueDL for a tournament: an average of all non-nil team TrueDLs.
|
39
|
+
# Might be nil for tournaments where all teams are ranked below top 5000.
|
40
|
+
#
|
41
|
+
# @param [Array] teams: list of hashes with `points` and `ranking`, e.g., `{ points: 28, ranking: 22 }`
|
42
|
+
# @param [Integer] number_of_questions
|
43
|
+
# @return [Float, nil]
|
44
|
+
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
|
48
|
+
|
49
|
+
return if dls.empty?
|
50
|
+
|
51
|
+
dls.sum / dls.size
|
52
|
+
end
|
53
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: truedl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jury Razumau
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- mail@razumau.net
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/true_dl.rb
|
22
|
+
- lib/truedl/version.rb
|
23
|
+
homepage: https://github.com/razumau/truedl
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata:
|
27
|
+
allowed_push_host: https://rubygems.org
|
28
|
+
homepage_uri: https://github.com/razumau/truedl
|
29
|
+
source_code_uri: https://github.com/razumau/truedl
|
30
|
+
changelog_uri: https://github.com/razumau/truedl/blob/main/CHANGELOG.md
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '3.0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.4.18
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Ruby implementation of TrueDL.
|
50
|
+
test_files: []
|