ruboty-rating 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bc543934aa2a1d16f429c190f35c2c6c22de7845
4
+ data.tar.gz: 1723800dce611197bf767c9dcfb5d2c09fa3cfa3
5
+ SHA512:
6
+ metadata.gz: d0fed7416f26634ecdc237b69fb42bdccb52ed8fb65a245fac3cd77a248571cb85dff5f63bbef5df9b826078bcdc119b464203b7d450f03ea04cc89f2b88d197
7
+ data.tar.gz: e1fd7cb9344c567247a2bfbb968db13baa05c1f1adbeb3ddb913153d2739be40124b8ba6e0ba49739eff1620b9fd809da0c10d4cbb4e6db277b356c344961b41
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at tomo.asleep@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-rating.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Ruboty::Rating
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruboty/rating`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-rating'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruboty-rating
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruboty-rating. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/rating"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,57 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Rating < Base
4
+ GAME_RESULT_PATTERN = %r{(?<left_player>\w+)(?:\s+)(?<result>[<>])(?:\s+)(?<right_player>\w+)$}
5
+
6
+ on(
7
+ GAME_RESULT_PATTERN,
8
+ name: 'remember_game_result',
9
+ description: 'Remember a game result',
10
+ )
11
+
12
+ on(
13
+ /show\s+rating\s+(?<player>\w+)/,
14
+ name: 'show_rating',
15
+ description: 'Show rating of a player',
16
+ )
17
+
18
+ on(
19
+ /show\s+ratings/,
20
+ name: 'show_ratings',
21
+ description: 'Show ratings of all player',
22
+ )
23
+
24
+ on(
25
+ /set\s+rating\s+(?<player>\w+)\s+(?<new_rating>\d+)/,
26
+ name: 'set_rating',
27
+ description: 'Set rating of a player manually',
28
+ )
29
+
30
+ on(
31
+ /delete\s+player\s+(?<player>\w+)/,
32
+ name: 'delete_player',
33
+ description: 'Show rating of a player',
34
+ )
35
+
36
+ def remember_game_result(message)
37
+ Ruboty::Rating::Actions::RememberGameResult.new(message).call
38
+ end
39
+
40
+ def show_rating(message)
41
+ Ruboty::Rating::Actions::ShowRating.new(message).call
42
+ end
43
+
44
+ def show_ratings(message)
45
+ Ruboty::Rating::Actions::ShowRatings.new(message).call
46
+ end
47
+
48
+ def set_rating(message)
49
+ Ruboty::Rating::Actions::SetRating.new(message).call
50
+ end
51
+
52
+ def set_rating(message)
53
+ Ruboty::Rating::Actions::SetRating.new(message).call
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,16 @@
1
+ require 'elo_rating'
2
+
3
+ require 'ruboty'
4
+ require 'ruboty/rating/actions/base'
5
+ require 'ruboty/rating/actions/delete_player'
6
+ require 'ruboty/rating/actions/remember_game_result'
7
+ require 'ruboty/rating/actions/set_rating'
8
+ require 'ruboty/rating/actions/show_rating'
9
+ require 'ruboty/rating/actions/show_ratings'
10
+ require 'ruboty/rating/version'
11
+ require 'ruboty/handlers/rating'
12
+
13
+ module Ruboty
14
+ module Rating
15
+ end
16
+ end
@@ -0,0 +1,22 @@
1
+ module Ruboty
2
+ module Rating
3
+ module Actions
4
+ class ShowRatings < Base
5
+ def call
6
+ if rating = ratings[player]
7
+ message.reply("#{player}: #{rating}")
8
+ else
9
+ message.reply("#{player} has not played any game.")
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ # @return [String]
16
+ def player
17
+ message[:player]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,32 @@
1
+ module Ruboty
2
+ module Rating
3
+ module Actions
4
+ class Base < Ruboty::Actions::Base
5
+ RATINGS_NAMESPACE = 'ratings'
6
+ GAME_RESULTS_NAMESPACE = 'rating_game_results'
7
+
8
+ attr_reader :message
9
+
10
+ def initialize(message)
11
+ @message = message
12
+ end
13
+
14
+ private
15
+
16
+ # @return [Hash{String => Integer}]
17
+ def ratings
18
+ message.robot.brain.data[RATINGS_NAMESPACE] ||= {}
19
+ end
20
+
21
+ # @return [Array<(String, String)>]
22
+ def game_results
23
+ message.robot.brain.data[GAME_RESULTS_NAMESPACE] ||= []
24
+ end
25
+
26
+ def default_rating
27
+ 1500
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,19 @@
1
+ module Ruboty
2
+ module Rating
3
+ module Actions
4
+ class DeletePlayer < Base
5
+ def call
6
+ ratings.delete(player)
7
+ message.reply("Removed #{player}")
8
+ end
9
+
10
+ private
11
+
12
+ # @return [String]
13
+ def player
14
+ message[:player]
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ module Ruboty
2
+ module Rating
3
+ module Actions
4
+ class RememberGameResult < Base
5
+ def call
6
+ match = EloRating::Match.new
7
+ winner_rating_old = (ratings[winner] || default_rating).to_i
8
+ loser_rating_old = (ratings[loser] || default_rating).to_i
9
+ match.add_player(rating: winner_rating_old, winner: true)
10
+ match.add_player(rating: loser_rating_old)
11
+
12
+ winner_rating_new, loser_rating_new = match.updated_ratings
13
+ ratings[winner] = winner_rating_new
14
+ ratings[loser] = loser_rating_new
15
+ game_results.push([winner, loser])
16
+
17
+ message.reply("#{winner}: #{winner_rating_old} -> #{winner_rating_new}\n#{loser}: #{loser_rating_old} -> #{loser_rating_new}")
18
+ end
19
+
20
+ private
21
+
22
+ # @return [String]
23
+ def winner
24
+ left_win? ? message[:left_player] : message[:right_player]
25
+ end
26
+
27
+ # @return [String]
28
+ def loser
29
+ left_win? ? message[:right_player] : message[:left_player]
30
+ end
31
+
32
+ # @return [true, false]
33
+ def left_win?
34
+ message[:result] == '>'
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,24 @@
1
+ module Ruboty
2
+ module Rating
3
+ module Actions
4
+ class SetRating < Base
5
+ def call
6
+ ratings[player] = new_rating
7
+ message.reply("Updated the rating of #{player}: #{new_rating}")
8
+ end
9
+
10
+ private
11
+
12
+ # @return [String]
13
+ def player
14
+ message[:player]
15
+ end
16
+
17
+ # @return [Integer]
18
+ def new_rating
19
+ message[:new_rating].to_i
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ module Ruboty
2
+ module Rating
3
+ module Actions
4
+ class ShowRating < Base
5
+ def call
6
+ if rating = ratings[player]
7
+ message.reply("#{player}: #{rating}")
8
+ else
9
+ message.reply("#{player} has not played any game.")
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ # @return [String]
16
+ def player
17
+ message[:player]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,12 @@
1
+ module Ruboty
2
+ module Rating
3
+ module Actions
4
+ class ShowRatings < Base
5
+ def call
6
+ rating_ranking = ratings.sort { |(_player, rating)| -rating }
7
+ message.reply(rating_ranking.map { |(player, rating)| "#{player}: #{rating}" }.join("\n"))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Rating
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/rating/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-rating"
8
+ spec.version = Ruboty::Rating::VERSION
9
+ spec.authors = ["Tomoya Chiba"]
10
+ spec.email = ["tomo.asleep@gmail.com"]
11
+
12
+ spec.summary = "A ruboty plugin to score your game results and calculate elo ratings"
13
+ spec.homepage = "https://github.com/tomoasleep/ruboty-rating"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "elo_rating", "~> 1.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-rating
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomoya Chiba
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: elo_rating
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - tomo.asleep@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/ruboty/handlers/rating.rb
86
+ - lib/ruboty/rating.rb
87
+ - lib/ruboty/rating/actions/.set_rating.rb@neomake_9361_42.rb
88
+ - lib/ruboty/rating/actions/base.rb
89
+ - lib/ruboty/rating/actions/delete_player.rb
90
+ - lib/ruboty/rating/actions/remember_game_result.rb
91
+ - lib/ruboty/rating/actions/set_rating.rb
92
+ - lib/ruboty/rating/actions/show_rating.rb
93
+ - lib/ruboty/rating/actions/show_ratings.rb
94
+ - lib/ruboty/rating/version.rb
95
+ - ruboty-rating.gemspec
96
+ homepage: https://github.com/tomoasleep/ruboty-rating
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.6.11
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: A ruboty plugin to score your game results and calculate elo ratings
119
+ test_files: []