Top users by tag score entropy

1

Please login or register to vote for this query.

(click on this box to dismiss)

Poker Meta

Q&A about the site for serious players and enthusiasts of poker

DECLARE @LogFact TABLE (
  N INT NOT NULL,
  LogFact FLOAT NOT NULL,
  PRIMARY KEY(N)
);

DECLARE @n INT = 1
DECLARE @logSum FLOAT = 0

WHILE @n < 100000
BEGIN
  INSERT INTO @LogFact VALUES(@n, @logSum)
  SET @n = @n + 1
  SET @logSum = @logSum + LOG(@n)
END;

WITH TagScores AS (
  SELECT
    Posts.OwnerUserId AS UserId,
    PostTags.TagId,
    SUM(Posts.Score) AS Score
  FROM Posts, PostTags
  WHERE
    Posts.ParentId = PostTags.PostId
    AND
    Posts.OwnerUserId > 0
    AND
    Posts.CommunityOwnedDate IS NULL
  GROUP BY Posts.OwnerUserId, PostTags.TagId
  HAVING SUM(Posts.Score) > 0
),
SumTagScore AS (
  SELECT UserId, SUM(Score) AS Score
  FROM TagScores
  GROUP BY UserId
)
SELECT TOP 100
  SumTagScore.UserId AS [User Link],
  (
    COALESCE(
        MIN(SumTagScoreLF.LogFact),
        LOG(2 * 3.1415927 * MIN(SumTagScore.Score)) / 2
          +
        LOG(1.0 * MIN(SumTagScore.Score) / 2.71728)
          * MIN(SumTagScore.Score)
      )
      - SUM(
        COALESCE(TagScoreLF.LogFact,
          LOG(2.0 * 3.1415927 * TagScores.Score) / 2
          +
          LOG(1.0 * TagScores.Score / 2.71728) * TagScores.Score
        )
      )
    ) / MIN(Users.Reputation)
    AS LogTagEntropyDensity
FROM TagScores
LEFT JOIN SumTagScore ON TagScores.UserId = SumTagScore.UserId
LEFT JOIN @LogFact TagScoreLF ON TagScores.Score = TagScoreLF.N
LEFT JOIN @LogFact SumTagScoreLF ON SumTagScore.Score = SumTagScoreLF.N
LEFT JOIN Users ON SumTagScore.UserId = Users.Id
WHERE
  TagScores.UserId = SumTagScore.UserId
  AND
  Users.Reputation > 1000
GROUP BY SumTagScore.UserId
ORDER BY LogTagEntropyDensity DESC, SumTagScore.UserId

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results