Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Play promos based on priority
Browse files Browse the repository at this point in the history
  • Loading branch information
dnas2 committed Dec 13, 2017
1 parent 2d147e6 commit 39571f0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
19 changes: 14 additions & 5 deletions ad-automation/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions ad-automation/adBreak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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++;
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions ad-automation/audioFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions ad-automation/promo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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; }
}
Expand Down

0 comments on commit 39571f0

Please sign in to comment.