pcbr 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pcbr.rb +6 -5
  3. data/spec/_spec.rb +38 -29
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e17564130abbbb6ebddcf3a3302c5d1ab617f8a0
4
- data.tar.gz: 6ba30f3821a168a951938aaf6d31671a1b632076
3
+ metadata.gz: 0ffebfcba7efed840c175df7f5bbc937193421a9
4
+ data.tar.gz: acee6ef464ff5ea9a4cbb2c09eb0786c11616b58
5
5
  SHA512:
6
- metadata.gz: ce0bfae1f4db6f52806437cf2821b1e5325e6557de69e119829361c1f354eef205877a7f2a83fa220a31e4bbf777beae8db327f8304defd517d9415a22f7fc3b
7
- data.tar.gz: 259c292b880fa28991baaa4359f3331b8e8683d61656eee4549ee12d62a65612433e936eadf512c1db4d844e0192508812e84f98a7ccda1fefc505d554a74fad
6
+ metadata.gz: 939b2a03b5c31a7ab328b5e06a17400d5b7e04b84aa5bba88c81943fa9bd4370122352975131e19a794a1e1052abe7c02688d340846dc42067361eefb24dc016
7
+ data.tar.gz: 32e71d883437a73ee6e3d5d9f7695b173a3024289e42892c2f020583d971e0a8b87d4ef8a48ca5a44b3f385e996c2d4bdd2a82085df30d73124183e3e586a07b
data/lib/pcbr.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class PCBR
2
2
 
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
 
5
5
  attr_reader :table
6
6
 
@@ -15,23 +15,24 @@ class PCBR
15
15
 
16
16
  def store key, *vector
17
17
  vector = vector.empty? ? [key] : vector.first
18
+ calculated = @callback[vector, key]
18
19
  score = @table.map do |item|
19
- @callback[vector, key].zip(@callback[item[1], item[0]]).map do |a, b|
20
+ calculated.zip(item[3]).map do |a, b|
20
21
  a <=> b
21
22
  end.uniq.inject(0, :+).tap do |point|
22
23
  item[2] -= point
23
24
  end
24
25
  end.inject 0, :+
25
- @table.push [key, vector, score]
26
+ @table.push [key, vector, score, calculated]
26
27
  end
27
28
 
28
29
  def score key
29
- @table.assoc(key).last
30
+ @table.assoc(key)[-2]
30
31
  end
31
32
 
32
33
  def sorted
33
34
  # from the best to the worst
34
- @table.sort_by.with_index{ |item, i| [-item.last, i] }.map(&:first)
35
+ @table.sort_by.with_index{ |item, i| [-item[2], i] }.map(&:first)
35
36
  end
36
37
 
37
38
  end
data/spec/_spec.rb CHANGED
@@ -1,52 +1,61 @@
1
1
  require_relative "../lib/pcbr"
2
2
 
3
+
4
+ require "pp"
5
+
6
+
3
7
  describe "basic specs" do
4
8
 
5
- example "#size", skip: :deprecated do
9
+ example "scalar key without vector and without &block" do
6
10
  rating = PCBR.new
7
11
  rating.store 1
8
12
  rating.store 2
9
- expect(rating.size).to eq(2)
13
+ expect(rating.sorted).to eq([2, 1])
10
14
  end
11
15
 
12
- example "order and methods: #score[key], #sorted, #data" do
16
+ example "#size", skip: :deprecated do
13
17
  rating = PCBR.new
14
- table = [
15
- [1, [1, 1], -1],
16
- [2, [2, 2], 5],
17
- [3, [0, 0], -5],
18
- [4, [1, 2], 3],
19
- [6, [1, 1], -1],
20
- [5, [0, 2], -1],
21
- ].each do |key, vector, |
22
- rating.store key, vector
23
- end
24
- expect(rating.sorted).to eq([2, 4, 1, 6, 5, 3])
25
- expect(rating.table.map(&:last).inject(:+)).to be_zero
26
- table.each do |key, _, score|
27
- expect(rating.score(key)).to eq(score)
28
- end
29
- expect(rating.table ).to eq(table)
18
+ rating.store 1
19
+ rating.store 2
20
+ expect(rating.size).to eq(2)
30
21
  end
31
22
 
32
23
  example "&block" do
24
+ n = 0
33
25
  rating = PCBR.new do |item|
26
+ n += 1
34
27
  [item[:goodness], -item[:badness]]
35
28
  end
29
+ rating.store 3, {goodness: 0, badness: 2}
36
30
  rating.store 2, {goodness: 1, badness: 2}
37
31
  rating.store 1, {goodness: 1, badness: 1}
38
- expect(rating.sorted).to eq([1, 2])
32
+ expect(rating.sorted).to eq([1, 2, 3])
33
+ expect(n).to eq(3)
39
34
  end
40
35
 
41
- example "scalar key without vector and without &block" do
36
+ example "#sorted and #score[key]" do
42
37
  rating = PCBR.new
43
- rating.store 1
44
- rating.store 2
45
- expect(rating.sorted).to eq([2, 1])
38
+ table = [
39
+ [1, [1, 1], -1, [1, 1]],
40
+ [2, [2, 2], 5, [2, 2]],
41
+ [3, [0, 0], -5, [0, 0]],
42
+ [4, [1, 2], 3, [1, 2]],
43
+ [6, [1, 1], -1, [1, 1]],
44
+ [5, [0, 2], -1, [0, 2]],
45
+ ].each do |key, vector, |
46
+ rating.store key, vector
47
+ end
48
+ expect(rating.sorted).to eq([2, 4, 1, 6, 5, 3])
49
+ expect(rating.table.map{ |i| i[2] }.inject(:+)).to be_zero
50
+ table.each do |key, _, score|
51
+ expect(rating.score(key)).to eq(score)
52
+ end
53
+ expect(rating.table).to eq(table)
46
54
  end
47
55
 
48
56
  end
49
57
 
58
+
50
59
  describe "examples" do
51
60
 
52
61
  example "github repos" do
@@ -72,13 +81,13 @@ describe "examples" do
72
81
  # Ruby Version Manager
73
82
  "RVM: rbenv/rbenv" => {issue: 24, pr: 12, watch: 301, star: 8257, fork: 769},
74
83
  "RVM: rvm/rvm" => {issue: 160, pr: 5, watch: 154, star: 3328, fork: 793},
75
- # DevOps Tools
84
+ # DevOps Tool
76
85
  "DOT: ansible/ansible" => {issue: 1074, pr: 322, watch: 1339, star: 16926, fork: 5075},
77
86
  "DOT: chef/chef" => {issue: 422, pr: 52, watch: 387, star: 4265, fork: 1774},
78
87
  "DOT: capistrano/capistrano" => {issue: 38, pr: 6, watch: 339, star: 8392, fork: 1365},
79
88
  }
80
89
 
81
- store_repos_to_rating = lambda do |rating|
90
+ push_repos = lambda do |rating|
82
91
  repos.each do |repo_name, repo_stats|
83
92
  rating.store repo_name, repo_stats
84
93
  end
@@ -87,17 +96,17 @@ describe "examples" do
87
96
  contribution_intensivity_rating = PCBR.new do |repo_stats| [
88
97
  repo_stats[:pr],
89
98
  -repo_stats[:fork],
90
- ] end.tap &store_repos_to_rating
99
+ ] end.tap &push_repos
91
100
 
92
101
  quality_rating = PCBR.new do |repo_stats| [
93
102
  repo_stats[:star],
94
103
  -repo_stats[:issue],
95
- ] end.tap &store_repos_to_rating
104
+ ] end.tap &push_repos
96
105
 
97
106
  resulting_rating = PCBR.new do |_, repo_name| [
98
107
  contribution_intensivity_rating.score(repo_name),
99
108
  quality_rating.score(repo_name),
100
- ] end.tap &store_repos_to_rating
109
+ ] end.tap &push_repos
101
110
 
102
111
  aggregate_failures do
103
112
  expect(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcbr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Maslov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2016-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  version: '0'
73
73
  requirements: []
74
74
  rubyforge_project:
75
- rubygems_version: 2.0.14
75
+ rubygems_version: 2.0.14.1
76
76
  signing_key:
77
77
  specification_version: 4
78
78
  summary: Pair Comparison Based Rating