pcbr 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pcbr.rb +17 -13
- data/spec/_spec.rb +25 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2871f614f5c3e9fdf49297ebca1fc97e148eb3e3
|
4
|
+
data.tar.gz: 162ccfbbcaebf10c1e3a762f68ffcbc0b326888d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f24b3e3e90bbde660ecd8c810e17f31cc949eefdb12b9d2b4a88746b9916023f16b6e379bc4f9fe9e7206b6741cdc4d489b07b6d768bb2ad7303973004867c7
|
7
|
+
data.tar.gz: 1702bac320df836e08bb1fef10195fa00b97ccd01a15b795cd8e082f6005c1c8f04233c9891eab78e4b392937fce1c4c73542de90e5f5812b9b4650899080d60
|
data/lib/pcbr.rb
CHANGED
@@ -1,38 +1,42 @@
|
|
1
1
|
class PCBR
|
2
2
|
|
3
|
-
VERSION = "0.
|
3
|
+
VERSION = "0.2.0"
|
4
4
|
|
5
5
|
attr_reader :table
|
6
6
|
|
7
|
+
ARRAY_101 = [0, 0, 0]
|
7
8
|
def initialize &block
|
8
9
|
@table = []
|
9
|
-
@callback = block ||
|
10
|
+
@callback = block || ( lambda do |a_, b_|
|
11
|
+
array = ARRAY_101.dup
|
12
|
+
[*a_].zip([*b_]) do |a, b|
|
13
|
+
next unless t = a <=> b
|
14
|
+
array[t] = t
|
15
|
+
end
|
16
|
+
array.inject :+
|
17
|
+
end )
|
10
18
|
end
|
11
19
|
|
12
20
|
# def size
|
13
21
|
# @table.size
|
14
22
|
# end
|
15
23
|
|
16
|
-
ARRAY_101 = [0, 0, 0]
|
17
24
|
def store key, *vector
|
18
|
-
vector = vector.empty? ?
|
19
|
-
calculated = @callback[vector, key]
|
25
|
+
vector = vector.empty? ? key : vector.first
|
20
26
|
score = 0
|
21
27
|
@table.each do |item|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
point = array.inject :+
|
28
|
+
fail unless [*vector].size == [*item[1]].size
|
29
|
+
|
30
|
+
point = @callback.call vector, item[1]
|
31
|
+
|
28
32
|
score += point
|
29
33
|
item[2] -= point
|
30
34
|
end
|
31
|
-
@table.push [key, vector, score
|
35
|
+
@table.push [key, vector, score]
|
32
36
|
end
|
33
37
|
|
34
38
|
def score key
|
35
|
-
@table.assoc(key)[
|
39
|
+
@table.assoc(key)[2]
|
36
40
|
end
|
37
41
|
|
38
42
|
def sorted
|
data/spec/_spec.rb
CHANGED
@@ -31,26 +31,27 @@ describe "basic specs" do
|
|
31
31
|
|
32
32
|
example "&block" do
|
33
33
|
n = 0
|
34
|
-
rating = PCBR.new do |
|
34
|
+
rating = PCBR.new do |a, b|
|
35
35
|
n += 1
|
36
|
-
|
36
|
+
a <=> b
|
37
37
|
end
|
38
|
-
rating.store
|
39
|
-
rating.store 2
|
40
|
-
rating.store
|
41
|
-
|
42
|
-
expect(
|
38
|
+
rating.store 1
|
39
|
+
rating.store 2
|
40
|
+
rating.store 3
|
41
|
+
rating.store 4
|
42
|
+
expect(rating.sorted).to eq([4, 3, 2, 1])
|
43
|
+
expect(n).to eq(6)
|
43
44
|
end
|
44
45
|
|
45
46
|
example "#sorted and #score[key]" do
|
46
47
|
rating = PCBR.new
|
47
48
|
table = [
|
48
|
-
[1, [1, 1], -1
|
49
|
-
[2, [2, 2], 5
|
50
|
-
[3, [0, 0], -5
|
51
|
-
[4, [1, 2], 3
|
52
|
-
[6, [1, 1], -1
|
53
|
-
[5, [0, 2], -1
|
49
|
+
[1, [1, 1], -1],
|
50
|
+
[2, [2, 2], 5],
|
51
|
+
[3, [0, 0], -5],
|
52
|
+
[4, [1, 2], 3],
|
53
|
+
[6, [1, 1], -1],
|
54
|
+
[5, [0, 2], -1],
|
54
55
|
].each do |key, vector, |
|
55
56
|
rating.store key, vector
|
56
57
|
end
|
@@ -96,26 +97,28 @@ describe "examples" do
|
|
96
97
|
"DOT: capistrano/capistrano" => {issue: 38, pr: 6, watch: 339, star: 8392, fork: 1365},
|
97
98
|
}
|
98
99
|
|
99
|
-
|
100
|
-
|
101
|
-
|
100
|
+
create_rating = lambda do |&callback|
|
101
|
+
PCBR.new.tap do |rating|
|
102
|
+
repos.each do |repo_name, repo_stats|
|
103
|
+
rating.store repo_name, callback[repo_stats, repo_name]
|
104
|
+
end
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
105
|
-
contribution_intensivity_rating =
|
108
|
+
contribution_intensivity_rating = create_rating.call do |repo_stats| [
|
106
109
|
repo_stats[:pr],
|
107
110
|
-repo_stats[:fork],
|
108
|
-
] end
|
111
|
+
] end
|
109
112
|
|
110
|
-
quality_rating =
|
113
|
+
quality_rating = create_rating.call do |repo_stats| [
|
111
114
|
repo_stats[:star],
|
112
115
|
-repo_stats[:issue],
|
113
|
-
] end
|
116
|
+
] end
|
114
117
|
|
115
|
-
resulting_rating =
|
118
|
+
resulting_rating = create_rating.call do |repo_stats, repo_name| [
|
116
119
|
contribution_intensivity_rating.score(repo_name),
|
117
120
|
quality_rating.score(repo_name),
|
118
|
-
] end
|
121
|
+
] end
|
119
122
|
|
120
123
|
aggregate_failures do
|
121
124
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Maslov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|