mysql - Sorting by preferred average value -


i'm making game involves people downloading , rating user-created maps. have option upvote/downvote map if like/dislike it, rate difficult on scale of 1-10.

in map browser, have option sort maps highest rated. done using laplace smoothing factors both number of upvotes total number of ratings sorting, sorting (upvotes + 1)/(numratings + 2). works fine.

now, there's option sort preferred difficulty, people can choose value 1-10, , sort maps how close average difficulty rating preferred rating. @ first sorting abs(preferred_difficulty - average_difficulty), didn't factor in number of ratings. right i'm using ((numratings + 1) * (10 - abs(average_difficulty - preferred_difficulty)) + 1) / (numratings + 1.5) out of sheer trial , error, kinda works, number of ratings outweighs preferred difficulty , results strange.

this need - can't figure out how sort smallest difference between preferred , average difficulty while incorporating number of ratings mix, since want low difficulty delta high rating count best result instead of high upvote count high rating count, ratings.

for example, if data:

avgdifficulty      numratings       6.0                 1       4.0                25       6.8                 4       6.2                 3       6.5                20       6.2                 1       6.4                 3 

and chooses preferred difficulty of 6.4, i'd want sort this:

avgdifficulty      numratings       6.5                20        6.4                 3          6.2                 3       6.8                 4       6.2                 1         6.0                 1       4.0                25   

basically want results close preferred difficulty @ top, i'd rather show results 0.1 off lots of ratings on exact matches few ratings. understand getting "right" results may not concrete in case, i'm looking starting point.

thanks help!

you have bit of nebulous question. need way combine rating , count. basic query is:

order abs(avg_difficulty - 6.4) 

but, want include count well. can define fixed band @ top , order these ranking:

order (case when abs(avg_difficulty - 6.4) < 0.1) numratings end) desc,          abs(avg_difficulty - 6.4) 

this expression combines 6.3 - 6.5 in 1 group , sorts these number of ratings. second key sorts else difference.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -