Created
September 13, 2015 03:23
-
-
Save CamDavidsonPilon/07e83fb67585d53bcb9d to your computer and use it in GitHub Desktop.
This is for the stackechange data api to find the most controversial python answer
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
declare @VoteStats table (parentid int, id int, U float, D float) | |
insert @VoteStats | |
SELECT | |
a.parentid, | |
a.id, | |
CAST(SUM(case when (VoteTypeID = 2) then 1. else 0. end) + 1. as float) as U, | |
CAST(SUM(case when (VoteTypeID = 3) then 1. else 0. end) + 1. as float) as D | |
FROM Posts q | |
JOIN PostTags qt | |
on qt.postid = q.ID | |
JOIN Tags T | |
on T.Id = qt.TagId | |
JOIN Posts a | |
on q.id = a.parentid | |
JOIN Votes | |
ON Votes.PostId = a.Id | |
WHERE TagName = 'python' | |
and a.PostTypeID = 2 -- these are answers | |
Group BY a.id, a.parentid | |
set nocount off | |
SELECT | |
TOP 100 | |
parentid, | |
id, | |
U, D, | |
SQRT(U*D / ((U+D) * (U+D) * (U+D+1))), | |
ABS(0.5 - U/(U+D) - 3.5*SQRT(U*D / ((U+D) * (U+D) * (U+D+1)))) + | |
ABS(0.5 - U/(U+D) + 3.5*SQRT(U*D / ((U+D) * (U+D) * (U+D+1)))) as Score | |
FROM @VoteStats | |
ORDER BY Score |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment