Skip to content

Commit 1e6c072

Browse files
committed
Finished key.js
1 parent 0cdc980 commit 1e6c072

4 files changed

Lines changed: 8 additions & 16 deletions

File tree

lib/algorithms.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ const async = require('async'),
44
_ = require('underscore'),
55
Key = require('./key');
66

7-
const CLASSNAME = config.className;
8-
97
// the jaccard coefficient outputs an objective measurement of the similarity between two objects. in this case, two users. the coefficient
108
// is the result of summing the two users likes/dislikes incommon then summing they're likes/dislikes that they disagree on. this sum is
119
// then divided by the number of items they both reviewed.

lib/input.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11

22
const config = require('./config.js'),
33
algo = require('./algorithms.js'),
4-
async = require('async');
5-
6-
const CLASSNAME = config.className;
4+
async = require('async'),
5+
Key = require('./key');
76

87
const updateSequence = function(userId, itemId, options = {}){
98
let updateWilson = true;
@@ -41,12 +40,9 @@ const changeRating = function(userId, itemId, options){
4140

4241
const removeRating = options['removeRating'] ? true : false;
4342

44-
const feeling = options['liked'] ? 'liked' : 'disliked';
45-
const mostFeeling = options['liked'] ? 'mostLiked' : 'mostDisliked';
46-
47-
const feelingItemSet = [CLASSNAME, 'item', itemId, feeling].join(':');
48-
const feelingUserSet = [CLASSNAME, 'user', userId, feeling].join(':');
49-
const mostFeelingSet = [CLASSNAME, mostFeeling].join(':');
43+
const feelingItemSet = options['liked'] ? Key.itemLikedBySet(itemId) : Key.itemDislikedBySet(itemId);
44+
const feelingUserSet = options['liked'] ? Key.userLikedSet(userId) : Key.userDislikedSet(userId);
45+
const mostFeelingSet = options['liked'] ? Key.mostLiked() : Key.mostDisliked();
5046

5147
return new Promise((resolve, reject) => {
5248
Promise.resolve().then(() => {

lib/key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Key {
4242
}
4343

4444
mostDisliked() {
45-
this.KeyArr = ['mostDisliked'];
45+
this.keyArr = ['mostDisliked'];
4646
return this.joinKey();
4747
}
4848

lib/stat.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const config = require('./config.js'),
33
client = require('./client.js'),
44
Key = require('./key');
55

6-
const CLASSNAME = config.className;
7-
86
const stat = {
97
recommendFor: function(userId, numberOfRecs){
108
return new Promise((resolve, reject) => {
@@ -36,14 +34,14 @@ const stat = {
3634
},
3735
mostLiked: function(){
3836
return new Promise((resolve, reject) => {
39-
client.zrevrangeAsync([CLASSNAME, 'mostLiked'].join(":"), 0, -1).then((results) => {
37+
client.zrevrangeAsync(Key.mostLiked(), 0, -1).then((results) => {
4038
resolve(results);
4139
});
4240
});
4341
},
4442
mostDisliked: function(){
4543
return new Promise((resolve, reject) => {
46-
client.zrevrangeAsync([CLASSNAME, 'mostDisliked'].join(":"), 0, -1).then((results) => {
44+
client.zrevrangeAsync(Key.mostDisliked(), 0, -1).then((results) => {
4745
resolve(results);
4846
});
4947
});

0 commit comments

Comments
 (0)