pcbr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (9) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +3 -0
  4. data/README.md +27 -0
  5. data/Rakefile +8 -0
  6. data/lib/pcbr.rb +41 -0
  7. data/pcbr.gemspec +18 -0
  8. data/spec/_spec.rb +55 -0
  9. metadata +78 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b49a66a529119ba0d10c495455cd2b8d0791b49c
4
+ data.tar.gz: eaba59b3069d04b8a0dc6e594b13ea58e2ec923f
5
+ SHA512:
6
+ metadata.gz: 93360c02ed2e69dcd9346f1c63c0cc81ae9ab646a642a083b52ce02b3ac06a6474b96f4ff0df03521d8774940cdee949fb5c4f2fe5ffa33263d4f78203d8eebf
7
+ data.tar.gz: 7bfd228ef04e97a3d94f9754b2957c91ea6498eb9b46559335d75c43529e24a5f8d8f275c09e6476491eb0132cca21f374955cc98f6876d18dbb4528e7c81ece
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,27 @@
1
+ # PCBR (Pairs Comparision Based Rating)
2
+
3
+ Making ratings is fun. After applying my method several times I've decided to gemify it.
4
+
5
+ ### Examples
6
+
7
+ TODO
8
+
9
+ ### How it works
10
+
11
+ The first idea of rating items by one-to-one comparision was about QuakeLive players in 2013 or so and it didn't work well. At that time I was thinking about tree data structure. Later in May 2015 I've realised that it's simply about dots in n-dimensional space and sectors.
12
+
13
+ TODO: better desription
14
+
15
+ At the moment it's a "proof of concept". It needs huge optimisations for lookups, maybe using trees.
16
+
17
+ ### Installation
18
+
19
+ $ gem install pcbr
20
+
21
+ ### Testing with RSpec before contributing
22
+
23
+ rspec
24
+
25
+ or
26
+
27
+ rake spec
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => %w{ spec }
4
+
5
+ require "rspec/core/rake_task"
6
+ RSpec::Core::RakeTask.new(:spec) do |t|
7
+ t.verbose = false
8
+ end
@@ -0,0 +1,41 @@
1
+ class PCBR
2
+
3
+ VERSION = "0.0.1"
4
+
5
+ def initialize &block
6
+ @table = []
7
+ @callback = block || ->_{[*_]}
8
+ end
9
+
10
+ def size
11
+ @table.size
12
+ end
13
+
14
+ def store key, *vector
15
+ vector = vector.empty? ? [key] : vector.first
16
+ score = @table.map do |item|
17
+ @callback[vector].zip(@callback[item[1]]).map do |a, b|
18
+ a <=> b
19
+ end.uniq.inject(0, :+).tap do |point|
20
+ item[2] -= point
21
+ end
22
+ end.inject 0, :+
23
+ @table.push [key, vector, score]
24
+ end
25
+
26
+ def score key
27
+ @table.assoc(key).last
28
+ end
29
+
30
+ def sorted
31
+ @table.sort_by.with_index{ |item, i| [item.last, i] }.map(&:first)
32
+ end
33
+
34
+ def data
35
+ Hash[ @table.map{ |key, vector, score| [key, vector] } ]
36
+ end
37
+ def scores
38
+ Hash[ @table.map{ |key, vector, score| [key, score] } ]
39
+ end
40
+
41
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "pcbr"
3
+ spec.version = (require_relative "lib/pcbr"; PCBR::VERSION)
4
+ spec.author = "Victor Maslov"
5
+ spec.email = "nakilon@gmail.com"
6
+ spec.summary = "Pair Comparision Based Rating"
7
+ spec.description = "not public yet"
8
+ spec.homepage = "https://github.com/Nakilon/pcbr"
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files -z`.split("\x0")
12
+ spec.test_files = ["spec/"]
13
+
14
+ spec.add_development_dependency "bundler", "~> 1.12.0"
15
+ spec.add_development_dependency "rspec", "~> 3.3.0"
16
+
17
+ spec.required_ruby_version = ">= 2.0.0"
18
+ end
@@ -0,0 +1,55 @@
1
+ require_relative "../lib/pcbr"
2
+
3
+ describe PCBR do
4
+
5
+ example "#size" do
6
+ rating = PCBR.new
7
+ rating.store 1
8
+ rating.store 2
9
+ expect(rating.size).to eq(2)
10
+ end
11
+
12
+ example "order, #score[key] and main methods" do
13
+ rating = PCBR.new
14
+ data = {
15
+ 1 => [1, 1],
16
+ 2 => [2, 2],
17
+ 3 => [0, 0],
18
+ 4 => [1, 2],
19
+ 6 => [1, 1],
20
+ 5 => [0, 2],
21
+ }.each do |key, vector|
22
+ rating.store key, vector
23
+ end
24
+ expectation = {
25
+ 3 => -5,
26
+ 1 => -1,
27
+ 6 => -1,
28
+ 5 => -1,
29
+ 4 => 3,
30
+ 2 => 5,
31
+ }.each do |item, score|
32
+ expect(rating.score(item)).to eq(score)
33
+ end
34
+ expect(rating.sorted).to eq(expectation.keys)
35
+ expect(rating.scores).to eq(expectation )
36
+ expect(rating.data ).to eq(data )
37
+ end
38
+
39
+ example "&block" do
40
+ rating = PCBR.new do |item|
41
+ [item[:goodness], -item[:badness]]
42
+ end
43
+ rating.store 1, {goodness: 1, badness: 1}
44
+ rating.store 2, {goodness: 1, badness: 2}
45
+ expect(rating.sorted).to eq([2, 1])
46
+ end
47
+
48
+ example "scalar key without vector and without &block" do
49
+ rating = PCBR.new
50
+ rating.store 2
51
+ rating.store 1
52
+ expect(rating.sorted).to eq([1, 2])
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pcbr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Victor Maslov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 1.12.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 1.12.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.3.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 3.3.0
41
+ description: not public yet
42
+ email: nakilon@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - .rspec
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - lib/pcbr.rb
52
+ - pcbr.gemspec
53
+ - spec/_spec.rb
54
+ homepage: https://github.com/Nakilon/pcbr
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 2.0.0
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.0.14
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Pair Comparision Based Rating
78
+ test_files: []