Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow toggling filtering of duplicate messages on agent via configuration #95

Closed
virizar opened this issue Feb 12, 2025 · 2 comments
Closed

Comments

@virizar
Copy link
Contributor

virizar commented Feb 12, 2025

Hi @PatrickRitchie

For our applications, we need to be able to allow messages to be sent from the agent even if the content of the message is the same on consecutive observations.

I have noticed that the agent, when checking if the data items of an observation have delta filtering, it checks if the message has not changed and if so prevents the observation to be updated and resend.

private static bool FilterDelta(IDataItem dataItem, IObservationInput newObservation, IObservationInput existingObservation)
{
if (dataItem != null)
{
if (!ObjectExtensions.ByteArraysEqual(newObservation.ChangeId, existingObservation.ChangeId))
{
if (!dataItem.Filters.IsNullOrEmpty() && dataItem.Representation == DataItemRepresentation.VALUE)
{
foreach (var filter in dataItem.Filters)
{
if (filter.Type == DataItemFilterType.MINIMUM_DELTA)
{
if (filter.Value > 0)
{
var x = newObservation.GetValue(ValueKeys.Result).ToDouble();
var y = existingObservation.GetValue(ValueKeys.Result).ToDouble();
// If difference between New and Existing exceeds Filter Minimum Delta Value
return Math.Abs(x - y) > filter.Value;
}
}
}
}
return true;
}
}
return false;

protected bool CheckCurrentObservation(string deviceUuid, IDataItem dataItem, IObservationInput observation)
{
if (_currentObservations != null && observation != null && !string.IsNullOrEmpty(deviceUuid) && dataItem != null)
{
var hash = $"{deviceUuid}:{dataItem.Id}";
_currentObservations.TryGetValue(hash, out var existingObservation);
if (observation != null && existingObservation != null)
{
var timestamp = observation.Timestamp;
var existingTimestamp = existingObservation.Timestamp.ToUnixTime();
var existingObservationInput = new ObservationInput(existingObservation);
// Check Filters
var update = FilterPeriod(dataItem, timestamp, existingTimestamp);
if (update) update = FilterDelta(dataItem, observation, existingObservationInput);
// Update if Filters are passed or if the DataItem is set to Discrete
if (update || dataItem.Discrete)
{
return true;
}
}
else
{
return true;
}
}
return false;
}

I can see that the adapter applications have a FilterDuplicates configuration element to toggle this behavior.

Is this something that could also be relevant for the agent? I can make a PR with what I am current using if this is of value for the agent.

@virizar
Copy link
Contributor Author

virizar commented Feb 12, 2025

Actually, it seems that each data item can be set to discreet on the device config? that would be the equivalent of this I suppose

@virizar
Copy link
Contributor Author

virizar commented Feb 14, 2025

Closing this since the discrete attribute of the data items is what should be used for this!

@virizar virizar closed this as completed Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant