Beispiel #1
0
        public static IQueryable <T> FilterBy <T>(this IQueryable <T> source, ReportCriteria reportCriteria) where T : class, IAdGroupAnalyticsData
        {
            // entity filter
            source = reportCriteria.BuyerAccounts.Aggregate(source, (current, buyerAccount) => current.Where(x => x.BuyerAccountId == buyerAccount.BuyerAccountId));
            if (reportCriteria.Advertiser != null)
            {
                source = source.Where(x => x.AdvertiserId == reportCriteria.Advertiser.AdvertiserId);
            }
            if (reportCriteria.AdvertiserProduct != null)
            {
                source = source.Where(x => x.AdvertiserProductId == reportCriteria.AdvertiserProduct.AdvertiserProductId);
            }
            if (reportCriteria.Campaign != null)
            {
                source = source.Where(x => x.CampaignId == reportCriteria.Campaign.CampaignId);
            }
            if (reportCriteria.AdGroup != null)
            {
                source = source.Where(x => x.AdGroupId == reportCriteria.AdGroup.AdGroupId);
            }

            // time range filter
            if (reportCriteria.LocalFromDateTime.HasValue)
            {
                source = source.Where(s => s.LocalDate >= reportCriteria.LocalFromDateTime);
            }
            if (reportCriteria.LocalToDateTime.HasValue)
            {
                source = source.Where(s => s.LocalDate < reportCriteria.LocalToDateTime);
            }

            return(source);
        }
Beispiel #2
0
        public async Task <IReport> GetAdvertiserReport(ReportCriteria reportCriteria)
        {
            var source = GetReportSouce <AdAnalyticsReportId>();

            source = source.FilterBy(reportCriteria);

            if (reportCriteria.Level == ReportLevelEnum.Daily)
            {
                return((await source.GroupBy(x => new
                {
                    Date = x.LocalDate,
                    x.AdvertiserId,
                    x.AdvertiserName,
                }).ToListAsync())
                       .AggregateReport()
                       .OrderBy(x => x.KeyData.Date)
                       .ThenBy(x => x.KeyData.AdvertiserName)
                       .ToReport(reportCriteria));
            }

            // summary
            return((await source.GroupBy(x => new
            {
                x.AdvertiserId,
                x.AdvertiserName,
            }).ToListAsync())
                   .AggregateReport()
                   .OrderBy(x => x.KeyData.AdvertiserName)
                   .ToReport(reportCriteria));
        }
Beispiel #3
0
        public async Task <IReport> GetStrategyReport(ReportCriteria reportCriteria)
        {
            var source = GetReportSouce <AdAnalyticsReportId>();

            source = source.FilterBy(reportCriteria);

            if (reportCriteria.Level == ReportLevelEnum.Daily)
            {
                // daily
                return((await source.GroupBy(x => new
                {
                    Date = x.LocalDate,
                    StrategyName = x.AdGroupName,
                    StrategyId = x.AdGroupId,
                    x.AdvertiserId,
                    x.AdvertiserName,
                    BrandId = x.AdvertiserProductId,
                    BrandName = x.ProductName,
                    x.CampaignId,
                    x.CampaignName,
                    x.CampaignStatusName
                }).ToListAsync())
                       .AggregateReport()
                       .OrderBy(x => x.KeyData.Date)
                       .ThenBy(x => x.KeyData.AdvertiserName)
                       .ThenBy(x => x.KeyData.BrandName)
                       .ThenBy(x => x.KeyData.CampaignName)
                       .ThenBy(x => x.KeyData.StrategyName)
                       .ToReport(reportCriteria));
            }

            // summary
            return((await source.GroupBy(x => new
            {
                StrategyName = x.AdGroupName,
                StrategyId = x.AdGroupId,
                x.AdvertiserId,
                x.AdvertiserName,
                BrandId = x.AdvertiserProductId,
                BrandName = x.ProductName,
                x.CampaignId,
                x.CampaignName,
                x.CampaignStatusName
            }).ToListAsync())
                   .AggregateReport()
                   .OrderBy(x => x.KeyData.AdvertiserName)
                   .ThenBy(x => x.KeyData.BrandName)
                   .ThenBy(x => x.KeyData.CampaignName)
                   .ThenBy(x => x.KeyData.StrategyName)
                   .ToReport(reportCriteria));
        }
Beispiel #4
0
        public static Report <T> ToReport <T>(this IEnumerable <PerformanceData <T> > source, ReportCriteria reportCriteria)
        {
            var report = new Report <T>(source)
            {
                ReportType  = reportCriteria.Type.ToString(),
                ReportLevel = reportCriteria.Level.ToString()
            };

            return(report);
        }