-4

Using this option:

;with postvotes as
(
select v.creationdate
     , p.id postid
     , case v.votetypeid
       when  1 then 'accepts'
       when 2 then 'up-votes'
       when 3 then 'down-votes'
       when 9 then 'bounty_recieved'
       end  vote_type
     , case p.posttypeid
       when 1 then 'question'
       when 2 then 'answer'
       end post_type
     , sum(case  v.votetypeid
           when 1 then 15
           when 2 then 10
           when 3 then -2
           when 9 then bountyamount
           end
       ) reputation_change

from votes v
inner join posts p on p.id = v.postid
where p.owneruserid = ##userid?1719510##
and posttypeid in (1,2)
and votetypeid in (1,2,3,9)
group by v.creationdate, p.id, votetypeid, posttypeid
),
bounties as
(
select v.creationdate
     , v.postid postid
     , 'bounty-offered' vote_type
     , 'question' post_type
     , sum(bountyamount) reputation_change
from votes v
where v.userid = ##userid?1719510##
and votetypeid = 8
group by v.creationdate, v.postid, votetypeid
),
approvededits as
(
select se.creationdate
     , se.postid postid
     , 'approved-edit' vote_type
     , case p.posttypeid
       when 1 then 'question'
       when 2 then 'answer'
       end  post_type
     , sum(2) reputation_change
from suggestededits se
inner join posts p on p.id = se.postid
where se.Owneruserid = ##userid?1719510##
and approvaldate is not null
group by se.creationdate, se.postid, posttypeid
)


select *
from postvotes
union
select *
from bounties
union
select *
from approvededits

What should be added to receive the full detailed reputation?

4
  • 2
    What does it return now?
    – BDL
    Commented Jan 28, 2020 at 11:30
  • 1
    SEDE is refresh once a week. It's up to date only for a really limited amount of time. Commented Jan 28, 2020 at 12:47
  • 3
    This is not a sensible use-case for SEDE. Why not just query the API?
    – Cody Gray Mod
    Commented Jan 28, 2020 at 19:23
  • Isn't there a convention of using uppercase for SQL keywords? Commented Jan 28, 2020 at 23:31

2 Answers 2

8

Getting a fully accurate reputation number via SEDE is not possible. There are events that affect your reputation but do not show up in SEDE, such as:

  1. -1 from downvoting answers
  2. +1 from removing your downvote on an answer, or if that answer is deleted
  3. -2 when a post you have an accepted suggested edit on is deleted
  4. -100 when a post of yours is red-flag deleted
  5. Legacy reputation retained when documentation shut down
  6. Reputation from deleted posts that is retained (Score >3, Visibility >60 Days, thanks Erik A's answer)

That being said, some time ago I wrote a query that calculates any user's reputation up to a certain date (use today for current) with a breakdown. It can be found on SEDE:

SELECT
-- Total Reputation
(
SUM(CASE WHEN r2d.ReputationFromVotes + r2d.ReputationFromSuggestedEdits > 200 THEN 200 ELSE r2d.ReputationFromVotes + r2d.ReputationFromSuggestedEdits END) 
+ SUM(r2d.ReputationFromBounties) 
+ COALESCE((SELECT SUM(v4.BountyAmount * -1) FROM Votes AS v4 WHERE v4.VoteTypeId = 8 AND v4.UserId = ##UserId## AND v4.CreationDate < ##UntilDate:string## ),0)
+ COALESCE((SELECT COUNT(*) * 2 FROM Posts AS p3 WHERE p3.OwnerUserId = ##UserId## AND p3.AcceptedAnswerId IS NOT NULL),0)
+ SUM(r2d.ReputationFromAccepts)
) AS TotalReputation,
-- Rep Capped Activities with the Cap Factored in
SUM(
CASE 
WHEN r2d.ReputationFromVotes + r2d.ReputationFromSuggestedEdits > 200 THEN 200
ELSE r2d.ReputationFromVotes + r2d.ReputationFromSuggestedEdits 
END) AS ReputationFromRepCap,
-- Total Bounties recieved
SUM(r2d.ReputationFromBounties) AS ReputationFromBounties,
-- Total Bounties given
COALESCE((SELECT SUM(v4.BountyAmount * -1) FROM Votes AS v4 WHERE v4.VoteTypeId = 8 AND v4.UserId = ##UserId## AND v4.CreationDate < ##UntilDate:string## ),0) AS ReputationGivenAsBounties,
-- Total Reputation from Accepting Answers
COALESCE((SELECT COUNT(*) * 2 FROM Posts AS p3 WHERE p3.OwnerUserId = ##UserId## AND p3.AcceptedAnswerId IS NOT NULL),0) AS ReputationFromAcceptingAnswers,
-- Total Reputation from Accepted Answers
SUM(r2d.ReputationFromAccepts) AS ReputationFromAcceptedAnswers


FROM

(

SELECT 
v.CreationDate AS VoteDate,

-- Total Reputation from Post Upvotes
-- PostTypeId 1 = Question, 2 = Answer
-- VoteTypeId 2 = Upvote, 3 = Downvote
-- CommunityOwnedDate is when a post was made CW. 
-- Votes before that count, after not.
-- Vote Date is truncated to full days only so grouping works
SUM((CASE 
  WHEN (p.PostTypeId = 1 AND v.VoteTypeId = 2 AND (p.CommunityOwnedDate > v.CreationDate OR p.CommunityOwnedDate IS NULL)) THEN 10 
  WHEN (p.PostTypeId = 2 AND v.VoteTypeId = 2 AND (p.CommunityOwnedDate > v.CreationDate OR p.CommunityOwnedDate IS NULL)) THEN 10 
  WHEN (v.VoteTypeId = 3 AND (p.CommunityOwnedDate > v.CreationDate OR p.CommunityOwnedDate IS NULL)) THEN -2
  ELSE 0 
END)) AS ReputationFromVotes,

-- Total Reputation from Answer Bounties
-- VoteTypeId 9 = Bounty Close (Bounty Awarded)
-- BountyAmount = Amount of Reputation awarded
SUM(CASE 
  WHEN v.VoteTypeId = 9 THEN v.BountyAmount
  ELSE 0
END) AS ReputationFromBounties,

-- Total Reputation from Answer Accepts
-- VoteTypeId 1 = AcceptedByOriginator (Answer Accepted)
SUM(CASE
  WHEN (v.VoteTypeId = 1 AND (p.CommunityOwnedDate > v.CreationDate OR p.CommunityOwnedDate IS NULL)) THEN 15
  ELSE 0 
END) AS ReputationFromAccepts,

-- Total Reputation from Suggested Edits
-- if ApprovalDate isn't NULL and RejectionDate is NULL it's been approved and not overriden
-- Group by the same Date as Votes for Rep-Cap evaluation (They count towards it)
COALESCE((SELECT
SUM(CASE WHEN (se.ApprovalDate IS NOT NULL AND se.RejectionDate IS NULL) THEN 2 ELSE 0 END)
FROM SuggestedEdits AS se
WHERE se.OwnerUserId = ##UserId##
AND YEAR(v.CreationDate) = YEAR(se.ApprovalDate)
AND MONTH(v.CreationDate) = MONTH(se.ApprovalDate)
AND DAY(v.CreationDate) = DAY(se.ApprovalDate) ),0) AS ReputationFromSuggestedEdits

FROM Posts AS p 
INNER JOIN Votes AS v ON v.PostId = p.Id

WHERE p.OwnerUserId =  ##UserId:int##
AND v.CreationDate <= ##UntilDate:string##

GROUP BY v.CreationDate

) as r2d

This query attempts to take into account the rep cap and as many other factors as possible, but it is not fully accurate due to the limitations mentioned above.

3
  • Unless I'm missing something one small improvement to that would be to not count the +15 for an accepted answer if it was a self-answered question.
    – PeterJ
    Commented Jan 28, 2020 at 12:14
  • @PeterJ thats true, it doesn't count those cases. I might take another pass at this later to fix some more stuff, I just dug it out after remembering I wrote something like that once.
    – Magisch
    Commented Jan 28, 2020 at 12:17
  • If you're going to rework it, you might want to exclude the accepted edits by deleted users too.
    – Erik A
    Commented Jan 28, 2020 at 12:19
4

You can't calculate full reputation using SEDE.

Things that are missing because of anonymization:

  • Downvotes you cast on answers (subtract 1 rep)
  • Spam flag penalties against your posts (subtract 100 rep)
  • Deleted posts that stayed around long enough not to revert reputation (score > 3 and visibility for >60 days).

Things that are hard to account for:

  • Lower rep boundary (you can't have less than 1 rep, so some downvotes don't count)
  • Reputation limit per day earned out of votes/edits (200)

Things that are often forgotten:

  • Edits approved by deleted users (these have no effect on rep)
  • Accepted answers on questions by the same user
  • Community wiki questions and answers

You missed all of the items in Things that are often forgotten and things that are hard to account for, plus obviously all items out of things that are missing because of anonymization because these are always missing

Not the answer you're looking for? Browse other questions tagged .