recommendationforuser 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/recommendation.rb +5 -27
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee50d4f49684af08e0bf7f4aa9dbd713bb03a344443df4d201e3df4c0e91c5e5
4
- data.tar.gz: 233185efc750675c1fc82cc5c5cb6c50ee1486b1d52859cc57b7165d8b215730
3
+ metadata.gz: a9a1e268add5b2f928ae5917d74829664727e112ee236aa1363a6ac9e3d5ba9d
4
+ data.tar.gz: 0baf7961265c94fe326e420d3fad4dcbf7dde75352863fa76cb6e40c222ea224
5
5
  SHA512:
6
- metadata.gz: 8de48903e9c2a90826a59a17b6453ffaafa4702c7235c638584d1b77ccbfaab91b3df5d52b08053226ea66b8bcd5da5c12528a7317d189c7204df4cfd3482a96
7
- data.tar.gz: ede1df565955fe638c63aefd358548ba91aa8db6a563e80840feeebc6e370afd084bc91ed0243a5d813afc7fef7766b29cfaa2c0f17f9b806694c98f81fefee9
6
+ metadata.gz: 56f12967e22bcc45966ada795acd4e7f494d5b370a6f23889d59b820c1b1eb391dcc93d9433d21ba3e1a56dc13f12fa42fe15836002d2629aefaf05e7d3d8625
7
+ data.tar.gz: 3b64bb3d59b2f85e4548734556a4594c61d3bae3189409d8f9abedb5d74d12ca6b264bbe3c7d74eba229f2341fef1b7241de305e76fc32ea715ad245d8af4dde
@@ -1,65 +1,43 @@
1
1
  module Recommendation
2
2
 
3
- def recommend_hotels # recommend hotels to a user
4
- # find all other users, equivalent to .where(‘id != ?’, self.id)
3
+ def recommend_hotels # recommend hotels to a user based on the similarity with other user
4
+
5
5
  other_users = self.class.all.where.not(id: self.id)
6
- # instantiate a new hash, set default value for any keys to 0
7
6
  recommended = Hash.new(0)
8
- # for each user of all other users
9
7
  other_users.each do |user|
10
- # find the hotels this user and another user both liked
11
8
  common_hotels = user.hotels & self.hotels
12
- # calculate the weight (recommendation rating)
13
9
  weight = common_hotels.size.to_f / user.hotels.size
14
- # add the extra hotels the other user liked
15
10
  ((user.hotels) - (common_hotels)).each do |hotel|
16
- # put the hotel along with the cumulative weight into hash
17
11
  recommended[hotel] += weight
18
12
  end
19
13
  end
20
- # sort by weight in descending order
21
14
  sorted_recommended = recommended.sort_by { |key, value| value }.reverse
22
15
  end
23
16
 
24
- def recommend_restaurants # recommend movies to a user
25
- # find all other users, equivalent to .where(‘id != ?’, self.id)
17
+ def recommend_restaurants # recommend restaurant to a user based on the similarity with other user
26
18
  other_users = self.class.all.where.not(id: self.id)
27
- # instantiate a new hash, set default value for any keys to 0
28
19
  recommended = Hash.new(0)
29
- # for each user of all other users
30
20
  other_users.each do |user|
31
- # find the restaurants this user and another user both liked
32
21
  common_restaurants = user.restaurants & self.restaurants
33
- # calculate the weight (recommendation rating)
34
22
  weight = common_restaurants.size.to_f / user.restaurants.size
35
- # add the extra restaurants the other user liked
36
23
  ((user.restaurants) - (common_restaurants)).each do |restaurant|
37
- # put the restaurant along with the cumulative weight into hash
38
24
  recommended[restaurant] += weight
39
25
  end
40
26
  end
41
- # sort by weight in descending order
42
27
  sorted_recommended = recommended.sort_by { |key, value| value }.reverse
43
28
  end
44
29
 
45
- def recommend_transports # recommend hotels to a user
46
- # find all other users, equivalent to .where(‘id != ?’, self.id)
30
+ def recommend_transports # recommend transports to a user based on the similarity with other user
31
+
47
32
  other_users = self.class.all.where.not(id: self.id)
48
- # instantiate a new hash, set default value for any keys to 0
49
33
  recommended = Hash.new(0)
50
- # for each user of all other users
51
34
  other_users.each do |user|
52
- # find the transports this user and another user both liked
53
35
  common_transports = user.transports & self.transports
54
- # calculate the weight (recommendation rating)
55
36
  weight = common_transports.size.to_f / user.transports.size
56
- # add the extra transports the other user liked
57
37
  ((user.transports) - (common_transports)).each do |transport|
58
- # put the transport along with the cumulative weight into hash
59
38
  recommended[transport] += weight
60
39
  end
61
40
  end
62
- # sort by weight in descending order
63
41
  sorted_recommended = recommended.sort_by { |key, value| value }.reverse
64
42
  end
65
43
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recommendationforuser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sarath Ravichandran
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-01 00:00:00.000000000 Z
11
+ date: 2019-12-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Recommendation.
14
14
  email: sarath.ravichandran@email.com
@@ -17,7 +17,7 @@ extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
19
  - lib/recommendation.rb
20
- homepage: http://rubygems.org/gems/recommendation
20
+ homepage: http://rubygems.org/gems/recommendationforuser
21
21
  licenses: []
22
22
  metadata: {}
23
23
  post_install_message: