Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I thought of this method for estimating the tail:</p> <p>for a list of tags, for each question in these tags give the 1st month after creation_date 80% of View_Count give the 2nd month after creation_date 10% of View_Count split 10% equally between the remaining months until today</p> <p>of course 80%, 10% is just a choice of mine, they can be calculated more precisely based on real data. Also, the second month 10% may be eliminated. All that logic is in the: <code>CASE WHEN diff ...</code> part.</p> <p>you obtain estimated view_count/question/month</p> <p>then all you have to do is sum view_count per month and if you want a window of time add a condition on the month</p> <p>I created a stored procedure that can do this, but you have to create first a temporary table #tags(Tag_name) where you put the desired tags.</p> <pre><code>CREATE PROCEDURE GetTagViews @startDate datetime, @endDate datetime As IF exists (SELECT null FROM sysobjects WHERE name = '#months' and type = 'U') DROP TABLE #MONTHS CREATE TABLE #MONTHS ( month datetime ) DECLARE @currMonth datetime SELECT @currMonth = MIN(Creation_Date) FROM Questions -- Populate #MONTHS with all the months from the oldest -- question creation_date to Today WHILE @currMonth &lt; getdate() BEGIN -- insert date starting at the beginning og the month INSERT INTO #MONTHS select @currMonth - day(@currMonth) + 1 SELECT @currMonth = dateadd(m, 1, @currMonth) -- advance 1 month END SELECT YEAR(month) y, MONTH(month) m, SUM(curr_month_views) Views FROM ( SELECT Q1.month, Q1.diff, round( CASE WHEN diff = dmin and diff = dmax THEN View_Count WHEN diff = dmin and diff &lt; dmax THEN 0.8*View_Count WHEN diff = dmin+1 and diff &lt; dmax THEN 0.1*View_Count WHEN diff = dmin+1 and diff = dmax THEN 0.2*View_Count WHEN diff &gt;= dmin+2 THEN 0.1/(dmax - (dmin+2) + 1)*View_Count ELSE 0 END, 0) curr_month_views FROM ( SELECT Q.question_id, m.month, DATEDIFF(m, Q.Creation_Date, m.month) diff, Q.View_Count, dmin, dmax FROM Questions Q, #MONTHS m, (SELECT MIN(DATEDIFF(m, Q.Creation_Date, m.month)) [dmin], MAX(DATEDIFF(m, Q.Creation_Date, m.month)) [dmax] FROM Questions Q,#MONTHS m WHERE DATEDIFF(m, Q.Creation_Date, m.month) &gt;= 0) MINMAX ) Q1 join QuestionTags QT on Q1.question_id = QT.question_id join #tags on #tags.Tag_Name = QT.Tag_Name ) b WHERE month &gt;= @startDate - day(@startDate) + 1 AND month &lt;= @enddate - day(@enddate) + 1 GROUP BY Year(month), Month(month) ORDER BY 1, 2 </code></pre> <p>If I run this procedure with the following data:</p> <pre><code>Question_Id View_Count Creation_Date tag_name ----------- ----------- ------------------------------ ---------- 0 42 2009-09-10 00:00:00.000 sql 1 326 2008-08-04 00:00:00.000 sql 2 377 2008-08-04 00:00:00.000 sql 3 568 2008-08-03 00:00:00.000 sql 4 839 2008-08-01 00:00:00.000 sql 5 228 2009-03-01 00:00:00.000 sql 6 178 2009-03-11 00:00:00.000 sql 7 348 2009-08-11 00:00:00.000 c# </code></pre> <p>populate #tags with 'sql' </p> <pre><code>GetTagViews '20090501', '20091001' y m Views ----------- ----------- --------------- 2009 5 21.000000000000 2009 6 21.000000000000 2009 7 21.000000000000 2009 8 21.000000000000 2009 9 55.000000000000 </code></pre> <p>populate #tags with 'c#' </p> <pre><code>GetTagViews '20090501', '20091001' y m Views ----------- ----------- ---------------------------------------- 2009 5 .000000000000 2009 6 .000000000000 2009 7 .000000000000 2009 8 278.000000000000 2009 9 35.000000000000 </code></pre> <p>populate #tags with both 'sql' &amp; 'c#' </p> <pre><code>GetTagViews '20090501', '20091001' y m Views ----------- ----------- ---------------- 2009 5 21.000000000000 2009 6 21.000000000000 2009 7 21.000000000000 2009 8 299.000000000000 2009 9 90.000000000000 </code></pre> <p>(you see that peak for (sql, c#) comparing to only (sql) for 2009-08, it's due to the c# question being asked that month.)</p> <p>N.B.: the rouding of estimates my lead to a difference of some views (~1) if you sum up detailed views and compare to the original data for a given question!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload