Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get PlayerLevel rating? #14

Open
ramsestom opened this issue Aug 21, 2015 · 3 comments
Open

get PlayerLevel rating? #14

ramsestom opened this issue Aug 21, 2015 · 3 comments

Comments

@ramsestom
Copy link

Hi Ben

I am currently looking at the server scripts and I have a question regarding playerlevel rating. In the playerslevel.list function, there is an option to sort levels by player ratings that seems to sort levels using a "rating" field:

switch(options.mode) {
case "alltime":
case "popular": // legacy
query.sort = "-rating";
break;
.....

However, levels do not have a rating field (only a ratings one wich is an array) so I do not really understand how it is supposed to work (I am new to mongoDB thouth so maybe there is a subtility I do not understand). Looking at the playerlevels objects structure in mongodb, I would say the alltime rating can only be obtained doing: score/votes

Also, when retrieving player levels with the api, wich field of the returned level object should I look at to get the alltime rating? (is there a rating field return or should I do score/votes?)

Finnaly, I found a bug in the playerlevels.list script. In the rate function, you must change the line

db.PlayerLevel.findOneAndUpdate({_id: doc._id}, doc, { upsert: false }, function(error) {

var docid = doc._id;
delete doc._id;
db.PlayerLevel.findOneAndUpdate({_id: docid}, doc, { upsert: false }, function(error) {

else mongoose return an eror saying: MongoError Mod on _id not allowed

@benlowry
Copy link
Member

Hi Ramse,

The ratings are stored in array that counts each vote for each value:

ratings: [ 
    number of 1* votes,
    number of 2* votes,
    ...
    number of 10* votes
];

Additionally the last 100 individual ratings are stored with its average:

ratingslast100average: ...;
ratingslast100: [ 
    rating of 1,
    rating of 1,
    rating of 5,
    rating of 10,
    ...
];

From that array you can calculate the all time:

var votes = 0, sum = 0;
for(var i=0, len=arr.length; i<len; i++) {
    sum += arr[i] * (i+1);
    votes += arr[i];
}
var average = sum / votes;

You can also access the ratingaverages field in a level which has these properties:

ratingaverage.today
ratingaverage.yesterday
ratingaverage.last7days,
ratingaverage.last30days,
ratingaverage.last90days

Thanks for the report, do you know how to do a pull request? If you don't I'll take care of it but if you've already made the change you can submit it and have it patched straight in.

@ramsestom
Copy link
Author

Hi Ben

Well, I do not have exactly the same structure as you mentionned. Indeed, the ratings array has this structure for me:

"ratings": {
     "2015-7-21": [
       NumberInt(1),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0) 
    ],
     "2015-7-20": [
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(1),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0) 
    ],
     "2015-7-23": [
       NumberInt(0),
       NumberInt(1),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0),
       NumberInt(0) 
    ] 
  },

So it looks like it is storing average votes for each day (I don't know the reason for this, seems pretty useless but there might be a good reason...)

I also have a ratingaverages array but wich is empty...

"ratingaverages": [

],

Also, my question was how did the ordering by rating works as, in the code, the query seems to use a "-rating" sort tag. So, as I understand it, it rely on a "rating" field to do the sorting. But there is no such field in my playerlevel objects (only a ratings field wich is an array of array) so I don't know how it is supposed to work...

Finally, concerning the pull request, I will let you do the change as I already made some personnal changes in the playtomic server source code to suit my own personnal needs.

@EddieOne
Copy link

You can calculate the rating using votes and score. Here's how to get a percentage.

Math.floor(((_data.levels[i].score / _data.levels[i].votes) / 10) * 100)+'% Liked';

I'm not clear exactly the question, if you want a sorted list set the mode property using one of following strings.

newest, last7daysaverage, last30daysaverage, alltime

We have also heavily modified the original, so some of this may be slightly off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants