diff --git a/ad-automation/Form1.cs b/ad-automation/Form1.cs index eba4b09..8674e61 100644 --- a/ad-automation/Form1.cs +++ b/ad-automation/Form1.cs @@ -36,11 +36,8 @@ public partial class adForm : Form public adForm() { InitializeComponent(); - nextMonday = DateTime.Today.AddDays(1); - while (nextMonday.DayOfWeek != DayOfWeek.Monday) - { - nextMonday = nextMonday.AddDays(1); - } + DateTime tomorrow = DateTime.Today.AddDays(1); + createBreaksForPicker.Value = tomorrow; } private void button1_Click(object sender, EventArgs e) @@ -253,7 +250,19 @@ private void getPromosInFolder(string folderPath) tmpPromo.deserialiseSavedInfo(); tmpPromo.setPriority(createBreaksForPicker.Value); tmpPromo.addToPromoTablePanel(promoTableLayoutPanel); + // Add promo mulitple times depending on priorities to weight the probabilityu of it being chosen allPromos.Add(tmpPromo); + if (tmpPromo.priority < 3) + { + allPromos.Add(tmpPromo); + allPromos.Add(tmpPromo); + } + if (tmpPromo.priority < 2) + { + allPromos.Add(tmpPromo); + allPromos.Add(tmpPromo); + allPromos.Add(tmpPromo); + } } } diff --git a/ad-automation/adBreak.cs b/ad-automation/adBreak.cs index 5b4426a..e3a2e66 100644 --- a/ad-automation/adBreak.cs +++ b/ad-automation/adBreak.cs @@ -83,10 +83,10 @@ private void addRandomBumper(string bumperType) private void addAdverts() { + int numFailures = 0; for (int i = 0; i < targetAds;) { advert newAdvert = adForm.selectAd(breakTime); - int numFailures = 0; if (newAdvert != null) { breakContents.Add(newAdvert); @@ -100,16 +100,16 @@ private void addAdverts() } else { + numFailures++; if (adForm.adsToPlayPerDay.Count() < 1) { break; // We've run out of adverts we can play } - else if (numFailures > 999) + else if (numFailures > 99) { // Avoids the unlikely case where we might sit spinning at this point if there's only one advert left to play and it can't be played because of the keyword rule - throw new NotEnoughFileOptionsException("There are adverts left to play but rules prevent them being played"); + break; // We don't want to throw an exception as the keyword might be permitted in a later break } - numFailures++; } } } diff --git a/ad-automation/audioFile.cs b/ad-automation/audioFile.cs index aa6de0e..6e59329 100644 --- a/ad-automation/audioFile.cs +++ b/ad-automation/audioFile.cs @@ -17,11 +17,6 @@ public class audioFile public string mp3CommentString; public string serialisedJsonBlock; - int playsPerDay(DateTime targetDay, bool includeOvernight) - { - throw new NotImplementedException(); - } - public bool isAdBreakBetweenStartAndEndDates(DateTime breakTime) { if (breakTime < this.endDate && breakTime > this.startDate) diff --git a/ad-automation/promo.cs b/ad-automation/promo.cs index 7ce8be9..c505041 100644 --- a/ad-automation/promo.cs +++ b/ad-automation/promo.cs @@ -10,7 +10,7 @@ namespace ad_automation { public class promo : audioFile { - int priority = 0; // 0=Station generic; 1=Has expiry more than 3 days away; 2=Has expiry in next 3 days. Used for weighted probability of being chosen + public int priority = 0; // 0=Station generic; 1=Has expiry more than 3 days away; 2=Has expiry in next 3 days. Used for weighted probability of being chosen public bool canPromoBePlayedInBreak(DateTime breakTime) { @@ -41,7 +41,8 @@ internal void deserialiseSavedInfo() internal void setPriority(DateTime breakTime) { - if (endDate.Subtract(breakTime).TotalHours < 72) { priority = 1; } + double hoursToEndDate = endDate.Subtract(breakTime).TotalHours; + if (hoursToEndDate < 72) { priority = 1; } else if (filename.Contains("Cam105")) { priority = 3; } else { priority = 2; } }