samer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/bin/samer +4 -0
- data/lib/data/users.yml +38 -0
- data/lib/samer.rb +12 -0
- data/lib/samer/data_provider.rb +17 -0
- data/lib/samer/engine.rb +37 -0
- data/lib/samer/similar_user.rb +9 -0
- data/lib/samer/user.rb +12 -0
- metadata +51 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZjJhZDQ0M2VmMmZmMjMxNTMyNDQ1NjQ4MThmYzEwYTM1Y2Q5NmY3Mg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDJlMmJmNWQwMDFkOGRhNDg3YjQ2YjZmZDVlNzA1ZThkNzkyMDYwZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjEzNzllODU5ZDA4NTA2ZTVmNDc4NGM2MzYwNjM4NDc3NGNlOWU5Mjk2MTk0
|
10
|
+
NTUyM2ZkMDI3ZWNhY2RmNTY5ZDFhN2NjYmRhNzcwMjY3ZWJhYjAxNWUwNTIw
|
11
|
+
OWMwMDliODI1MGI2NDU1ODZmZjQ1YmJhZDgyNTg4NzMyZjljNTY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MmUyNjE4NzI3OGQ4YjllNTAwZGQ0NzhiOWQ1ODBkMTNlYzAzMWZmZWExN2Iy
|
14
|
+
OTdkOTMwZTQyODhjMjAwYzllNzhhY2UwOTQ1NDBmZjRmN2Q0NjUwZGRkOTBl
|
15
|
+
ZTQyZTJhN2NhZTc3ODhmNTA3MzVhMjU2NTg2MmE2NzA3YTFkMjM=
|
data/bin/samer
ADDED
data/lib/data/users.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Electronic music
|
2
|
+
john:
|
3
|
+
'trance': 5
|
4
|
+
'ambient': 4
|
5
|
+
'chillout': 4
|
6
|
+
'rock': 3
|
7
|
+
'pop': 1
|
8
|
+
'heavy-metal': 1
|
9
|
+
# Pop, ballad
|
10
|
+
jane:
|
11
|
+
'trance': 1
|
12
|
+
'ambient': 2
|
13
|
+
'chillout': 3
|
14
|
+
'ballad': 4
|
15
|
+
'pop': 5
|
16
|
+
# Rock
|
17
|
+
jake:
|
18
|
+
'rock': 5
|
19
|
+
'heavy-metal': 4
|
20
|
+
'pop': 1
|
21
|
+
'ballad': 2
|
22
|
+
'trance': 1
|
23
|
+
# Pop, ballad
|
24
|
+
jasmine:
|
25
|
+
'pop': 5
|
26
|
+
'ballad': 4
|
27
|
+
'heavy-metal': 1
|
28
|
+
'rock': 2
|
29
|
+
'trance': 1
|
30
|
+
'ambient': 2
|
31
|
+
# Chillout, ambient, ballad
|
32
|
+
johanna:
|
33
|
+
'ambient': 5
|
34
|
+
'ballad': 3
|
35
|
+
'chillout': 4
|
36
|
+
'pop': 2
|
37
|
+
'rock': 2
|
38
|
+
'heavy-metal': 0
|
data/lib/samer.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'samer/user'
|
2
|
+
|
3
|
+
module Samer
|
4
|
+
class DataProvider
|
5
|
+
|
6
|
+
DATA_PATH = File.expand_path '../../data/users.yml', __FILE__
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@data = YAML.load_file DATA_PATH
|
10
|
+
end
|
11
|
+
|
12
|
+
def prepare
|
13
|
+
@data.keys.map!{ |name| User.new name, @data[name] }
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
data/lib/samer/engine.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# require 'samer/similar_user'
|
2
|
+
|
3
|
+
module Samer
|
4
|
+
class Engine
|
5
|
+
|
6
|
+
def initialize users
|
7
|
+
@users = users
|
8
|
+
end
|
9
|
+
|
10
|
+
def find_for name
|
11
|
+
similar = {}
|
12
|
+
current_user = @users.find{ |user| user.name == name }
|
13
|
+
|
14
|
+
@users.each do |user|
|
15
|
+
next if user.name == current_user.name
|
16
|
+
similar[user.name] = distance(current_user, user)
|
17
|
+
end
|
18
|
+
|
19
|
+
similar.max_by{ |_, score| score }
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def distance current_user, user
|
26
|
+
distances = []
|
27
|
+
|
28
|
+
current_user.music.keys.each do |genre|
|
29
|
+
next unless user.music[genre]
|
30
|
+
distances.push (current_user.music[genre] - user.music[genre]) ** 2
|
31
|
+
end
|
32
|
+
|
33
|
+
1.fdiv 1 + Math.sqrt(distances.inject(0){ |sum, score| sum + score })
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/samer/user.rb
ADDED
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: samer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evgeniy Fateev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem that finds similar person to you by comparing music ratings
|
14
|
+
email: spaceflow@gmail.com
|
15
|
+
executables:
|
16
|
+
- samer
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/samer
|
21
|
+
- lib/data/users.yml
|
22
|
+
- lib/samer.rb
|
23
|
+
- lib/samer/data_provider.rb
|
24
|
+
- lib/samer/engine.rb
|
25
|
+
- lib/samer/similar_user.rb
|
26
|
+
- lib/samer/user.rb
|
27
|
+
homepage: http://rubygems.org/gems/samer
|
28
|
+
licenses:
|
29
|
+
- MIT
|
30
|
+
metadata: {}
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 2.2.2
|
48
|
+
signing_key:
|
49
|
+
specification_version: 4
|
50
|
+
summary: Find someone like you!
|
51
|
+
test_files: []
|