ranking

How are Reddit and Hacker News ranking algorithms used?

倾然丶 夕夏残阳落幕 提交于 2019-12-20 08:05:04
问题 I've been looking at ranking algorithms recently, specifically those used by Reddit and Hacker News. The algorithms themselves are simple enough, but I don't quite understand how they are used. One thing that I could do is implement the algorithm straight in SQL, so that every time a user goes to a page displaying ranked posts, something like this would run: SELECT thing1, thing2 FROM table ORDER BY ranking_algorithm DESC LIMIT page*20, 20 There are several similar questions on SO, but the

Simple MySQL Update Rank with Ties

做~自己de王妃 提交于 2019-12-19 04:34:07
问题 I am attempting to store the rank of users based on a score, all it one table, and skipping ranks when there is a tie. For example: ID Score Rank 2 23 1 4 17 2 1 17 2 5 10 4 3 2 5 Each time a user's score is updated, The rank for the entire table must also be updated, so after a score update, the following query is run: SET @rank=0; UPDATE users SET rank= @rank:= (@rank+1) ORDER BY score DESC; But this doesn't support ties, or skipping rank numbers after ties, for that matter. I want to

MySQL Rank with ties

柔情痞子 提交于 2019-12-18 04:53:30
问题 I am new to sql and I have never used variables or conditions in mysql, but know that from other programming languages. Since a few days I try to find a way to rank a user score. I read a lot of articles, and also questions that asked on stackoverflow and finally I found a solution that nearly does it like I want it. SELECT score_users.uid, score_users.score, @prev := @curr, @curr := score, @rank := IF(@prev = @curr, @rank, @rank +1) AS rank FROM score_users, (SELECT @curr := null, @prev :=

How to remove duplicate search result in elasticsearch?

夙愿已清 提交于 2019-12-18 03:37:42
问题 First Create some example data (e1,e2,e3 are types and test is the index name): PUT test/e1/1 { "id":1 "subject": "subject 1" } PUT test/e2/1 { "id":1 "subject": "subject 2" } PUT test/e3/2 { "id":2 "subject": "subject 3" } Now my question is: how can I get just these two data? remove duplicate data with the same id in the curl -XGET _search result. test/e1/1 { "id":1 "subject": "subject 1" } test/e3/2 { "id":2 "subject": "subject 3" } 回答1: First you will need to search across multiple index.

Wikidata results sorted by something similar to a PageRank

半世苍凉 提交于 2019-12-17 16:36:06
问题 In Wikidata (Wikidata SPARQL endpoint), is there a way to order the SPARQL query results with something like a PageRank? SELECT DISTINCT ?entity ?entityLabel WHERE { ?entity wdt:P31 wd:Q5. SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } } LIMIT 100 OFFSET 0 Can we specify a field to order the results by and that field expresses that the entity at the top is more notable/important/recognizable that the following one and so on? 回答1: It seems that PageRank does not make much

Efficient method to calculate the rank vector of a list in Python

血红的双手。 提交于 2019-12-17 10:46:08
问题 I'm looking for an efficient way to calculate the rank vector of a list in Python, similar to R's rank function. In a simple list with no ties between the elements, element i of the rank vector of a list l should be x if and only if l[i] is the x -th element in the sorted list. This is simple so far, the following code snippet does the trick: def rank_simple(vector): return sorted(range(len(vector)), key=vector.__getitem__) Things get complicated, however, if the original list has ties (i.e.

permutation ranking with DI sequence

爷,独闯天下 提交于 2019-12-13 20:27:39
问题 I want to rank and unrank through a subset of permutations given by length. The subset is definded as follows: Example for permutation length 4: We have the Input the Bitstring length 3 (always permutation length - 1) 010 0 means 2 consecutive elements are I ncreasing. 1 means 2 consecutive elements are D ecreasing. For this Bitstring exist the subset with following permutations: 1324 , 1423 , 2314 , 2413 , 3412 The bitstring defined subset of permutations i want to rank and unrank? Is there

Extracting the corresponding value of a rank vector in Matlab

青春壹個敷衍的年華 提交于 2019-12-13 09:37:50
问题 I intend to assign ranks to indices of an array (not the array itself) and create a second vector containing these ranks. Example: data: x=[ 3 7 2 0 5 2] ranks: x'=[ 3 5 2 1 4 2] After assigning the ranks to the indices, I need to extract the corresponding value of the kth (starting from 1) minimum index in each iteration of a loop, until a certain condition satisfies. For example, I need the corresponding value of the first minimum index in the first iteration, meaning the corresponding

Calculate the number of consecutive daily sessions a user has in MySQL

只愿长相守 提交于 2019-12-13 07:57:39
问题 How do I calculate the number of sessions a user has which are 1 day apart from each other? This is what I have so far. The answer should be 46, but this code returns just the last ranked record and the difference between it and the very first record. I'd like to get the number 46 as the correct output. set @pk1 =''; set @rn1 = 1; set @days = ''; select c.user_id, c.day_session, datediff(d.day_session, c.day_session) from (select user_id, day_session, rank FROM (select user_id, day_session,

calculate rank of the user

给你一囗甜甜゛ 提交于 2019-12-13 05:02:09
问题 I want to calculate rank using MySQL. I have a table called result result_id test_id exam_id user_id percentage 1 5 6 50 57 2 5 6 58 76 3 5 6 65 42 I want to calculate the rank of the user according to his user_id and test_id like user_id(58) has 1 rank user_id(50) has 2 and so on I tried query like select percentage from result where test_id=$test_id(i.e 5) and user_id=$user_id(i.e 58) but it gives 76 and doesn't give the rank I also tried select percentage from result where test_id=$test_id