Last active
August 29, 2015 14:02
-
-
Save makaroni4/8974feb2bdc16d2e90e7 to your computer and use it in GitHub Desktop.
Calculating ratings at http://www.lookatme.ru/mag/blogs/contests/204707-konkurs_08
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// скрипт учитывает повторные голосования пользователей и максимум 3 картинки от одного пользователя | |
var numbers = {}; | |
var voted_users = {}; | |
$(".comment").each(function(i, comment) { | |
var user_id = $(comment).find("a[role='comment-user']").attr("href"); | |
console.log(user_id) | |
if(voted_users[user_id] == undefined) { | |
$(comment).find(".comment-text").each(function(i, t) { | |
var r = /\d{3}/g; | |
var text = $(t).text(); | |
var picture_id_counter = 0 | |
while ((m = r.exec(text)) != null && picture_id_counter < 3) { | |
key = m[0] | |
if(numbers[key] == undefined) { | |
numbers[key] = 1; | |
} else { | |
numbers[key] += 1; | |
} | |
picture_id_counter++; | |
} | |
}) | |
voted_users[user_id] = true; | |
} | |
}) | |
var sortable = []; | |
for (var key in numbers) | |
sortable.push([key, numbers[key]]) | |
console.log(JSON.stringify(sortable.sort(function(a, b) {return b[1] - a[1]}))) | |
// [["290",218],["307",181],["320",27],["319",26],["291",16],["288",14],["309",13],["284",10],["318",10],["317",9],["316",9],["311",9],["303",6],["301",4],["281",4],["287",4],["282",4],["308",4],["294",3],["292",3],["313",3],["295",2],["296",2],["314",2],["297",2],["298",2],["370",2],["310",2],["300",2],["286",2],["312",1],["306",1],["304",1],["209",1],["299",1],["293",1],["289",1],["333",1],["351",1],["182",1]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment