Added ability to filter out reporting geofencing events statuses

This commit is contained in:
dshvaika 2025-08-07 18:33:17 +03:00
parent c783176e71
commit 589e159b54

View File

@ -126,13 +126,37 @@ public class GeofencingCalculatedFieldState implements CalculatedFieldState {
.stream()
.map(zoneState -> zoneState.evaluate(entityCoordinates))
.collect(Collectors.toSet());
aggregateZoneGroupEvent(zoneEvents).ifPresent(event ->
resultNode.put(zoneGroupConfig.getReportTelemetryPrefix() + "Event", event.name())
);
aggregateZoneGroupEvent(zoneEvents)
.filter(geofencingEvent -> zoneGroupConfig.getReportEvents().contains(geofencingEvent))
.ifPresent(event ->
resultNode.put(zoneGroupConfig.getReportTelemetryPrefix() + "Event", event.name())
);
});
return Futures.immediateFuture(List.of(new CalculatedFieldResult(ctx.getOutput().getType(), ctx.getOutput().getScope(), resultNode)));
}
@Override
public boolean isReady() {
return arguments.keySet().containsAll(requiredArguments) &&
arguments.values().stream().noneMatch(ArgumentEntry::isEmpty);
}
@Override
public void checkStateSize(CalculatedFieldEntityCtxId ctxId, long maxStateSize) {
if (!sizeExceedsLimit && maxStateSize > 0 && CalculatedFieldUtils.toProto(ctxId, this).getSerializedSize() > maxStateSize) {
arguments.clear();
sizeExceedsLimit = true;
}
}
// TODO: Create a new class field to not do this on each calculation.
private Map<String, GeofencingArgumentEntry> getGeofencingArguments() {
return arguments.entrySet()
.stream()
.filter(entry -> !coordinateKeys.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, entry -> (GeofencingArgumentEntry) entry.getValue()));
}
private Optional<GeofencingEvent> aggregateZoneGroupEvent(Set<GeofencingEvent> zoneEvents) {
boolean hasEntered = false;
boolean hasLeft = false;
@ -166,26 +190,4 @@ public class GeofencingCalculatedFieldState implements CalculatedFieldState {
return Optional.empty();
}
@Override
public boolean isReady() {
return arguments.keySet().containsAll(requiredArguments) &&
arguments.values().stream().noneMatch(ArgumentEntry::isEmpty);
}
@Override
public void checkStateSize(CalculatedFieldEntityCtxId ctxId, long maxStateSize) {
if (!sizeExceedsLimit && maxStateSize > 0 && CalculatedFieldUtils.toProto(ctxId, this).getSerializedSize() > maxStateSize) {
arguments.clear();
sizeExceedsLimit = true;
}
}
// TODO: Create a new class field to not do this on each calculation.
private Map<String, GeofencingArgumentEntry> getGeofencingArguments() {
return arguments.entrySet()
.stream()
.filter(entry -> !coordinateKeys.contains(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, entry -> (GeofencingArgumentEntry) entry.getValue()));
}
}