From 1287c13516a17d5fa54e2de967aa766b3f68a8b5 Mon Sep 17 00:00:00 2001 From: Alex Bezdieniezhnykh Date: Mon, 14 Apr 2025 19:43:14 +0300 Subject: [PATCH] fix ui bugs, fix RefreshThumbnails method --- Azaion.Common/Services/AnnotationService.cs | 3 +- Azaion.Common/Services/GalleryService.cs | 29 +++++++++++--- Azaion.Dataset/DatasetExplorerEventHandler.cs | 39 ++++++++++--------- Azaion.Suite/App.xaml.cs | 4 +- Azaion.Suite/postbuild.cmd | 14 ++++++- 5 files changed, 62 insertions(+), 27 deletions(-) diff --git a/Azaion.Common/Services/AnnotationService.cs b/Azaion.Common/Services/AnnotationService.cs index 5b528bf..30bad22 100644 --- a/Azaion.Common/Services/AnnotationService.cs +++ b/Azaion.Common/Services/AnnotationService.cs @@ -147,7 +147,7 @@ public class AnnotationService : INotificationHandler : AnnotationStatus.Created; await db.Detections.DeleteAsync(x => x.AnnotationName == fName, token: token); - await db.BulkCopyAsync(detections, cancellationToken: token); + if (ann != null) { await db.Annotations @@ -177,6 +177,7 @@ public class AnnotationService : INotificationHandler }; await db.InsertAsync(ann, token: token); } + await db.BulkCopyAsync(detections, cancellationToken: token); return ann; }); diff --git a/Azaion.Common/Services/GalleryService.cs b/Azaion.Common/Services/GalleryService.cs index 5331e6b..82616de 100644 --- a/Azaion.Common/Services/GalleryService.cs +++ b/Azaion.Common/Services/GalleryService.cs @@ -73,7 +73,7 @@ public class GalleryService( await _updateLock.WaitAsync(); var existingAnnotations = new ConcurrentDictionary(await dbFactory.Run(async db => await db.Annotations.ToDictionaryAsync(x => x.Name))); - var missedAnnotations = new ConcurrentBag(); + var missedAnnotations = new ConcurrentDictionary(); try { var prefixLen = Constants.THUMBNAIL_PREFIX.Length; @@ -89,7 +89,7 @@ public class GalleryService( await ParallelExt.ForEachAsync(files, async (file, cancellationToken) => { - var fName = Path.GetFileNameWithoutExtension(file.Name); + var fName = file.Name.ToFName(); try { var labelName = Path.Combine(_dirConfig.LabelsDirectory, $"{fName}.txt"); @@ -136,7 +136,7 @@ public class GalleryService( { Time = time, OriginalMediaName = originalMediaName, - Name = file.Name.ToFName(), + Name = fName, ImageExtension = Path.GetExtension(file.Name), Detections = detections, CreatedDate = File.GetCreationTimeUtc(file.FullName), @@ -146,8 +146,15 @@ public class GalleryService( AnnotationStatus = AnnotationStatus.Validated }; + //Remove duplicates if (!existingAnnotations.ContainsKey(fName)) - missedAnnotations.Add(annotation); + { + if (missedAnnotations.ContainsKey(fName)) + Console.WriteLine($"{fName} is already exists! Duplicate!"); + else + missedAnnotations.TryAdd(fName, annotation); + } + if (!thumbnails.Contains(fName)) await CreateThumbnail(annotation, cancellationToken); @@ -181,10 +188,20 @@ public class GalleryService( { MaxBatchSize = 50 }; + + //Db could be updated during the long files scraping + existingAnnotations = new ConcurrentDictionary(await dbFactory.Run(async db => + await db.Annotations.ToDictionaryAsync(x => x.Name))); + var insertedDuplicates = missedAnnotations.Where(x => existingAnnotations.ContainsKey(x.Key)).ToList(); + var annotationsToInsert = missedAnnotations + .Where(a => !existingAnnotations.ContainsKey(a.Key)) + .Select(x => x.Value) + .ToList(); + await dbFactory.Run(async db => { - await db.BulkCopyAsync(copyOptions, missedAnnotations); - await db.BulkCopyAsync(copyOptions, missedAnnotations.SelectMany(x => x.Detections)); + await db.BulkCopyAsync(copyOptions, annotationsToInsert); + await db.BulkCopyAsync(copyOptions, annotationsToInsert.SelectMany(x => x.Detections)); }); dbFactory.SaveToDisk(); _updateLock.Release(); diff --git a/Azaion.Dataset/DatasetExplorerEventHandler.cs b/Azaion.Dataset/DatasetExplorerEventHandler.cs index 03d69b8..09b41e4 100644 --- a/Azaion.Dataset/DatasetExplorerEventHandler.cs +++ b/Azaion.Dataset/DatasetExplorerEventHandler.cs @@ -1,6 +1,7 @@ using System.IO; using System.Windows; using System.Windows.Input; +using System.Windows.Threading; using Azaion.Common.DTO; using Azaion.Common.DTO.Queue; using Azaion.Common.Events; @@ -103,26 +104,28 @@ public class DatasetExplorerEventHandler( public async Task Handle(AnnotationCreatedEvent notification, CancellationToken cancellationToken) { - var annotation = notification.Annotation; - var selectedClass = datasetExplorer.LvClasses.CurrentClassNumber; - - //TODO: For editing existing need to handle updates - datasetExplorer.AddAnnotationToDict(annotation); - if (annotation.Classes.Contains(selectedClass) || selectedClass == -1) + datasetExplorer.Dispatcher.Invoke(async () => { - var annThumb = new AnnotationThumbnail(annotation); - if (datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name)) - { - datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name); - var ann = datasetExplorer.SelectedAnnotations.FirstOrDefault(x => x.Annotation.Name == annThumb.Annotation.Name); - if (ann != null) - datasetExplorer.SelectedAnnotations.Remove(ann); - } + var annotation = notification.Annotation; + var selectedClass = datasetExplorer.LvClasses.CurrentClassNumber; - datasetExplorer.SelectedAnnotations.Insert(0, annThumb); - datasetExplorer.SelectedAnnotationDict.Add(annThumb.Annotation.Name, annThumb); - } - await Task.CompletedTask; + //TODO: For editing existing need to handle updates + datasetExplorer.AddAnnotationToDict(annotation); + if (annotation.Classes.Contains(selectedClass) || selectedClass == -1) + { + var annThumb = new AnnotationThumbnail(annotation); + if (datasetExplorer.SelectedAnnotationDict.ContainsKey(annThumb.Annotation.Name)) + { + datasetExplorer.SelectedAnnotationDict.Remove(annThumb.Annotation.Name); + var ann = datasetExplorer.SelectedAnnotations.FirstOrDefault(x => x.Annotation.Name == annThumb.Annotation.Name); + if (ann != null) + datasetExplorer.SelectedAnnotations.Remove(ann); + } + + datasetExplorer.SelectedAnnotations.Insert(0, annThumb); + datasetExplorer.SelectedAnnotationDict.Add(annThumb.Annotation.Name, annThumb); + } + }); } public async Task Handle(AnnotationsDeletedEvent notification, CancellationToken cancellationToken) diff --git a/Azaion.Suite/App.xaml.cs b/Azaion.Suite/App.xaml.cs index b86517e..8ca24e1 100644 --- a/Azaion.Suite/App.xaml.cs +++ b/Azaion.Suite/App.xaml.cs @@ -173,7 +173,9 @@ public partial class App services.AddSingleton(_resourceLoader); services.AddSingleton(_authProvider); services.AddSingleton(); - + services.AddSingleton(); + services.AddSingleton(); + services.AddHttpClient(); #endregion services.AddSingleton(); diff --git a/Azaion.Suite/postbuild.cmd b/Azaion.Suite/postbuild.cmd index da1b574..7423da5 100644 --- a/Azaion.Suite/postbuild.cmd +++ b/Azaion.Suite/postbuild.cmd @@ -9,7 +9,19 @@ call upload-file %FILE1_TO_UPLOAD% %RESOURCES_FOLDER% set FILE2_TO_UPLOAD=%cd%\..\Azaion.Dataset\bin\%CONFIG%\net8.0-windows\Azaion.Dataset.dll call upload-file %FILE2_TO_UPLOAD% %RESOURCES_FOLDER% -set DESTINATION=%cd%\bin\Debug\net8.0-windows\gps-denied +set SUITE_FOLDER=%cd%\bin\%CONFIG%\net8.0-windows\ + +rem Inference + +set INFERENCE_PATH=%cd%\..\Azaion.Inference +xcopy /E %INFERENCE_PATH%\dist\azaion-inference %SUITE_FOLDER% +copy %INFERENCE_PATH%\venv\Lib\site-packages\tensorrt_libs\nvinfer_10.dll %SUITE_FOLDER% +copy %INFERENCE_PATH%\venv\Lib\site-packages\tensorrt_libs\nvinfer_plugin_10.dll %SUITE_FOLDER% +copy %INFERENCE_PATH%\venv\Lib\site-packages\tensorrt_libs\nvonnxparser_10.dll %SUITE_FOLDER% +copy %INFERENCE_PATH%\config.yaml %SUITE_FOLDER% + +rem Gps Denied +set DESTINATION=%SUITE_FOLDER%\gps-denied set GPS_DENIED=%cd%\..\..\gps-denied\ rmdir %DESTINATION% /s /q