Skip to content

Commit

Permalink
Stats: fix issue with duplicate key when playing the exact same widge…
Browse files Browse the repository at this point in the history
…t at the same time (from a subplaylist) #284
  • Loading branch information
dasgarner committed Mar 17, 2023
1 parent f08809b commit 57399bc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
7 changes: 7 additions & 0 deletions Rendering/Media.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public partial class Media : UserControl
/// </summary>
protected DateTime _startTick;

/// <summary>
/// A unique ID for this instance of media
/// </summary>
public Guid UniqueId { get; private set; }

/// <summary>
/// The ScheduleId
/// </summary>
Expand Down Expand Up @@ -131,6 +136,8 @@ public Media(MediaOptions options)
{
InitializeComponent();

UniqueId = Guid.NewGuid();

// Store the options.
this.options = options;
this.Id = options.mediaid;
Expand Down
6 changes: 3 additions & 3 deletions Rendering/Region.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private void StartNext(double position)

// Open a stat record
// options accurately reflect the current media, so we can use them.
StatManager.Instance.WidgetStart(this.options.scheduleId, this.options.layoutId, _currentMediaOptions.mediaid);
StatManager.Instance.WidgetStart(newMedia.UniqueId, this.options.scheduleId, this.options.layoutId, _currentMediaOptions.mediaid);
}
}

Expand Down Expand Up @@ -706,7 +706,7 @@ private void StopMedia(Media media)
// Close the stat record
if (media.IsFailedToPlay)
{
StatManager.Instance.WidgetClearFailed(media.ScheduleId, media.LayoutId, media.Id);
StatManager.Instance.WidgetClearFailed(media.UniqueId, media.ScheduleId, media.LayoutId, media.Id);

if (isAdspaceExchange)
{
Expand Down Expand Up @@ -735,7 +735,7 @@ private void StopMedia(Media media)
}
else
{
StatManager.Instance.WidgetStop(media.ScheduleId, media.LayoutId, media.Id, media.StatsEnabled, adspaceExchangeImpressionUrls);
StatManager.Instance.WidgetStop(media.UniqueId, media.ScheduleId, media.LayoutId, media.Id, media.StatsEnabled, adspaceExchangeImpressionUrls);
}

// Media Stopped Event removes the media from the scene
Expand Down
23 changes: 17 additions & 6 deletions Stats/StatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ public void Stop()
/// <summary>
/// Layout Start Event
/// </summary>
/// <param name="uniqueId"></param>
/// <param name="scheduleId"></param>
/// <param name="layoutId"></param>
public void LayoutStart(Guid uniqueId, int scheduleId, int layoutId)
Expand Down Expand Up @@ -224,6 +225,7 @@ public void LayoutStart(Guid uniqueId, int scheduleId, int layoutId)
/// <summary>
/// Layout Stop Event
/// </summary>
/// <param name="uniqueId"></param>
/// <param name="scheduleId"></param>
/// <param name="layoutId"></param>
/// <param name="statEnabled"></param>
Expand Down Expand Up @@ -273,17 +275,18 @@ public double LayoutStop(Guid uniqueId, int scheduleId, int layoutId, bool statE
/// <summary>
/// Widget Start Event
/// </summary>
/// <param name="uniqueId"></param>
/// <param name="scheduleId"></param>
/// <param name="layoutId"></param>
/// <param name="widgetId"></param>
public void WidgetStart(int scheduleId, int layoutId, string widgetId)
public void WidgetStart(Guid uniqueId, int scheduleId, int layoutId, string widgetId)
{
Debug.WriteLine(string.Format("WidgetStart: scheduleId: {0}, layoutId: {1}, widgetId: {2}", scheduleId, layoutId, widgetId), "StatManager");

lock (_locker)
{
// New record, which we put in the dictionary
string key = scheduleId + "-" + layoutId + "-" + widgetId;
string key = uniqueId + "-" + scheduleId + "-" + layoutId + "-" + widgetId;
Stat stat = new Stat
{
Type = StatType.Media,
Expand All @@ -303,12 +306,19 @@ public void WidgetStart(int scheduleId, int layoutId, string widgetId)
}
}

public void WidgetClearFailed(int scheduleId, int layoutId, string widgetId)
/// <summary>
/// If a widget fails to play we should not record a stat for it.
/// </summary>
/// <param name="uniqueId"></param>
/// <param name="scheduleId"></param>
/// <param name="layoutId"></param>
/// <param name="widgetId"></param>
public void WidgetClearFailed(Guid uniqueId, int scheduleId, int layoutId, string widgetId)
{
lock (_locker)
{
// Record we expect to already be open in the Dictionary
string key = scheduleId + "-" + layoutId + "-" + widgetId;
string key = uniqueId + "-" + scheduleId + "-" + layoutId + "-" + widgetId;

LogMessage.Info("StatManager", "WidgetClearFailed", "Removing failed widget: " + key);

Expand All @@ -319,13 +329,14 @@ public void WidgetClearFailed(int scheduleId, int layoutId, string widgetId)
/// <summary>
/// Widget Stop Event
/// </summary>
/// <param name="uniqueId"></param>
/// <param name="scheduleId"></param>
/// <param name="layoutId"></param>
/// <param name="widgetId"></param>
/// <param name="statEnabled"></param>
/// <param name="urls"></param>
/// <returns>Duration</returns>
public double WidgetStop(int scheduleId, int layoutId, string widgetId, bool statEnabled, List<string> urls)
public double WidgetStop(Guid uniqueId, int scheduleId, int layoutId, string widgetId, bool statEnabled, List<string> urls)
{
Debug.WriteLine(string.Format("WidgetStop: scheduleId: {0}, layoutId: {1}, widgetId: {2}", scheduleId, layoutId, widgetId), "StatManager");

Expand All @@ -334,7 +345,7 @@ public double WidgetStop(int scheduleId, int layoutId, string widgetId, bool sta
lock (_locker)
{
// Record we expect to already be open in the Dictionary
string key = scheduleId + "-" + layoutId + "-" + widgetId;
string key = uniqueId + "-" + scheduleId + "-" + layoutId + "-" + widgetId;

if (this.proofOfPlay.TryGetValue(key, out Stat stat))
{
Expand Down

0 comments on commit 57399bc

Please sign in to comment.