fix datasetexplorer view

save annotation with detections
fix sending to queue
This commit is contained in:
Alex Bezdieniezhnykh
2024-12-26 23:47:03 +02:00
parent 81dcb2a92e
commit 5fe46cd6f5
4 changed files with 24 additions and 15 deletions
+6 -1
View File
@@ -19,8 +19,13 @@ public class AnnotationImageView(Annotation annotation) : INotifyPropertyChanged
Task.Run(async () => Thumbnail = await Annotation.ThumbPath.OpenImage()); Task.Run(async () => Thumbnail = await Annotation.ThumbPath.OpenImage());
return _thumbnail; return _thumbnail;
} }
private set => _thumbnail = value; private set
{
_thumbnail = value;
OnPropertyChanged();
}
} }
public string ImageName => Path.GetFileName(Annotation.ImagePath); public string ImageName => Path.GetFileName(Annotation.ImagePath);
public void Delete() public void Delete()
+4 -1
View File
@@ -8,6 +8,7 @@ using Azaion.Common.DTO.Queue;
using Azaion.CommonSecurity.DTO; using Azaion.CommonSecurity.DTO;
using Azaion.CommonSecurity.Services; using Azaion.CommonSecurity.Services;
using LinqToDB; using LinqToDB;
using LinqToDB.Data;
using MediatR; using MediatR;
using MessagePack; using MessagePack;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@@ -67,7 +68,7 @@ public class AnnotationService
//Queue (only from operators) //Queue (only from operators)
public async Task Consume(AnnotationCreatedMessage message, CancellationToken cancellationToken = default) public async Task Consume(AnnotationCreatedMessage message, CancellationToken cancellationToken = default)
{ {
if (message.CreatedRole == RoleEnum.Validator) //Don't proceed our own messages (or from another Validator) if (message.CreatedRole != RoleEnum.Operator) //Process only operator's messages
return; return;
await SaveAnnotationInner( await SaveAnnotationInner(
@@ -104,6 +105,8 @@ public class AnnotationService
? AnnotationStatus.Validated ? AnnotationStatus.Validated
: AnnotationStatus.Created; : AnnotationStatus.Created;
await db.Detections.DeleteAsync(x => x.AnnotationName == fName, token: token);
await db.BulkCopyAsync(detections, cancellationToken: token);
if (ann != null) if (ann != null)
await db.Annotations await db.Annotations
.Where(x => x.Name == fName) .Where(x => x.Name == fName)
+13 -5
View File
@@ -65,13 +65,15 @@ public class FailsafeAnnotationsProducer
.Where(x => x.Status == AnnotationStatus.Created) .Where(x => x.Status == AnnotationStatus.Created)
.Select(x => new Message(MessagePackSerializer.Serialize(x))) .Select(x => new Message(MessagePackSerializer.Serialize(x)))
.ToList(); .ToList();
await _annotationProducer.Send(createdMessages, CompressionType.Gzip); if (createdMessages.Any())
await _annotationProducer.Send(createdMessages, CompressionType.Gzip);
var validatedMessages = messagesChunk var validatedMessages = messagesChunk
.Where(x => x.Status == AnnotationStatus.Validated) .Where(x => x.Status == AnnotationStatus.Validated)
.Select(x => new Message(MessagePackSerializer.Serialize(x))) .Select(x => new Message(MessagePackSerializer.Serialize(x)))
.ToList(); .ToList();
await _annotationConfirmProducer.Send(validatedMessages, CompressionType.Gzip); if (validatedMessages.Any())
await _annotationConfirmProducer.Send(validatedMessages, CompressionType.Gzip);
await _dbFactory.Run(async db => await _dbFactory.Run(async db =>
await db.AnnotationsQueue.DeleteAsync(aq => messagesChunk.Any(x => aq.Name == x.Name), token: cancellationToken)); await db.AnnotationsQueue.DeleteAsync(aq => messagesChunk.Any(x => aq.Name == x.Name), token: cancellationToken));
@@ -80,10 +82,12 @@ public class FailsafeAnnotationsProducer
catch (Exception e) catch (Exception e)
{ {
_logger.LogError(e, e.Message); _logger.LogError(e, e.Message);
await Task.Delay(TimeSpan.FromSeconds(30), cancellationToken); await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
} }
await Task.Delay(TimeSpan.FromSeconds(10), cancellationToken);
} }
} }
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
} }
} }
@@ -91,7 +95,8 @@ public class FailsafeAnnotationsProducer
{ {
return await _dbFactory.Run(async db => return await _dbFactory.Run(async db =>
{ {
var annotations = await db.AnnotationsQueue.Join(db.Annotations, aq => aq.Name, a => a.Name, (aq, a) => a) var annotations = await db.AnnotationsQueue.Join(
db.Annotations.LoadWith(x => x.Detections), aq => aq.Name, a => a.Name, (aq, a) => a)
.ToListAsync(token: cancellationToken); .ToListAsync(token: cancellationToken);
var messages = new List<AnnotationCreatedMessage>(); var messages = new List<AnnotationCreatedMessage>();
@@ -105,10 +110,13 @@ public class FailsafeAnnotationsProducer
CreatedRole = annotation.CreatedRole, CreatedRole = annotation.CreatedRole,
CreatedEmail = annotation.CreatedEmail, CreatedEmail = annotation.CreatedEmail,
CreatedDate = annotation.CreatedDate, CreatedDate = annotation.CreatedDate,
Status = annotation.AnnotationStatus,
ImageExtension = annotation.ImageExtension,
Image = image, Image = image,
Detections = JsonConvert.SerializeObject(annotation.Detections), Detections = JsonConvert.SerializeObject(annotation.Detections),
Source = annotation.Source Source = annotation.Source,
}; };
messages.Add(annCreateMessage); messages.Add(annCreateMessage);
} }
+1 -8
View File
@@ -118,14 +118,7 @@ public partial class App
services.AddSingleton<VLCFrameExtractor>(); services.AddSingleton<VLCFrameExtractor>();
services.AddSingleton<IDbFactory, DbFactory>(); services.AddSingleton<IDbFactory, DbFactory>();
services.AddHttpClient<AzaionApiClient>((sp, client) => services.AddSingleton<FailsafeAnnotationsProducer>();
{
var apiConfig = sp.GetRequiredService<IOptions<ApiConfig>>().Value;
client.BaseAddress = new Uri(apiConfig.Url);
client.Timeout = TimeSpan.FromSeconds(apiConfig.TimeoutSeconds);
});
services.AddSingleton<FailsafeAnnotationsProducer>();
services.AddSingleton<AnnotationService>(); services.AddSingleton<AnnotationService>();