public static void PopulatePrePostCampaignKPIs(ICampaignKpiData campaignData, ScenarioCampaignResultItem source, ScenarioCampaignResultModel result) { var totalNominalValue = source.NominalValue + campaignData.NominalValue; var revenueBudget = campaignData.RevenueBudget ?? 0; var totalPayback = campaignData.Payback ?? 0; var differenceValueDelivered = totalNominalValue - revenueBudget; var differenceValueDeliveredPayback = totalNominalValue - revenueBudget - totalPayback; var dayPartRevenueWithPayback = revenueBudget + totalPayback; result.ZeroRatedSpots = (int)source.ZeroRatedSpots; result.NominalValue = source.NominalValue; result.TotalNominalValue = totalNominalValue; result.RevenueBudget = revenueBudget; result.TotalPayback = totalPayback; result.DifferenceValueDelivered = differenceValueDelivered; result.DifferenceValueDeliveredPayback = differenceValueDeliveredPayback; result.DifferenceValueDeliveredPercentage = revenueBudget == 0 ? 0 : Math.Round((differenceValueDelivered / revenueBudget) * 100, 2); result.DifferenceValueDeliveredPercentagePayback = dayPartRevenueWithPayback == 0 ? 0 : Math.Round((differenceValueDeliveredPayback / dayPartRevenueWithPayback) * 100, 2); }
/// <summary>Generates the report data.</summary> /// <param name="source">The source.</param> /// <returns></returns> public IReadOnlyCollection <ScenarioCampaignResultModel> GenerateReportData( IReadOnlyCollection <ScenarioCampaignExtendedResultItem> source) { if (source is null || source.Count == 0) { return(Array.Empty <ScenarioCampaignResultModel>()); } PrepareRelatedData(source); var result = source .AsParallel() .Select(item => { var scenarioCampaignResultModel = new ScenarioCampaignResultModel { ExternalCampRef = item.CampaignExternalId, DaypartName = item.DaypartName, DurationSecs = item.SpotLength, TargetRatings = item.TargetRatings, PreRunRatings = item.PreRunRatings, ISRCancelledRatings = item.ISRCancelledRatings, ISRCancelledSpots = item.ISRCancelledSpots, RSCancelledRatings = item.RSCancelledRatings, RSCancelledSpots = item.RSCancelledSpots, OptimiserRatings = item.OptimiserRatings, StrikeWeightStartDate = item.StrikeWeightStartDate, StrikeWeightEndDate = item.StrikeWeightEndDate, OptimiserBookedSpots = item.OptimiserBookedSpots, PreRunRatingsDiff = item.PreRunRatings - item.TargetRatings, PostRunRatings = item.PreRunRatings + item.OptimiserRatings - (item.ISRCancelledRatings + item.RSCancelledRatings), MediaSalesGroup = item.MediaSalesGroup, ProductAssignee = item.ProductAssignee, StopBooking = item.StopBooking, CreationDate = item.CreationDate, AutomatedBooked = item.AutomatedBooked, TopTail = item.TopTail, ReportingCategory = item.ReportingCategory, ClashCode = item.ClashCode, AgencyName = item.AgencyName, PassThatDelivered100Percent = item.PassThatDelivered100Percent }; scenarioCampaignResultModel.PostRunRatingsDiff = scenarioCampaignResultModel.PostRunRatings - item.TargetRatings; var campaign = ResolveCampaign(item); if (campaign is null) { return(scenarioCampaignResultModel); } scenarioCampaignResultModel.CampaignName = campaign.Name; scenarioCampaignResultModel.CampaignGroup = campaign.CampaignGroup; scenarioCampaignResultModel.BusinessType = campaign.BusinessType; scenarioCampaignResultModel.CampaignStartDate = campaign.StartDateTime; scenarioCampaignResultModel.CampaignEndDate = campaign.EndDateTime; scenarioCampaignResultModel.DaysToEndOfCampaign = (campaign.EndDateTime - DateTime.Now).Days; scenarioCampaignResultModel.TargetAchievedPct = Math.Round( item.TargetRatings == 0 ? 0 : scenarioCampaignResultModel.PostRunRatings / item.TargetRatings * 100, 2, MidpointRounding.AwayFromZero ); scenarioCampaignResultModel.SalesAreaGroupName = campaign.SalesAreaCampaignTarget .Select(sact => sact?.SalesAreaGroup) .FirstOrDefault(sag => IsSalesAreaNameEqual(sag, item)) ?.GroupName; var demographic = ResolveDemographic(campaign); if (!(demographic is null)) { scenarioCampaignResultModel.DemographicName = demographic.Name; } var product = ResolveProduct(campaign); if (!(product is null)) { scenarioCampaignResultModel.AdvertiserName = product.AdvertiserName; scenarioCampaignResultModel.ProductName = product.Name; var childClash = ResolveClash(campaign); if (!(childClash is null)) { scenarioCampaignResultModel.ChildClashName = childClash.Description; var parentClash = ResolveParentClash(campaign); if (!(parentClash is null)) { scenarioCampaignResultModel.ParentClashName = parentClash.Description; } } } if (_enablePerformanceKpiColumns) { if (_isCampaignLevel) { var campaignLevelReportData = new CampaignLevelReport { NominalValue = campaign.RevenueBooked.HasValue ? campaign.RevenueBooked.Value : 0, RevenueBudget = campaign.RevenueBudget, Payback = (double)campaign.CalculateTotalPayback() }; PrePostCampaignKPIsCalculator.PopulatePrePostCampaignKPIs(campaignLevelReportData, item, scenarioCampaignResultModel); } else { var dayPart = ResolveDayPartKpiModel(campaign, item); if (dayPart != null) { PrePostCampaignKPIsCalculator.PopulatePrePostCampaignKPIs(dayPart, item, scenarioCampaignResultModel); } } } return(scenarioCampaignResultModel);