Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ raccoon.undisliked('userId', 'itemId').then(() => {
// similar to unliked. removes the negative disliked rating as if it was never rated.
```

#### Reports:
``` js
raccoon.reported('userId', 'itemId').then(() => {
});
// after a user report an item, the report record is immediately
// stored in Redis in various sets for the user/item.
```

#### Shared:
``` js
raccoon.shared('userId', 'itemId').then(() => {
});
// after a user shared an item, the shared record is immediately
// stored in Redis in various sets for the user/item.
```

### Recommendations

``` js
Expand Down Expand Up @@ -190,6 +206,16 @@ raccoon.mostDisliked().then((results) => {
// same as mostLiked but the opposite.
});

raccoon.mostReported().then((results) => {
// returns an array of the 'mostReported' sorted set which represents the global
// number of reports for all the items.
});

raccoon.mostShared().then((results) => {
// returns an array of the 'mostShared' sorted set which represents the global
// number of shares for all the items.
});

raccoon.likedBy('itemId').then((results) => {
// returns an array which lists all the users who liked that item.
});
Expand All @@ -206,6 +232,22 @@ raccoon.dislikedCount('itemId').then((results) => {
// same as likedCount but for disliked.
});

raccoon.reportedBy('itemId').then((results) => {
// returns an array which lists all the users who reported that item.
});

raccoon.reportedCount('itemId').then((results) => {
// returns the number of users who have reported that item.
});

raccoon.sharedBy('itemId').then((results) => {
// returns an array which lists all the users who shared that item.
});

raccoon.sharedCount('itemId').then((results) => {
// returns the number of users who have shared that item.
});

raccoon.allLikedFor('userId').then((results) => {
// returns an array of all the items that user has liked.
});
Expand All @@ -214,6 +256,14 @@ raccoon.allDislikedFor('userId').then((results) => {
// returns an array of all the items that user has disliked.
});

raccoon.allReportsFor('userId').then((results) => {
// returns an array of all the items that user has reported.
});

raccoon.allSharesFor('userId').then((results) => {
// returns an array of all the items that user has shared.
});

raccoon.allWatchedFor('userId').then((results) => {
// returns an array of all the items that user has liked or disliked.
});
Expand Down
43 changes: 38 additions & 5 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,30 @@ const changeRating = function(userId, itemId, options){

const removeRating = options.removeRating ? true : false;

const feelingItemSet = options.liked ? Key.itemLikedBySet(itemId) : Key.itemDislikedBySet(itemId);
const feelingUserSet = options.liked ? Key.userLikedSet(userId) : Key.userDislikedSet(userId);
const mostFeelingSet = options.liked ? Key.mostLiked() : Key.mostDisliked();
let feelingItemSet, feelingUserSet, mostFeelingSet;

if (options.liked) {
feelingItemSet = Key.itemLikedBySet(itemId);
feelingUserSet = Key.userLikedSet(userId);
mostFeelingSet = Key.mostLiked();
}
else if (options.disliked) {
feelingItemSet = Key.itemDislikedBySet(itemId);
feelingUserSet = Key.userDislikedSet(userId);
mostFeelingSet = Key.mostDisliked();
}
else if (options.reported) {
feelingItemSet = Key.itemReportedBySet(itemId);
feelingUserSet = Key.userReportedSet(userId);
mostFeelingSet = Key.mostReported();
updateRecommendations = false;
}
else if (options.shared) {
feelingItemSet = Key.itemSharedBySet(itemId);
feelingUserSet = Key.userSharedSet(userId);
mostFeelingSet = Key.mostShared();
updateRecommendations = false;
}

return new Promise((resolve, reject) => {
Promise.resolve().then(() => {
Expand Down Expand Up @@ -82,7 +103,7 @@ const liked = function(userId, itemId, options = {}){
};

const disliked = function(userId, itemId, options = {}){
options.liked = false;
options.disliked = true;
return changeRating(userId, itemId, options);
};

Expand All @@ -93,16 +114,28 @@ const unliked = function(userId, itemId, options = {}){
};

const undisliked = function(userId, itemId, options = {}){
options.liked = false;
options.disliked = true;
options.removeRating = true;
return changeRating(userId, itemId, options);
};

const reported = function(userId, itemId, options = {}){
options.reported = true;
return changeRating(userId, itemId, options);
};

const shared = function(userId, itemId, options = {}){
options.shared = true;
return changeRating(userId, itemId, options);
};

const input = {
liked,
disliked,
unliked,
undisliked,
reported,
shared,
updateSequence
};

Expand Down
30 changes: 30 additions & 0 deletions lib/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ class Key {
return this.joinKey();
}

userReportedSet(userId) {
this.keyArr = [USER, userId, 'reported'];
return this.joinKey();
}

userSharedSet(userId) {
this.keyArr = [USER, userId, 'shared'];
return this.joinKey();
}

itemLikedBySet(itemId) {
this.keyArr = [ITEM, itemId, 'liked'];
return this.joinKey();
Expand All @@ -36,6 +46,16 @@ class Key {
return this.joinKey();
}

itemReportedBySet(itemId) {
this.keyArr = [ITEM, itemId, 'reported'];
return this.joinKey();
}

itemSharedBySet(itemId) {
this.keyArr = [ITEM, itemId, 'shared'];
return this.joinKey();
}

mostLiked() {
this.keyArr = ['mostLiked'];
return this.joinKey();
Expand All @@ -46,6 +66,16 @@ class Key {
return this.joinKey();
}

mostReported() {
this.keyArr = ['mostReported'];
return this.joinKey();
}

mostShared() {
this.keyArr = ['mostShared'];
return this.joinKey();
}

recommendedZSet(userId) {
this.keyArr = [USER, userId, 'recommendedZSet'];
return this.joinKey();
Expand Down
10 changes: 10 additions & 0 deletions lib/raccoon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const inputProtoMethods = {
disliked,
unliked,
undisliked,
reported,
shared,
updateSequence
} = input;

Expand All @@ -24,15 +26,23 @@ const statProtoMethods = {
bestRatedWithScores,
mostLiked,
mostDisliked,
mostReported,
mostShared,
usersWhoLikedAlsoLiked,
mostSimilarUsers,
leastSimilarUsers,
likedBy,
likedCount,
dislikedBy,
dislikedCount,
reportedBy,
reportedCount,
sharedBy,
sharedCount,
allLikedFor,
allDislikedFor,
allReportedFor,
allSharedFor,
allWatchedFor
} = stat;

Expand Down
62 changes: 59 additions & 3 deletions lib/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@ const stat = {
},
usersWhoLikedAlsoLiked: function(itemId){
},
mostSimilarUsers: function(userId){
mostReported: function(){
return new Promise((resolve, reject) => {
client.zrevrangeAsync(Key.mostReported(), 0, -1).then((results) => {
resolve(results);
});
});
},
mostShared: function(){
return new Promise((resolve, reject) => {
client.zrevrangeAsync(Key.mostShared(), 0, -1).then((results) => {
resolve(results);
});
});
},
mostSimilarUsers: function (userId) {
return new Promise((resolve, reject) => {
client.zrevrangeAsync(Key.similarityZSet(userId), 0, -1).then((results) => {
resolve(results);
Expand Down Expand Up @@ -90,7 +104,35 @@ const stat = {
});
});
},
allLikedFor: function(userId){
reportedBy: function(itemId){
return new Promise((resolve, reject) => {
client.smembersAsync(Key.itemReportedBySet(itemId)).then((results) => {
resolve(results);
});
});
},
reportedCount: function(itemId){
return new Promise((resolve, reject) => {
client.scardAsync(Key.itemReportedBySet(itemId)).then((results) => {
resolve(results);
});
});
},
sharedBy: function(itemId){
return new Promise((resolve, reject) => {
client.smembersAsync(Key.itemSharedBySet(itemId)).then((results) => {
resolve(results);
});
});
},
sharedCount: function(itemId){
return new Promise((resolve, reject) => {
client.scardAsync(Key.itemSharedBySet(itemId)).then((results) => {
resolve(results);
});
});
},
allLikedFor: function (userId) {
return new Promise((resolve, reject) => {
client.smembersAsync(Key.userLikedSet(userId)).then((results) => {
resolve(results);
Expand All @@ -104,7 +146,21 @@ const stat = {
});
});
},
allWatchedFor: function(userId){
allReportedFor: function(userId){
return new Promise((resolve, reject) => {
client.smembersAsync(Key.userReportedSet(userId)).then((results) => {
resolve(results);
});
});
},
allSharedFor: function(userId){
return new Promise((resolve, reject) => {
client.smembersAsync(Key.userSharedSet(userId)).then((results) => {
resolve(results);
});
});
},
allWatchedFor: function (userId) {
return new Promise((resolve, reject) => {
client.sunionAsync(Key.userLikedSet(userId), Key.userDislikedSet(userId)).then((results) => {
resolve(results);
Expand Down