Skip to content

Commit

Permalink
Reworked calculation of normalised score
Browse files Browse the repository at this point in the history
Issue #297 Used the Interval class to set the possible score range of an event.
  • Loading branch information
towsey committed Apr 29, 2020
1 parent bcc33bb commit 5afbf11
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
9 changes: 0 additions & 9 deletions src/AnalysisBase/ResultBases/EventBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ public abstract class EventBase : ResultBase
// AT: the above definition cannot be changed!
public virtual double Score { get; set; }

/// <summary>
/// Gets or sets a maximum possible score for this event.
/// This is used to establish a score scale and thereby normalise the score.
/// It is assumed that the score range is 0.0 to scoreMax.
/// </summary>
public virtual double ScoreMax { get; set; }

public double ScoreNormalised => this.Score / this.ScoreMax;

/// <summary>
/// Gets or sets the Event's Start Seconds.
/// IMPORTANT: This field is time offset relative to the recording.
Expand Down
17 changes: 16 additions & 1 deletion src/AudioAnalysisTools/Events/EventCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AudioAnalysisTools.Events
{
using Acoustics.Shared;
using AnalysisBase.ResultBases;
using AudioAnalysisTools.Events.Drawing;
using SixLabors.ImageSharp.PixelFormats;
Expand Down Expand Up @@ -32,7 +33,21 @@ public abstract class EventCommon : EventBase, IDrawableEvent
/// </summary>
public string ComponentName => this.GetType().Name;

//ae.Name = parameters.ComponentName;
/// <summary>
/// Gets or sets the event score.
/// This is a score in absolute units as determined by context.
/// ScoreMax determines the scale.
/// </summary>
public override double Score { get; set; }

/// <summary>
/// Gets or sets a min-max range of values for the score for this event.
/// This is used to establish a score scale and thereby normalise the score.
/// By default the minimum value of range = zero.
/// </summary>
public Interval<double> ScoreRange { get; set; }

public double ScoreNormalised => this.Score / this.ScoreRange.Maximum;

/// <summary>
/// Draw this event on an image.
Expand Down
3 changes: 2 additions & 1 deletion src/AudioAnalysisTools/Events/Types/ChirpEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace AudioAnalysisTools
using System;
using System.Collections.Generic;
using System.Linq;
using Acoustics.Shared;
using AudioAnalysisTools.Events;
using AudioAnalysisTools.Events.Drawing;
using AudioAnalysisTools.Events.Interfaces;
Expand All @@ -30,7 +31,7 @@ public class ChirpEvent : SpectralEvent, ITracks<Track>
public ChirpEvent(Track chirp, double maxScore)
{
this.Tracks.Add(chirp);
this.maxScore = maxScore;
this.ScoreRange = new Interval<double>(0, maxScore);
}

public List<Track> Tracks { get; private set; } = new List<Track>(1);
Expand Down
3 changes: 2 additions & 1 deletion src/AudioAnalysisTools/Events/Types/ClickEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace AudioAnalysisTools
using System;
using System.Collections.Generic;
using System.Linq;
using Acoustics.Shared;
using AudioAnalysisTools.Events;
using AudioAnalysisTools.Events.Drawing;
using AudioAnalysisTools.Events.Interfaces;
Expand All @@ -18,7 +19,7 @@ public class ClickEvent : SpectralEvent, ITracks<Track>
public ClickEvent(Track click, double maxScore)
{
this.Tracks.Add(click);
this.ScoreMax = maxScore;
this.ScoreRange = new Interval<double>(0, maxScore);
}

public List<Track> Tracks { get; private set; } = new List<Track>(1);
Expand Down
3 changes: 2 additions & 1 deletion src/AudioAnalysisTools/Events/Types/WhipEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace AudioAnalysisTools
using System;
using System.Collections.Generic;
using System.Linq;
using Acoustics.Shared;
using AudioAnalysisTools.Events;
using AudioAnalysisTools.Events.Drawing;
using AudioAnalysisTools.Events.Interfaces;
Expand All @@ -18,7 +19,7 @@ public class WhipEvent : SpectralEvent, ITracks<Track>
public WhipEvent(Track whip, double maxScore)
{
this.Tracks.Add(whip);
this.ScoreMax = maxScore;
this.ScoreRange = new Interval<double>(0, maxScore);
}

public List<Track> Tracks { get; private set; } = new List<Track>(1);
Expand Down
3 changes: 2 additions & 1 deletion src/AudioAnalysisTools/Events/Types/WhistleEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace AudioAnalysisTools
using System;
using System.Collections.Generic;
using System.Linq;
using Acoustics.Shared;
using AudioAnalysisTools.Events;
using AudioAnalysisTools.Events.Drawing;
using AudioAnalysisTools.Events.Interfaces;
Expand All @@ -18,7 +19,7 @@ public class WhistleEvent : SpectralEvent, ITracks<Track>
public WhistleEvent(Track whistle, double maxScore)
{
this.Tracks.Add(whistle);
this.ScoreMax = maxScore;
this.ScoreRange = new Interval<double>(0, maxScore);
}

public List<Track> Tracks { get; private set; } = new List<Track>(1);
Expand Down

0 comments on commit 5afbf11

Please sign in to comment.