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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 989bc24051aaf56c2d3d534084d58fd1f25f0fc8
4
- data.tar.gz: 09e99955e26f6bf9d827fd91617f358194015163
3
+ metadata.gz: 6befa005ce3acab7a18f769432d10b623b8e5614
4
+ data.tar.gz: 8f5de518b91f83d56c0e8910e7099a5fac0580f5
5
5
  SHA512:
6
- metadata.gz: 9e832a7ae1793dbad7a0eb86d8c071a3ba3de584f525b73ec7006ce8bf42c0e0cd7f3ff508c6e0e61a05195c987e0d0e4053c7c2eca1ad76b6e340799764346d
7
- data.tar.gz: 1db7014953182b98c79ba49c77a541ab9dea01a57a1e85d86d376dbbb66e569b9f2229c0cbf44c811bbebf99cd9cc6861b84fe0254d5d770464e705fb4d01b41
6
+ metadata.gz: daaa6e1226b4cf3d89b01aa0ff0674fd9aa5b6dcd62e074afb6bd783bb94ae86a63996944e9a96b6d59c82c1dcccff320660bf1bcc89c3191fc878877111e2cf
7
+ data.tar.gz: 0f9a585fae511532461ed0ea3246320190e347cf6c9e369234c74cdbd5c9e7d5f408a4f18e1b9bd5b15681160a4e452ff8db223fcfd0281c481d096c33da851f
data/bin/samer CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'samer'
4
- puts Samer.find_for ARGV[0]
4
+ puts Samer.find_for ARGV[0]
5
+
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
- require 'samer/data_provider'
3
- require 'samer/engine'
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]
@@ -1,4 +1,5 @@
1
- require 'samer/user'
1
+ # require 'samer/user'
2
+ require_relative 'user'
2
3
 
3
4
  module Samer
4
5
  class DataProvider
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
- similar = {}
14
- current_user = @users.find{ |user| user.name == name }
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
- similar[user.name] = distance(current_user, user)
18
+ @similars[user.name] = distance(current_user, user)
20
19
  end
21
20
 
22
- similar.max_by{ |_, score| score }
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.music.keys.each do |genre|
32
- next unless user.music[genre]
33
- distances.push (current_user.music[genre] - user.music[genre]) ** 2
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
@@ -1,11 +1,11 @@
1
1
  module Samer
2
2
  class User
3
3
 
4
- attr_reader :name, :music
4
+ attr_reader :name, :genres
5
5
 
6
- def initialize name, music
6
+ def initialize name, genres
7
7
  @name = name
8
- @music = music
8
+ @genres = genres
9
9
  end
10
10
 
11
11
  end
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.2
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: 2014-07-09 00:00:00.000000000 Z
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 ratings
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.2.2
47
+ rubygems_version: 2.4.6
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: Find someone like you!
@@ -1,9 +0,0 @@
1
- module Samer
2
- class SimilarUser
3
-
4
- def initialize
5
- @similar = {}
6
- end
7
-
8
- end
9
- end