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); }
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)); }
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)); }
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); }