Skip to content

Commit

Permalink
prevent redundant alert messages, see #391
Browse files Browse the repository at this point in the history
  • Loading branch information
jbphet committed Feb 21, 2024
1 parent 72dd8a0 commit 8ae124b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions js/common/view/EnergyFluxAlerter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ class EnergyFluxAlerter extends Alerter {
// description string property for the energy flux sensed by the flux meter
private readonly energyFluxDescriptionProperty: TReadOnlyProperty<string>;

// Previous alert string - used to decide if a change has occurred since the last alert.
private previousEnergyFluxDescriptionAlert = '';

// boolean flag that tracks whether the flux sensor has moved since the last alert was announced
private sensorMovedSinceLastAlert = false;

Expand Down Expand Up @@ -208,10 +211,13 @@ class EnergyFluxAlerter extends Alerter {

// Did one or more of the flux values change enough to warrant an alert? Or did something else happen to
// trigger a full alert?
if ( largestFluxChange > ENERGY_FLUX_THRESHOLD_FOR_INDEPENDENT_ALERTS || this.performFullAlertNextCycle ) {
if ( ( largestFluxChange > ENERGY_FLUX_THRESHOLD_FOR_INDEPENDENT_ALERTS &&
this.energyFluxDescriptionProperty.value !== this.previousEnergyFluxDescriptionAlert ) ||
this.performFullAlertNextCycle ) {

// The flux change is over the threshold, so do an alert of the current energy flux description.
// Do a full alert.
this.alert( this.energyFluxDescriptionProperty.value );
this.previousEnergyFluxDescriptionAlert = this.energyFluxDescriptionProperty.value;
alerted = true;
}

Expand All @@ -222,6 +228,7 @@ class EnergyFluxAlerter extends Alerter {
// trigger a new alert on its own?
if ( largestFluxChange > NON_NEGLIGIBLE_FLUX_CHANGE ) {
this.alert( this.energyFluxDescriptionProperty.value );
this.previousEnergyFluxDescriptionAlert = this.energyFluxDescriptionProperty.value;
}
else {

Expand Down

0 comments on commit 8ae124b

Please sign in to comment.