recommendationforuser 1.0.0
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 +7 -0
- data/lib/recommendation.rb +66 -0
- metadata +42 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ee50d4f49684af08e0bf7f4aa9dbd713bb03a344443df4d201e3df4c0e91c5e5
|
|
4
|
+
data.tar.gz: 233185efc750675c1fc82cc5c5cb6c50ee1486b1d52859cc57b7165d8b215730
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8de48903e9c2a90826a59a17b6453ffaafa4702c7235c638584d1b77ccbfaab91b3df5d52b08053226ea66b8bcd5da5c12528a7317d189c7204df4cfd3482a96
|
|
7
|
+
data.tar.gz: ede1df565955fe638c63aefd358548ba91aa8db6a563e80840feeebc6e370afd084bc91ed0243a5d813afc7fef7766b29cfaa2c0f17f9b806694c98f81fefee9
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module Recommendation
|
|
2
|
+
|
|
3
|
+
def recommend_hotels # recommend hotels to a user
|
|
4
|
+
# find all other users, equivalent to .where(‘id != ?’, self.id)
|
|
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
|
+
recommended = Hash.new(0)
|
|
8
|
+
# for each user of all other users
|
|
9
|
+
other_users.each do |user|
|
|
10
|
+
# find the hotels this user and another user both liked
|
|
11
|
+
common_hotels = user.hotels & self.hotels
|
|
12
|
+
# calculate the weight (recommendation rating)
|
|
13
|
+
weight = common_hotels.size.to_f / user.hotels.size
|
|
14
|
+
# add the extra hotels the other user liked
|
|
15
|
+
((user.hotels) - (common_hotels)).each do |hotel|
|
|
16
|
+
# put the hotel along with the cumulative weight into hash
|
|
17
|
+
recommended[hotel] += weight
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
# sort by weight in descending order
|
|
21
|
+
sorted_recommended = recommended.sort_by { |key, value| value }.reverse
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def recommend_restaurants # recommend movies to a user
|
|
25
|
+
# find all other users, equivalent to .where(‘id != ?’, self.id)
|
|
26
|
+
other_users = self.class.all.where.not(id: self.id)
|
|
27
|
+
# instantiate a new hash, set default value for any keys to 0
|
|
28
|
+
recommended = Hash.new(0)
|
|
29
|
+
# for each user of all other users
|
|
30
|
+
other_users.each do |user|
|
|
31
|
+
# find the restaurants this user and another user both liked
|
|
32
|
+
common_restaurants = user.restaurants & self.restaurants
|
|
33
|
+
# calculate the weight (recommendation rating)
|
|
34
|
+
weight = common_restaurants.size.to_f / user.restaurants.size
|
|
35
|
+
# add the extra restaurants the other user liked
|
|
36
|
+
((user.restaurants) - (common_restaurants)).each do |restaurant|
|
|
37
|
+
# put the restaurant along with the cumulative weight into hash
|
|
38
|
+
recommended[restaurant] += weight
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
# sort by weight in descending order
|
|
42
|
+
sorted_recommended = recommended.sort_by { |key, value| value }.reverse
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def recommend_transports # recommend hotels to a user
|
|
46
|
+
# find all other users, equivalent to .where(‘id != ?’, self.id)
|
|
47
|
+
other_users = self.class.all.where.not(id: self.id)
|
|
48
|
+
# instantiate a new hash, set default value for any keys to 0
|
|
49
|
+
recommended = Hash.new(0)
|
|
50
|
+
# for each user of all other users
|
|
51
|
+
other_users.each do |user|
|
|
52
|
+
# find the transports this user and another user both liked
|
|
53
|
+
common_transports = user.transports & self.transports
|
|
54
|
+
# calculate the weight (recommendation rating)
|
|
55
|
+
weight = common_transports.size.to_f / user.transports.size
|
|
56
|
+
# add the extra transports the other user liked
|
|
57
|
+
((user.transports) - (common_transports)).each do |transport|
|
|
58
|
+
# put the transport along with the cumulative weight into hash
|
|
59
|
+
recommended[transport] += weight
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
# sort by weight in descending order
|
|
63
|
+
sorted_recommended = recommended.sort_by { |key, value| value }.reverse
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: recommendationforuser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sarath Ravichandran
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Recommendation.
|
|
14
|
+
email: sarath.ravichandran@email.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/recommendation.rb
|
|
20
|
+
homepage: http://rubygems.org/gems/recommendation
|
|
21
|
+
licenses: []
|
|
22
|
+
metadata: {}
|
|
23
|
+
post_install_message:
|
|
24
|
+
rdoc_options: []
|
|
25
|
+
require_paths:
|
|
26
|
+
- lib
|
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '0'
|
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
requirements: []
|
|
38
|
+
rubygems_version: 3.0.3
|
|
39
|
+
signing_key:
|
|
40
|
+
specification_version: 4
|
|
41
|
+
summary: Recommendation.
|
|
42
|
+
test_files: []
|