/// <summary> /// A pass for Booked spots. Don't store results, no spots placed. /// </summary> private void ExecuteBookedPass( SmoothPassBooked specificSmoothPass, IReadOnlyCollection <Break> breaksForThePeriodBeingSmoothed, ISet <Guid> spotIdsUsed, SmoothBatchOutput smoothBatchOutput) { SmoothPassResult result = _smoothPassBookedExecuter.Execute( specificSmoothPass, breaksForThePeriodBeingSmoothed, spotIdsUsed); smoothBatchOutput.BookedSpotsUnplacedDueToRestrictions += result.BookedSpotIdsUnplacedDueToRestrictions.Count; }
/// <summary> /// Executes a Smooth pass. Checks booked spots, unplaces any spots with /// a restriction /// </summary> /// <param name="smoothPass"></param> /// <param name="breaksForThePeriodBeingSmoothed"></param> /// <param name="spotIdsUsed"></param> /// <returns></returns> public SmoothPassResult Execute( SmoothPassBooked smoothPass, IReadOnlyCollection <Break> breaksForThePeriodBeingSmoothed, ISet <Guid> spotIdsUsed ) { var smoothPassResult = new SmoothPassResult(smoothPass.Sequence); var programme = _smoothProgramme.Programme; var salesArea = _smoothProgramme.SalesArea; // Check booked spots within each break foreach (var smoothBreak in _smoothProgramme.ProgrammeSmoothBreaks) { var breakSpotsToCheck = new List <SmoothSpot>( smoothBreak.SmoothSpots.Where(s => !s.IsCurrent)); Break theBreak = smoothBreak.TheBreak; bool AnySponsorshipRestrictions(Spot spotToCheckForRestrictions) { IReadOnlyCollection <(Guid spotUid, SmoothFailureMessages failureMessage)> result = _sponsorshipRestrictionService.CheckSponsorshipRestrictions( spotToCheckForRestrictions, theBreak.ExternalBreakRef, theBreak.ScheduledDate, theBreak.Duration, smoothBreak.SmoothSpots.Select(s => s.Spot).ToList() ); return(result .Where(r => r.spotUid == spotToCheckForRestrictions.Uid) .Select(r => r.failureMessage) .Any(r => _sponsorshipRestrictionFailures.Contains(r))); } foreach (var smoothSpot in breakSpotsToCheck) { Spot spot = smoothSpot.Spot; try { if (AnySponsorshipRestrictions(spot)) { UnplaceRestrictedSpot( smoothPass, smoothSpot, smoothBreak, "Sponsorship restrictions found: spot is a competitor to the sponsor", spotIdsUsed ); continue; } var restrictionResults = _smoothResources.RestrictionChecker .CheckRestrictions( programme, theBreak, spot, salesArea, breaksForThePeriodBeingSmoothed, _allProgrammesForPeriodAndSalesArea); if (restrictionResults.Count == 0) { continue; } UnplaceRestrictedSpot( smoothPass, smoothSpot, smoothBreak, $"Restrictions {GetRestrictionResultsDescription(restrictionResults)}", spotIdsUsed ); smoothPassResult.BookedSpotIdsUnplacedDueToRestrictions.Add(spot.Uid); } catch (Exception exception) { RaiseException( $"Error checking booked spot {spot.ExternalSpotRef} " + $"on pass {Log(smoothPass.Sequence)}", exception ); } } } return(smoothPassResult); }