coletivo 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,8 @@ module Coletivo
6
6
 
7
7
  validates :person, :rateable, :weight, :presence => true
8
8
 
9
- def self.find_for_recommendation(recommendable)
10
- find(:all)
9
+ def self.find_for_recommendation(person, rateable_type)
10
+ where(:rateable_type => rateable_type.to_s)
11
11
  end
12
12
  end
13
13
  end
@@ -9,7 +9,7 @@ module Coletivo
9
9
  module ClassMethods
10
10
  def find_recommendations_for(model, options = {})
11
11
  sim_totals, weighted_means = {}, {}
12
- preferences = options[:preferences] ||
12
+ preferences = options[:preferences] ||=
13
13
  load_preferences_for_recommendation(model)
14
14
 
15
15
  preferences.each do |other, other_prefs|
@@ -41,11 +41,6 @@ module Coletivo
41
41
  .compact
42
42
  end
43
43
 
44
- def find_ratings_for_recommendation(recommendable)
45
- Coletivo::Config.ratings_container\
46
- .find_for_recommendation(recommendable)
47
- end
48
-
49
44
  # Map a preferences Hash by a collection of ratings.
50
45
  #
51
46
  # Rating objects have a +person+, a +rateable+ object and a +weight+.
@@ -64,21 +59,23 @@ module Coletivo
64
59
  #
65
60
  # Expected keys are :person or :rateable
66
61
  def map_ratings_to_preferences(ratings)
67
- #TODO: ?? #preferences_by_ratings(:rateable, :person): Item based rec.
68
- key, subkey = :person, :rateable
62
+ #TODO: (???) Item based mapping.
63
+ key, subkey = :person_id, :rateable_id
69
64
  preferences = {}
70
65
 
71
66
  ratings.each do |rating|
72
- p = preferences[rating.send(key).id] ||= {}
73
- p[rating.send(subkey).id] = rating.weight
67
+ p = preferences[rating.send(key)] ||= {}
68
+ p[rating.send(subkey)] = rating.weight
74
69
  end
75
70
 
76
71
  preferences
77
72
  end
78
73
 
79
74
  def load_preferences_for_recommendation(model)
80
- r = model.class.find_ratings_for_recommendation(model)
81
- model.class.map_ratings_to_preferences(r)
75
+ r = Coletivo::Config.ratings_container\
76
+ .find_for_recommendation(model, self)
77
+
78
+ map_ratings_to_preferences(r)
82
79
  end
83
80
  end
84
81
 
@@ -11,6 +11,8 @@ class CreatePersonRatings < ActiveRecord::Migration
11
11
 
12
12
  t.timestamps
13
13
  end
14
+
15
+ add_index :person_ratings, :rateable_type, :unique => false
14
16
  end
15
17
 
16
18
  def self.down
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coletivo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 0
10
- version: 0.0.0
9
+ - 1
10
+ version: 0.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Di\xC3\xB3genes Falc\xC3\xA3o"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-08 00:00:00 -03:00
18
+ date: 2011-07-20 00:00:00 -03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency