Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Fix for statistics pipline to display proper last 6 weeks data around the new year #712

Merged
merged 5 commits into from
Feb 1, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,30 @@ BEGIN
AND [Year] = @MinYear

DECLARE @Cursor DATETIME = (SELECT ISNULL(MAX([Position]), @ReportGenerationTime) FROM [dbo].[Cursors] (NOLOCK) WHERE [Name] = 'GetDirtyPackageId')

SELECT TOP 6 D.[Year],
DECLARE @MaxDate DATE = DATEADD(DAY, 42, @MinDate);

WITH WeekLookup AS
(
-- Around new year we might have an issue where week start and week end have different
agr marked this conversation as resolved.
Show resolved Hide resolved
-- [WeekOfYear] and [Year] values, which cause same week to be represented twice in
-- the result set. This CTE makes sure that all days within one week have same
-- [WeekOfYear] and [Year] values around new year (taken from the first day of that week).
SELECT d.[Id], dd.[WeekOfYear], dd.[Year]
FROM [dbo].[Dimension_Date] AS d WITH(NOLOCK)
CROSS APPLY
(
SELECT TOP(1) [WeekOfYear], [Year]
FROM [dbo].[Dimension_Date] AS d2 WITH(NOLOCK)
WHERE d2.[Date] <= d.[Date] AND d2.[DayOfWeek] = 1
ORDER BY d2.[Date] DESC
) AS dd
WHERE d.[Date] >= @MinDate AND d.[Date] < @MaxDate AND d.[Date] <= @Cursor
)
SELECT D.[Year],
D.[WeekOfYear],
SUM(ISNULL(Facts.[DownloadCount], 0)) 'Downloads'
SUM(ISNULL(Facts.[DownloadCount], 0)) AS [Downloads]
FROM [dbo].[Fact_Download] AS Facts (NOLOCK)

INNER JOIN [dbo].[Dimension_Date] AS D (NOLOCK)
ON D.[Id] = Facts.[Dimension_Date_Id]

WHERE D.[Date] IS NOT NULL
AND ISNULL(D.[Date], CONVERT(DATE, '1900-01-01')) >=
DATETIMEFROMPARTS(
DATEPART(year, @MinDate),
DATEPART(month, @MinDate),
DATEPART(day, @MinDate),
0, 0, 0, 0)
AND ISNULL(D.[Date], CONVERT(DATE, DATEADD(day, 1, @ReportGenerationTime))) <
DATETIMEFROMPARTS(
DATEPART(year, @ReportGenerationTime),
DATEPART(month, @ReportGenerationTime),
DATEPART(day, @ReportGenerationTime),
0, 0, 0, 0)
AND Facts.[Timestamp] <= @Cursor

GROUP BY D.[Year], D.[WeekOfYear]
ORDER BY [Year], [WeekOfYear]

INNER JOIN WeekLookup AS D ON D.Id = Facts.Dimension_Date_Id
GROUP BY D.[Year], D.[WeekOfYear]
ORDER BY [Year], [WeekOfYear]
END