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.
- checksums.yaml +4 -4
- data/lib/recommendation.rb +5 -27
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a9a1e268add5b2f928ae5917d74829664727e112ee236aa1363a6ac9e3d5ba9d
|
|
4
|
+
data.tar.gz: 0baf7961265c94fe326e420d3fad4dcbf7dde75352863fa76cb6e40c222ea224
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56f12967e22bcc45966ada795acd4e7f494d5b370a6f23889d59b820c1b1eb391dcc93d9433d21ba3e1a56dc13f12fa42fe15836002d2629aefaf05e7d3d8625
|
|
7
|
+
data.tar.gz: 3b64bb3d59b2f85e4548734556a4594c61d3bae3189409d8f9abedb5d74d12ca6b264bbe3c7d74eba229f2341fef1b7241de305e76fc32ea715ad245d8af4dde
|
data/lib/recommendation.rb
CHANGED
|
@@ -1,65 +1,43 @@
|
|
|
1
1
|
module Recommendation
|
|
2
2
|
|
|
3
|
-
def recommend_hotels # recommend hotels to a user
|
|
4
|
-
|
|
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
|
|
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
|
|
46
|
-
|
|
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.
|
|
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:
|
|
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/
|
|
20
|
+
homepage: http://rubygems.org/gems/recommendationforuser
|
|
21
21
|
licenses: []
|
|
22
22
|
metadata: {}
|
|
23
23
|
post_install_message:
|