Skip to content

Commit

Permalink
handle previews better
Browse files Browse the repository at this point in the history
  • Loading branch information
mlapaglia committed Jun 22, 2021
1 parent dab5d61 commit 116766d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
42 changes: 9 additions & 33 deletions OpenAlprWebhookProcessor/WebhookProcessor/GroupWebhookHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public GroupWebhookHandler(
public async Task HandleWebhookAsync(
Webhook webhook,
bool isBulkImport,
List<string> previouslyProcessedGroups,
CancellationToken cancellationToken)
{
var camera = await _processorContext.Cameras
Expand All @@ -68,41 +67,18 @@ public async Task HandleWebhookAsync(
return;
}

var alreadyProcessed = false;

if (previouslyProcessedGroups != null)
{
alreadyProcessed = previouslyProcessedGroups
.Intersect(webhook.Group.Uuids)
.Any();

if (!alreadyProcessed)
{
previouslyProcessedGroups.AddRange(webhook.Group.Uuids);
}
}
else
{
alreadyProcessed = await _processorContext.PlateGroups.Select(x => x.OpenAlprUuid)
.Intersect(webhook.Group.Uuids)
.AnyAsync(cancellationToken);
}

if (alreadyProcessed)
{
_logger.LogWarning("Duplicate group received, skipping: " + webhook.Group.BestUuid);
return;
}

var previousPreviewGroup = await _processorContext.PlateGroups
var previousPreviewGroups = await _processorContext.PlateGroups
.Where(x => webhook.Group.Uuids.Contains(x.OpenAlprUuid))
.FirstOrDefaultAsync(cancellationToken);
.ToListAsync(cancellationToken);

PlateGroup plateGroup;
if (previousPreviewGroup != null)
if (previousPreviewGroups.Count > 0)
{
_logger.LogInformation("Previous preview plate exists: " + previousPreviewGroup.BestNumber + ", overwriting");
plateGroup = previousPreviewGroup;
plateGroup = previousPreviewGroups[0];
_processorContext.PlateGroups.RemoveRange(previousPreviewGroups.Skip(1));

_logger.LogInformation("Previous preview plate exists: " + plateGroup.BestNumber + ", overwriting");

}
else
{
Expand All @@ -124,7 +100,7 @@ public async Task HandleWebhookAsync(

MapVehicle(plateGroup, webhook);

if (previousPreviewGroup == null)
if (previousPreviewGroups.Count == 0)
{
_processorContext.PlateGroups.Add(plateGroup);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ await newGroup.Content.ReadAsStreamAsync(cancellationToken),
continue;
}

var previouslyProcessedGroups = await _processorContext.PlateGroups
.Select(x => x.OpenAlprUuid)
.ToListAsync(cancellationToken);
try
{
await _groupWebhookHandler.HandleWebhookAsync(
Expand All @@ -104,7 +101,6 @@ await _groupWebhookHandler.HandleWebhookAsync(
Group = group,
},
true,
previouslyProcessedGroups,
cancellationToken);
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public async Task<ActionResult> Post(CancellationToken cancellationToken)
await _groupWebhookHandler.HandleWebhookAsync(
alertGroupResult,
false,
null,
cancellationToken);
}
else if (rawWebhook.Contains("alpr_group"))
Expand All @@ -62,7 +61,6 @@ await _groupWebhookHandler.HandleWebhookAsync(
await _groupWebhookHandler.HandleWebhookAsync(
groupResult,
false,
null,
cancellationToken);
}
else if (rawWebhook.Contains("alpr_results"))
Expand Down

0 comments on commit 116766d

Please sign in to comment.