Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
60 changes: 30 additions & 30 deletions Doppler.ReportingApi/Infrastructure/CampaignRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ FROM dbo.usertimezone timezone
C.[IdUser]
,[IdCampaign]
,CAST(
DATEADD(MINUTE, @timezone, C.[UTCScheduleDate])
DATEADD(MINUTE, @timezone, C.[UTCSentDate])
AS DATE
) AS [Date]
,COALESCE(C.[AmountSentSubscribers], C.[AmountSubscribersToSend], 0) AS [Sent]
Expand All @@ -62,7 +62,7 @@ JOIN [dbo].[User] U WITH (NOLOCK)
WHERE
U.[Email] = @userName
AND C.[Status] IN (5,9,10)
AND C.[UTCScheduleDate] BETWEEN @startDate AND @endDate
AND C.[UTCSentDate] BETWEEN @startDate AND @endDate
AND C.[IdTestCampaign] IS NULL
AND C.[IdScheduledTask] IS NULL
AND C.Active = 1
Expand All @@ -71,7 +71,7 @@ UNION ALL
S.[IdUser]
,S.[IdCampaign]
,CAST(
DATEADD(MINUTE, @timezone, C.[UTCScheduleDate])
DATEADD(MINUTE, @timezone, C.[UTCSentDate])
AS DATE
) AS [Date]
,0 [Sent]
Expand Down Expand Up @@ -101,7 +101,7 @@ JOIN [dbo].[User] U WITH (NOLOCK)
WHERE
U.[Email] = @userName
AND C.[Status] IN (5,9,10)
AND C.[UTCScheduleDate] BETWEEN @startDate AND @endDate
AND C.[UTCSentDate] BETWEEN @startDate AND @endDate
AND S.[IdSubscribersStatus] = 5
AND C.[IdTestCampaign] IS NULL
AND C.[IdScheduledTask] IS NULL
Expand All @@ -110,7 +110,7 @@ GROUP BY
S.[IdUser]
,S.[IdCampaign]
,CAST(
DATEADD(MINUTE, @timezone, C.[UTCScheduleDate])
DATEADD(MINUTE, @timezone, C.[UTCSentDate])
AS DATE
)
) AS RPT
Expand Down Expand Up @@ -145,7 +145,7 @@ FROM dbo.usertimezone timezone
RPT.[IdUser]
,RPT.[IdCampaign]
,RPT.[Name]
,dateadd(MINUTE, @timezone, RPT.[UTCScheduleDate]) AS [UTCScheduleDate]
,dateadd(MINUTE, @timezone, RPT.[UTCSentDate]) AS [UTCSentDate]
,RPT.[FromEmail]
,RPT.[CampaignType]
,RPT.[IdTestAB]
Expand Down Expand Up @@ -192,7 +192,7 @@ END AS [SpamRate]
C.[IdUser]
,C.[IdCampaign]
,C.[Name]
,C.[UTCScheduleDate]
,C.[UTCSentDate]
,C.[FromEmail]
,C.[CampaignType]
,C.[IdTestAB]
Expand Down Expand Up @@ -243,8 +243,8 @@ GROUP BY c.IdCampaign
U.[Email] = @userName
AND C.[Status] IN (5,9)
AND C.Active = 1
AND (@startDate IS NULL OR C.[UTCScheduleDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCScheduleDate] < @endDate)
AND (@startDate IS NULL OR C.[UTCSentDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCSentDate] < @endDate)
AND (@campaignName IS NULL OR LOWER(LTRIM(RTRIM(C.[Name]))) LIKE '%' + LOWER(LTRIM(RTRIM(@campaignName))) + '%')
AND (
@campaignType IS NULL
Expand All @@ -264,13 +264,13 @@ OR C.[IdLabel] IN @labels
GROUP BY RPT.[IdUser]
,RPT.[IdCampaign]
,RPT.[Name]
,RPT.[UTCScheduleDate]
,RPT.[UTCSentDate]
,RPT.[FromEmail]
,RPT.[CampaignType]
,RPT.[IdTestAB]
,RPT.[LabelName]
,RPT.[LabelColour]
ORDER BY RPT.[UTCScheduleDate] DESC
ORDER BY RPT.[UTCSentDate] DESC
OFFSET @pageNumber * @pageSize ROWS
FETCH NEXT @pageSize ROWS ONLY";

Expand All @@ -297,8 +297,8 @@ LEFT JOIN [dbo].[Label] L WITH (NOLOCK)
U.[Email] = @userName
AND C.[Status] IN (5,9)
AND C.Active = 1
AND (@startDate IS NULL OR C.[UTCScheduleDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCScheduleDate] < @endDate)
AND (@startDate IS NULL OR C.[UTCSentDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCSentDate] < @endDate)
AND (@campaignName IS NULL OR LOWER(LTRIM(RTRIM(C.[Name]))) LIKE '%' + LOWER(LTRIM(RTRIM(@campaignName))) + '%')
AND (
@campaignType IS NULL
Expand Down Expand Up @@ -335,8 +335,8 @@ FROM dbo.usertimezone timezone

SELECT
RPT.[IdUser]
,YEAR(dateadd(MINUTE, @timezone, UTCScheduleDate)) [Year]
,MONTH(dateadd(MINUTE, @timezone, UTCScheduleDate)) [Month]
,YEAR(dateadd(MINUTE, @timezone, UTCSentDate)) [Year]
,MONTH(dateadd(MINUTE, @timezone, UTCSentDate)) [Month]
,COUNT(DISTINCT RPT.[IdCampaign]) [CampaginsCount]
,SUM(RPT.[Subscribers]) [Subscribers]
,SUM(RPT.[Sent]) [Sent]
Expand Down Expand Up @@ -378,7 +378,7 @@ END AS [SpamRate]
SELECT
C.[IdUser]
,C.[IdCampaign]
,C.[UTCScheduleDate]
,C.[UTCSentDate]
,ISNULL(C.[AmountSentSubscribers],0) [Subscribers]
,(ISNULL(C.AmountSentSubscribers, 0) - (ISNULL(C.HardBouncedMailCount, 0) + ISNULL(C.SoftBouncedMailCount, 0))) AS [Sent]
,ISNULL(C.[DistinctOpenedMailCount],0) [Opens]
Expand All @@ -395,16 +395,16 @@ JOIN [dbo].[User] U WITH (NOLOCK)
U.[Email] = @userName
AND C.[Status] IN (5,9)
AND C.Active = 1
AND (@startDate IS NULL OR C.[UTCScheduleDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCScheduleDate] < @endDate)
AND (@startDate IS NULL OR C.[UTCSentDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCSentDate] < @endDate)
AND C.[IdTestCampaign] IS NULL
AND C.[IdScheduledTask] IS NULL
AND (C.TestABCategory IS NULL OR C.TestABCategory = 3)
UNION ALL
SELECT
S.[IdUser]
,S.[IdCampaign]
,C.[UTCScheduleDate]
,C.[UTCSentDate]
,0 [Subscribers]
,0 [Sent]
,0 [Opens]
Expand Down Expand Up @@ -435,8 +435,8 @@ JOIN [dbo].[User] U WITH (NOLOCK)
U.[Email] = @userName
AND C.[Status] IN (5,9)
AND C.Active = 1
AND (@startDate IS NULL OR C.[UTCScheduleDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCScheduleDate] < @endDate)
AND (@startDate IS NULL OR C.[UTCSentDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCSentDate] < @endDate)
AND C.[IdTestCampaign] IS NULL
AND C.[IdScheduledTask] IS NULL
AND (C.TestABCategory IS NULL OR C.TestABCategory = 3)
Expand All @@ -445,13 +445,13 @@ GROUP BY
S.[IdUser]
,S.[IdCampaign]
,C.[Name]
,C.[UTCScheduleDate]
,C.[UTCSentDate]
,C.[FromEmail]
,C.[CampaignType]
) RPT
GROUP BY RPT.[IdUser]
,YEAR(dateadd(MINUTE, @timezone, UTCScheduleDate))
,MONTH(dateadd(MINUTE, @timezone, UTCScheduleDate))
,YEAR(dateadd(MINUTE, @timezone, UTCSentDate))
,MONTH(dateadd(MINUTE, @timezone, UTCSentDate))

ORDER BY [Year] DESC, [Month] DESC
OFFSET @pageNumber * @pageSize ROWS
Expand All @@ -472,24 +472,24 @@ SELECT COUNT(*)
FROM (
SELECT
C.[IdUser],
YEAR(C.[UTCScheduleDate]) AS [Year],
MONTH(C.[UTCScheduleDate]) AS [Month]
YEAR(C.[UTCSentDate]) AS [Year],
MONTH(C.[UTCSentDate]) AS [Month]
FROM [dbo].[Campaign] C WITH (NOLOCK)
JOIN [dbo].[User] U WITH (NOLOCK)
ON C.[IdUser] = U.[IdUser]
WHERE
U.[Email] = @userName
AND C.[Status] IN (5,9)
AND C.Active = 1
AND (@startDate IS NULL OR C.[UTCScheduleDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCScheduleDate] < @endDate)
AND (@startDate IS NULL OR C.[UTCSentDate] >= @startDate)
AND (@endDate IS NULL OR C.[UTCSentDate] < @endDate)
AND C.[IdTestCampaign] IS NULL
AND C.[IdScheduledTask] IS NULL
AND (C.TestABCategory IS NULL OR C.TestABCategory = 3)
GROUP BY
C.[IdUser],
YEAR(C.[UTCScheduleDate]),
MONTH(C.[UTCScheduleDate])
YEAR(C.[UTCSentDate]),
MONTH(C.[UTCSentDate])
) AS MonthlyGroups;";

var count = await connection.QuerySingleAsync<int>(dummyDatabaseQuery, new { userName, startDate, endDate });
Expand Down
4 changes: 2 additions & 2 deletions Doppler.ReportingApi/Models/SentCampaignsMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public class SentCampaignMetrics
public string Name { get; set; }

/// <summary>
/// UTC date and time when the campaign was scheduled to be sent.
/// UTC date and time when the campaign was sent.
/// </summary>
public DateTime UTCScheduleDate { get; set; }
public DateTime UTCSentDate { get; set; }

/// <summary>
/// Email address used as the sender of the campaign.
Expand Down