samer 1.0.2 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/samer +2 -1
- data/lib/data/users.yml +4 -0
- data/lib/samer.rb +6 -4
- data/lib/samer/data_provider.rb +2 -1
- data/lib/samer/engine.rb +18 -10
- data/lib/samer/user.rb +3 -3
- metadata +5 -5
- data/lib/samer/similar_user.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6befa005ce3acab7a18f769432d10b623b8e5614
|
4
|
+
data.tar.gz: 8f5de518b91f83d56c0e8910e7099a5fac0580f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daaa6e1226b4cf3d89b01aa0ff0674fd9aa5b6dcd62e074afb6bd783bb94ae86a63996944e9a96b6d59c82c1dcccff320660bf1bcc89c3191fc878877111e2cf
|
7
|
+
data.tar.gz: 0f9a585fae511532461ed0ea3246320190e347cf6c9e369234c74cdbd5c9e7d5f408a4f18e1b9bd5b15681160a4e452ff8db223fcfd0281c481d096c33da851f
|
data/bin/samer
CHANGED
data/lib/data/users.yml
CHANGED
@@ -6,6 +6,7 @@ john:
|
|
6
6
|
'rock': 3
|
7
7
|
'pop': 1
|
8
8
|
'heavy-metal': 1
|
9
|
+
|
9
10
|
# Pop, ballad
|
10
11
|
jane:
|
11
12
|
'trance': 1
|
@@ -13,6 +14,7 @@ jane:
|
|
13
14
|
'chillout': 3
|
14
15
|
'ballad': 4
|
15
16
|
'pop': 5
|
17
|
+
|
16
18
|
# Rock
|
17
19
|
jake:
|
18
20
|
'rock': 5
|
@@ -20,6 +22,7 @@ jake:
|
|
20
22
|
'pop': 1
|
21
23
|
'ballad': 2
|
22
24
|
'trance': 1
|
25
|
+
|
23
26
|
# Pop, ballad
|
24
27
|
jasmine:
|
25
28
|
'pop': 5
|
@@ -28,6 +31,7 @@ jasmine:
|
|
28
31
|
'rock': 2
|
29
32
|
'trance': 1
|
30
33
|
'ambient': 2
|
34
|
+
|
31
35
|
# Chillout, ambient, ballad
|
32
36
|
johanna:
|
33
37
|
'ambient': 5
|
data/lib/samer.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
|
3
|
-
|
2
|
+
require_relative 'samer/data_provider'
|
3
|
+
require_relative 'samer/engine'
|
4
4
|
|
5
5
|
module Samer
|
6
6
|
|
7
7
|
def self.find_for name
|
8
|
-
DataProvider.new
|
9
8
|
@engine ||= Engine.new(DataProvider.new.prepare)
|
10
9
|
@engine.find_for name
|
11
10
|
end
|
12
11
|
|
13
|
-
end
|
12
|
+
end
|
13
|
+
|
14
|
+
#TODO Учитывать нулевые оценки
|
15
|
+
# p Samer.find_for 'jake' # => ['same_user', coefficient]
|
data/lib/samer/data_provider.rb
CHANGED
data/lib/samer/engine.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
# require 'samer/similar_user'
|
2
|
-
|
3
1
|
module Samer
|
4
2
|
class Engine
|
5
3
|
|
@@ -10,16 +8,18 @@ module Samer
|
|
10
8
|
end
|
11
9
|
|
12
10
|
def find_for name
|
13
|
-
|
14
|
-
|
11
|
+
@name = name
|
12
|
+
@similars = {}
|
13
|
+
|
15
14
|
return "User @#{name} is not present in example users list. See it in lib/data/users.yml" unless current_user
|
16
15
|
|
17
16
|
@users.each do |user|
|
18
17
|
next if user.name == current_user.name
|
19
|
-
|
18
|
+
@similars[user.name] = distance(current_user, user)
|
20
19
|
end
|
21
20
|
|
22
|
-
|
21
|
+
@similars
|
22
|
+
# similar
|
23
23
|
end
|
24
24
|
|
25
25
|
|
@@ -28,13 +28,21 @@ module Samer
|
|
28
28
|
def distance current_user, user
|
29
29
|
distances = []
|
30
30
|
|
31
|
-
current_user.
|
32
|
-
next unless user.
|
33
|
-
distances.push (current_user.
|
31
|
+
current_user.genres.keys.each do |genre|
|
32
|
+
next unless user.genres[genre]
|
33
|
+
distances.push (current_user.genres[genre] - user.genres[genre]) ** 2
|
34
34
|
end
|
35
35
|
|
36
36
|
1.fdiv 1 + Math.sqrt(distances.inject(0){ |sum, score| sum + score })
|
37
37
|
end
|
38
38
|
|
39
|
+
def current_user
|
40
|
+
@current_user ||= @users.find{ |user| user.name == @name }
|
41
|
+
end
|
42
|
+
|
43
|
+
def similar
|
44
|
+
@similars.max_by{ |_, score| score }
|
45
|
+
end
|
46
|
+
|
39
47
|
end
|
40
|
-
end
|
48
|
+
end
|
data/lib/samer/user.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: samer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeniy Fateev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: A simple gem that finds similar person to you by comparing music
|
13
|
+
description: A simple gem that finds similar person to you by comparing the music
|
14
|
+
ratings
|
14
15
|
email: spaceflow@gmail.com
|
15
16
|
executables:
|
16
17
|
- samer
|
@@ -22,7 +23,6 @@ files:
|
|
22
23
|
- lib/samer.rb
|
23
24
|
- lib/samer/data_provider.rb
|
24
25
|
- lib/samer/engine.rb
|
25
|
-
- lib/samer/similar_user.rb
|
26
26
|
- lib/samer/user.rb
|
27
27
|
homepage: http://rubygems.org/gems/samer
|
28
28
|
licenses:
|
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
46
|
rubyforge_project:
|
47
|
-
rubygems_version: 2.
|
47
|
+
rubygems_version: 2.4.6
|
48
48
|
signing_key:
|
49
49
|
specification_version: 4
|
50
50
|
summary: Find someone like you!
|