Site Activity and VoteGraph

53

(click on this box to dismiss)

Plot the site activity by voting, questions, answers and comments, aggregated per week.

Q&A about the site for members of the workforce navigating the professional setting

``````declare @epoch as datetime = DATEADD(WEEK, - ##Weeks:int?60## - 1, CURRENT_TIMESTAMP)
;

with VoteNames as (
select pt.Id as PostTypeId,
vt.Id as VoteTypeId,
case when pt.Id in (1, 2) and vt.Id = 1 then 'AnswerAccept'
when pt.Id = 1 and vt.Id != 1 then 'QuestionVote'
when pt.Id = 2 and vt.Id != 1 then 'AnswerVote'
else 'Unknown'
end as VName
from VoteTypes vt,
PostTypes pt
where vt.Id in (1, 2, 3)
and pt.Id in (1, 2)

) , Activity as (

select DATEADD(DAY, 7 - DATEPART(WEEKDAY, CONVERT(DATE,u.CreationDate)), CONVERT(DATE,u.CreationDate)) as YearMon,
'NewUser' as Series,
count(*) as Action
from Users u
where u.CreationDate > @epoch
group by DATEADD(DAY, 7 - DATEPART(WEEKDAY, CONVERT(DATE,u.CreationDate)), CONVERT(DATE,u.CreationDate))

UNION

select DATEADD(DAY, 7 - DATEPART(WEEKDAY, v.CreationDate), v.CreationDate) as YearMon,
VName as Series,
count(*) as Action
from Posts p,
VoteNames as vn
where p.Id = v.PostId
and v.VoteTypeId = vn.VoteTypeId
and p.PostTypeId = vn.PostTypeId
and v.VoteTypeId in (1, 2, 3)
and p.PostTypeId in (1, 2)
and v.CreationDate > @epoch
group by DATEADD(DAY, 7 - DATEPART(WEEKDAY, v.CreationDate), v.CreationDate),
VName

UNION

select DATEADD(DAY, 7 - DATEPART(WEEKDAY, CONVERT(DATE,p.CreationDate)), Convert(DATE, p.CreationDate)) as YearMon,
pt.Name as Series,
count(*) as Action
from Posts p, PostTypes pt
where p.PostTypeId = pt.Id
and p.PostTypeId in (1, 2)
and p.CreationDate > @epoch
Group by DATEADD(DAY, 7 - DATEPART(WEEKDAY, CONVERT(DATE,p.CreationDate)), Convert(DATE, p.CreationDate)),
pt.Name

UNION

SELECT DATEADD(DAY, 7 - DATEPART(WEEKDAY, CONVERT(DATE,c.CreationDate)), Convert(DATE, c.CreationDate)) as YearMon,
'Comment' as Series,
count(*) as Action
where c.CreationDate > @epoch
Group by DATEADD(DAY, 7 - DATEPART(WEEKDAY, CONVERT(DATE,c.CreationDate)), Convert(DATE, c.CreationDate))
)
select *
from Activity
pivot (
sum(Action)