add offset

fixes
add visual validation border and validate functionality
This commit is contained in:
Alex Bezdieniezhnykh
2024-12-28 15:51:27 +02:00
parent 5fe46cd6f5
commit 8b94837f18
27 changed files with 251 additions and 128 deletions
+13 -13
View File
@@ -151,7 +151,7 @@ public partial class Annotator
} }
}; };
LvFiles.MouseDoubleClick += async (_, _) => await _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Play)); LvFiles.MouseDoubleClick += async (_, _) => await _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Play));
LvClasses.SelectionChanged += (_, _) => LvClasses.SelectionChanged += (_, _) =>
{ {
@@ -238,7 +238,7 @@ public partial class Annotator
_appConfig.AnnotationConfig.LeftPanelWidth = MainGrid.ColumnDefinitions.FirstOrDefault()!.Width.Value; _appConfig.AnnotationConfig.LeftPanelWidth = MainGrid.ColumnDefinitions.FirstOrDefault()!.Width.Value;
_appConfig.AnnotationConfig.RightPanelWidth = MainGrid.ColumnDefinitions.LastOrDefault()!.Width.Value; _appConfig.AnnotationConfig.RightPanelWidth = MainGrid.ColumnDefinitions.LastOrDefault()!.Width.Value;
await ThrottleExt.Throttle(() => await ThrottleExt.ThrottleRunFirst(() =>
{ {
_configUpdater.Save(_appConfig); _configUpdater.Save(_appConfig);
return Task.CompletedTask; return Task.CompletedTask;
@@ -478,21 +478,21 @@ public partial class Annotator
private void PlayClick(object sender, RoutedEventArgs e) private void PlayClick(object sender, RoutedEventArgs e)
{ {
_mediator.Publish(new PlaybackControlEvent(_mediaPlayer.CanPause ? PlaybackControlEnum.Pause : PlaybackControlEnum.Play)); _mediator.Publish(new AnnotatorControlEvent(_mediaPlayer.CanPause ? PlaybackControlEnum.Pause : PlaybackControlEnum.Play));
} }
private void PauseClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Pause)); private void PauseClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Pause));
private void StopClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Stop)); private void StopClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Stop));
private void PreviousFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.PreviousFrame)); private void PreviousFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.PreviousFrame));
private void NextFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.NextFrame)); private void NextFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.NextFrame));
private void SaveAnnotationsClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.SaveAnnotations)); private void SaveAnnotationsClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.SaveAnnotations));
private void RemoveSelectedClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.RemoveSelectedAnns)); private void RemoveSelectedClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.RemoveSelectedAnns));
private void RemoveAllClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.RemoveAllAnns)); private void RemoveAllClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.RemoveAllAnns));
private void TurnOffVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOffVolume)); private void TurnOffVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.TurnOffVolume));
private void TurnOnVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOnVolume)); private void TurnOnVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.TurnOnVolume));
private void OpenHelpWindowClick(object sender, RoutedEventArgs e) private void OpenHelpWindowClick(object sender, RoutedEventArgs e)
{ {
@@ -517,7 +517,7 @@ public partial class Annotator
if (LvFiles.SelectedIndex == -1) if (LvFiles.SelectedIndex == -1)
LvFiles.SelectedIndex = 0; LvFiles.SelectedIndex = 0;
await _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Play)); await _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Play));
_mediaPlayer.SetPause(true); _mediaPlayer.SetPause(true);
var manualCancellationSource = new CancellationTokenSource(); var manualCancellationSource = new CancellationTokenSource();
+2 -2
View File
@@ -26,7 +26,7 @@ public class AnnotatorEventHandler(
: :
INotificationHandler<KeyEvent>, INotificationHandler<KeyEvent>,
INotificationHandler<AnnClassSelectedEvent>, INotificationHandler<AnnClassSelectedEvent>,
INotificationHandler<PlaybackControlEvent>, INotificationHandler<AnnotatorControlEvent>,
INotificationHandler<VolumeChangedEvent> INotificationHandler<VolumeChangedEvent>
{ {
private const int STEP = 20; private const int STEP = 20;
@@ -105,7 +105,7 @@ public class AnnotatorEventHandler(
#endregion #endregion
} }
public async Task Handle(PlaybackControlEvent notification, CancellationToken cancellationToken = default) public async Task Handle(AnnotatorControlEvent notification, CancellationToken cancellationToken = default)
{ {
await ControlPlayback(notification.PlaybackControl, cancellationToken); await ControlPlayback(notification.PlaybackControl, cancellationToken);
mainWindow.VideoView.Focus(); mainWindow.VideoView.Focus();
+1 -8
View File
@@ -1,14 +1,7 @@
using System.Windows.Input; using MediatR;
using Azaion.Common.DTO;
using MediatR;
namespace Azaion.Annotator.DTO; namespace Azaion.Annotator.DTO;
public class PlaybackControlEvent(PlaybackControlEnum playbackControlEnum) : INotification
{
public PlaybackControlEnum PlaybackControl { get; set; } = playbackControlEnum;
}
public class VolumeChangedEvent(int volume) : INotification public class VolumeChangedEvent(int volume) : INotification
{ {
public int Volume { get; set; } = volume; public int Volume { get; set; } = volume;
-3
View File
@@ -85,11 +85,8 @@ public class Constants
#region Queue #region Queue
public const string MQ_DIRECT_TYPE = "direct";
public const string MQ_ANNOTATIONS_QUEUE = "azaion-annotations"; public const string MQ_ANNOTATIONS_QUEUE = "azaion-annotations";
public const string MQ_ANNOTATIONS_CONFIRM_QUEUE = "azaion-annotations-confirm"; public const string MQ_ANNOTATIONS_CONFIRM_QUEUE = "azaion-annotations-confirm";
public const string ANNOTATION_PRODUCER = "AnnotationsProducer";
public const string ANNOTATION_CONFIRM_PRODUCER = "AnnotationsConfirmProducer";
#endregion #endregion
+2 -1
View File
@@ -1,4 +1,5 @@
using MediatR; using Azaion.Common.Database;
using MediatR;
namespace Azaion.Common.DTO; namespace Azaion.Common.DTO;
+2
View File
@@ -2,6 +2,7 @@
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using Azaion.Common.Database;
using Azaion.Common.Extensions; using Azaion.Common.Extensions;
namespace Azaion.Common.DTO; namespace Azaion.Common.DTO;
@@ -27,6 +28,7 @@ public class AnnotationImageView(Annotation annotation) : INotifyPropertyChanged
} }
public string ImageName => Path.GetFileName(Annotation.ImagePath); public string ImageName => Path.GetFileName(Annotation.ImagePath);
public bool IsSeed => Annotation.AnnotationStatus == AnnotationStatus.Created;
public void Delete() public void Delete()
{ {
@@ -0,0 +1,13 @@
using MediatR;
namespace Azaion.Common.DTO;
public class AnnotatorControlEvent(PlaybackControlEnum playbackControlEnum) : INotification
{
public PlaybackControlEnum PlaybackControl { get; set; } = playbackControlEnum;
}
public class DatasetExplorerControlEvent(PlaybackControlEnum playbackControlEnum) : INotification
{
public PlaybackControlEnum PlaybackControl { get; set; } = playbackControlEnum;
}
+1 -1
View File
@@ -186,7 +186,7 @@ public class YoloLabel : Label
public class Detection : YoloLabel public class Detection : YoloLabel
{ {
public string AnnotationName { get; set; } public string AnnotationName { get; set; } = null!;
public double? Probability { get; set; } public double? Probability { get; set; }
//For db //For db
+2 -1
View File
@@ -15,5 +15,6 @@ public enum PlaybackControlEnum
TurnOnVolume = 10, TurnOnVolume = 10,
Previous = 11, Previous = 11,
Next = 12, Next = 12,
Close = 13 Close = 13,
ValidateAnnotations = 15
} }
@@ -1,4 +1,5 @@
using Azaion.CommonSecurity.DTO; using Azaion.Common.Database;
using Azaion.CommonSecurity.DTO;
namespace Azaion.Common.DTO.Queue; namespace Azaion.Common.DTO.Queue;
using MessagePack; using MessagePack;
@@ -1,11 +1,10 @@
using System.IO; using System.IO;
using System.Windows.Media.Imaging; using Azaion.Common.DTO;
using Azaion.Common.DTO.Config; using Azaion.Common.DTO.Config;
using Azaion.Common.DTO.Queue; using Azaion.Common.DTO.Queue;
using Azaion.Common.Extensions;
using Azaion.CommonSecurity.DTO; using Azaion.CommonSecurity.DTO;
namespace Azaion.Common.DTO; namespace Azaion.Common.Database;
public class Annotation public class Annotation
{ {
@@ -47,8 +46,3 @@ public enum AnnotationStatus
Created = 10, Created = 10,
Validated = 20 Validated = 20
} }
public class AnnotationName
{
public string Name { get; set; } = null!;
}
+6
View File
@@ -0,0 +1,6 @@
namespace Azaion.Common.Database;
public class AnnotationName
{
public string Name { get; set; } = null!;
}
+1
View File
@@ -9,4 +9,5 @@ public class AnnotationsDb(DataOptions dataOptions) : DataConnection(dataOptions
public ITable<Annotation> Annotations => this.GetTable<Annotation>(); public ITable<Annotation> Annotations => this.GetTable<Annotation>();
public ITable<AnnotationName> AnnotationsQueue => this.GetTable<AnnotationName>(); public ITable<AnnotationName> AnnotationsQueue => this.GetTable<AnnotationName>();
public ITable<Detection> Detections => this.GetTable<Detection>(); public ITable<Detection> Detections => this.GetTable<Detection>();
public ITable<QueueOffset> QueueOffsets => this.GetTable<QueueOffset>();
} }
+15
View File
@@ -4,6 +4,7 @@ using System.IO;
using Azaion.Common.DTO; using Azaion.Common.DTO;
using Azaion.Common.DTO.Config; using Azaion.Common.DTO.Config;
using LinqToDB; using LinqToDB;
using LinqToDB.Data;
using LinqToDB.DataProvider.SQLite; using LinqToDB.DataProvider.SQLite;
using LinqToDB.Mapping; using LinqToDB.Mapping;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -63,6 +64,20 @@ public class DbFactory : IDbFactory
db.CreateTable<Annotation>(); db.CreateTable<Annotation>();
db.CreateTable<AnnotationName>(); db.CreateTable<AnnotationName>();
db.CreateTable<Detection>(); db.CreateTable<Detection>();
db.CreateTable<QueueOffset>();
db.QueueOffsets.BulkCopy(new List<QueueOffset>
{
new()
{
Offset = 0,
QueueName = Constants.MQ_ANNOTATIONS_QUEUE
},
new()
{
Offset = 0,
QueueName = Constants.MQ_ANNOTATIONS_CONFIRM_QUEUE
}
});
} }
public async Task<T> Run<T>(Func<AnnotationsDb, Task<T>> func) public async Task<T> Run<T>(Func<AnnotationsDb, Task<T>> func)
+7
View File
@@ -0,0 +1,7 @@
namespace Azaion.Common.Database;
public class QueueOffset
{
public string QueueName { get; set; } = null!;
public ulong Offset { get; set; }
}
+21 -5
View File
@@ -2,18 +2,34 @@
public static class ThrottleExt public static class ThrottleExt
{ {
private static bool _throttleOn; private static bool _throttleRunFirstOn;
public static async Task Throttle(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default) public static async Task ThrottleRunFirst(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default)
{ {
if (_throttleOn) if (_throttleRunFirstOn)
return; return;
_throttleOn = true; _throttleRunFirstOn = true;
await func(); await func();
_ = Task.Run(async () => _ = Task.Run(async () =>
{ {
await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500), cancellationToken); await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500), cancellationToken);
_throttleOn = false; _throttleRunFirstOn = false;
}, cancellationToken); }, cancellationToken);
} }
private static bool _throttleRunAfter;
public static async Task ThrottleRunAfter(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default)
{
if (_throttleRunAfter)
return;
_throttleRunAfter = true;
_ = Task.Run(async () =>
{
await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500), cancellationToken);
await func();
_throttleRunAfter = false;
}, cancellationToken);
}
} }
+40 -15
View File
@@ -5,6 +5,7 @@ using Azaion.Common.Database;
using Azaion.Common.DTO; using Azaion.Common.DTO;
using Azaion.Common.DTO.Config; using Azaion.Common.DTO.Config;
using Azaion.Common.DTO.Queue; using Azaion.Common.DTO.Queue;
using Azaion.Common.Extensions;
using Azaion.CommonSecurity.DTO; using Azaion.CommonSecurity.DTO;
using Azaion.CommonSecurity.Services; using Azaion.CommonSecurity.Services;
using LinqToDB; using LinqToDB;
@@ -25,6 +26,7 @@ public class AnnotationService
private readonly FailsafeAnnotationsProducer _producer; private readonly FailsafeAnnotationsProducer _producer;
private readonly IGalleryService _galleryService; private readonly IGalleryService _galleryService;
private readonly IMediator _mediator; private readonly IMediator _mediator;
private readonly IHardwareService _hardwareService;
private readonly QueueConfig _queueConfig; private readonly QueueConfig _queueConfig;
private Consumer _consumer = null!; private Consumer _consumer = null!;
@@ -33,19 +35,21 @@ public class AnnotationService
FailsafeAnnotationsProducer producer, FailsafeAnnotationsProducer producer,
IOptions<QueueConfig> queueConfig, IOptions<QueueConfig> queueConfig,
IGalleryService galleryService, IGalleryService galleryService,
IMediator mediator) IMediator mediator,
IHardwareService hardwareService)
{ {
_apiClient = apiClient; _apiClient = apiClient;
_dbFactory = dbFactory; _dbFactory = dbFactory;
_producer = producer; _producer = producer;
_galleryService = galleryService; _galleryService = galleryService;
_mediator = mediator; _mediator = mediator;
_hardwareService = hardwareService;
_queueConfig = queueConfig.Value; _queueConfig = queueConfig.Value;
Task.Run(async () => await Init()).Wait(); Task.Run(async () => await Init()).Wait();
} }
private async Task Init() private async Task Init(CancellationToken cancellationToken = default)
{ {
var consumerSystem = await StreamSystem.Create(new StreamSystemConfig var consumerSystem = await StreamSystem.Create(new StreamSystemConfig
{ {
@@ -53,11 +57,28 @@ public class AnnotationService
UserName = _queueConfig.ConsumerUsername, UserName = _queueConfig.ConsumerUsername,
Password = _queueConfig.ConsumerPassword Password = _queueConfig.ConsumerPassword
}); });
var offset = (await _dbFactory.Run(db => db.QueueOffsets.FirstOrDefaultAsync(
x => x.QueueName == Constants.MQ_ANNOTATIONS_QUEUE, token: cancellationToken))
)?.Offset ?? 0;
_consumer = await Consumer.Create(new ConsumerConfig(consumerSystem, Constants.MQ_ANNOTATIONS_QUEUE) _consumer = await Consumer.Create(new ConsumerConfig(consumerSystem, Constants.MQ_ANNOTATIONS_QUEUE)
{ {
OffsetSpec = new OffsetTypeFirst(), Reference = _hardwareService.GetHardware().Hash,
MessageHandler = async (stream, _, _, message) => OffsetSpec = new OffsetTypeOffset(offset + 1),
await Consume(MessagePackSerializer.Deserialize<AnnotationCreatedMessage>(message.Data.Contents)), MessageHandler = async (stream, consumer, context, message) =>
{
await Consume(MessagePackSerializer.Deserialize<AnnotationCreatedMessage>(message.Data.Contents), cancellationToken);
await _dbFactory.Run(async db => await db.QueueOffsets
.Where(x => x.QueueName == Constants.MQ_ANNOTATIONS_QUEUE)
.Set(x => x.Offset, context.Offset)
.UpdateAsync(token: cancellationToken));
await ThrottleExt.ThrottleRunAfter(() =>
{
_dbFactory.SaveToDisk();
return Task.CompletedTask;
}, TimeSpan.FromSeconds(3), cancellationToken);
}
}); });
} }
@@ -65,6 +86,10 @@ public class AnnotationService
public async Task SaveAnnotation(string fName, string imageExtension, List<Detection> detections, SourceEnum source, Stream? stream = null, CancellationToken token = default) => public async Task SaveAnnotation(string fName, string imageExtension, List<Detection> detections, SourceEnum source, Stream? stream = null, CancellationToken token = default) =>
await SaveAnnotationInner(DateTime.UtcNow, fName, imageExtension, detections, source, stream, _apiClient.User.Role, _apiClient.User.Email, token); await SaveAnnotationInner(DateTime.UtcNow, fName, imageExtension, detections, source, stream, _apiClient.User.Role, _apiClient.User.Email, token);
//Manual
public async Task ValidateAnnotation(Annotation annotation, CancellationToken token = default) =>
await SaveAnnotationInner(DateTime.UtcNow, annotation.Name, annotation.ImageExtension, annotation.Detections.ToList(), SourceEnum.Manual, null, _apiClient.User.Role, _apiClient.User.Email, token);
//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)
{ {
@@ -84,24 +109,20 @@ public class AnnotationService
} }
private async Task SaveAnnotationInner(DateTime createdDate, string fName, string imageExtension, List<Detection> detections, SourceEnum source, Stream? stream, private async Task SaveAnnotationInner(DateTime createdDate, string fName, string imageExtension, List<Detection> detections, SourceEnum source, Stream? stream,
RoleEnum createdRole, RoleEnum userRole,
string createdEmail, string createdEmail,
CancellationToken token = default) CancellationToken token = default)
{ {
//Flow for roles: //Flow for roles:
// Operator: // Operator or (AI from any role) -> Created
// sourceEnum: (manual, ai) <AnnotationCreatedMessage> // Validator, Admin & Manual -> Validated
// Validator:
// sourceEnum: (manual) if was in received.json then <AnnotationValidatedMessage> else <AnnotationCreatedMessage>
// sourceEnum: (queue, AI) if queue CreatedMessage with the same user - do nothing Add to received.json
var classes = detections.Select(x => x.ClassNumber).Distinct().ToList() ?? [];
AnnotationStatus status; AnnotationStatus status;
var annotation = await _dbFactory.Run(async db => var annotation = await _dbFactory.Run(async db =>
{ {
var ann = await db.Annotations.FirstOrDefaultAsync(x => x.Name == fName, token: token); var ann = await db.Annotations.FirstOrDefaultAsync(x => x.Name == fName, token: token);
status = ann?.AnnotationStatus == AnnotationStatus.Created && createdRole == RoleEnum.Validator status = userRole.IsValidator() && source == SourceEnum.Manual
? AnnotationStatus.Validated ? AnnotationStatus.Validated
: AnnotationStatus.Created; : AnnotationStatus.Created;
@@ -110,7 +131,6 @@ public class AnnotationService
if (ann != null) if (ann != null)
await db.Annotations await db.Annotations
.Where(x => x.Name == fName) .Where(x => x.Name == fName)
.Set(x => x.Classes, classes)
.Set(x => x.Source, source) .Set(x => x.Source, source)
.Set(x => x.AnnotationStatus, status) .Set(x => x.AnnotationStatus, status)
.UpdateAsync(token: token); .UpdateAsync(token: token);
@@ -122,7 +142,7 @@ public class AnnotationService
Name = fName, Name = fName,
ImageExtension = imageExtension, ImageExtension = imageExtension,
CreatedEmail = createdEmail, CreatedEmail = createdEmail,
CreatedRole = createdRole, CreatedRole = userRole,
AnnotationStatus = status, AnnotationStatus = status,
Source = source, Source = source,
Detections = detections Detections = detections
@@ -142,5 +162,10 @@ public class AnnotationService
await _producer.SendToQueue(annotation, token); await _producer.SendToQueue(annotation, token);
await _mediator.Publish(new AnnotationCreatedEvent(annotation), token); await _mediator.Publish(new AnnotationCreatedEvent(annotation), token);
await ThrottleExt.ThrottleRunAfter(() =>
{
_dbFactory.SaveToDisk();
return Task.CompletedTask;
}, TimeSpan.FromSeconds(5), token);
} }
} }
-5
View File
@@ -150,11 +150,6 @@ public class GalleryService(
}; };
await dbFactory.Run(async db => await dbFactory.Run(async db =>
{ {
var xx = missedAnnotations.GroupBy(x => x.Name)
.Where(gr => gr.Count() > 1)
.ToList();
foreach (var gr in xx)
Console.WriteLine(gr.Key);
await db.BulkCopyAsync(copyOptions, missedAnnotations); await db.BulkCopyAsync(copyOptions, missedAnnotations);
await db.BulkCopyAsync(copyOptions, missedAnnotations.SelectMany(x => x.Detections)); await db.BulkCopyAsync(copyOptions, missedAnnotations.SelectMany(x => x.Detections));
}); });
+9 -1
View File
@@ -1,4 +1,6 @@
namespace Azaion.CommonSecurity.DTO; using Azaion.Common.Extensions;
namespace Azaion.CommonSecurity.DTO;
public enum RoleEnum public enum RoleEnum
{ {
@@ -10,3 +12,9 @@ public enum RoleEnum
ResourceUploader = 50, //Uploading dll and ai models ResourceUploader = 50, //Uploading dll and ai models
ApiAdmin = 1000 //everything ApiAdmin = 1000 //everything
} }
public static class RoleEnumExtensions
{
public static bool IsValidator(this RoleEnum role) =>
role.In(RoleEnum.Validator, RoleEnum.Admin, RoleEnum.ApiAdmin);
}
@@ -4,6 +4,7 @@ public class SecurityConstants
{ {
public const string CONFIG_PATH = "config.json"; public const string CONFIG_PATH = "config.json";
public const string DUMMY_DIR = "dummy";
#region ApiConfig #region ApiConfig
public const string DEFAULT_API_URL = "https://api.azaion.com/"; public const string DEFAULT_API_URL = "https://api.azaion.com/";
@@ -31,7 +31,7 @@ public class ResourceLoader(AzaionApiClient api, ApiCredentials credentials) : I
{ {
Console.WriteLine(e); Console.WriteLine(e);
var currentLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!; var currentLocation = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
var dllPath = Path.Combine(currentLocation, "dummy", $"{assemblyName}.dll"); var dllPath = Path.Combine(currentLocation, SecurityConstants.DUMMY_DIR, $"{assemblyName}.dll");
return Assembly.LoadFile(dllPath); return Assembly.LoadFile(dllPath);
} }
} }
+38 -14
View File
@@ -13,6 +13,20 @@
<Window.Resources> <Window.Resources>
<DataTemplate x:Key="ThumbnailTemplate" DataType="{x:Type dto:AnnotationImageView}"> <DataTemplate x:Key="ThumbnailTemplate" DataType="{x:Type dto:AnnotationImageView}">
<Border BorderBrush="IndianRed" Padding="5">
<Border.Style>
<Style TargetType="Border">
<Setter Property="BorderThickness" Value="0"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding IsSeed}" Value="True">
<Setter Property="BorderThickness" Value="8"></Setter>
</DataTrigger>
<DataTrigger Binding="{Binding IsSeed}" Value="False">
<Setter Property="BorderThickness" Value="0"></Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Border.Style>
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition>
@@ -29,6 +43,7 @@
Foreground="LightGray" Foreground="LightGray"
Text="{Binding ImageName}" /> Text="{Binding ImageName}" />
</Grid> </Grid>
</Border>
</DataTemplate> </DataTemplate>
</Window.Resources> </Window.Resources>
@@ -109,20 +124,29 @@
</ItemsPanelTemplate> </ItemsPanelTemplate>
</StatusBar.ItemsPanel> </StatusBar.ItemsPanel>
<StatusBarItem Grid.Column="2" Background="Black"> <StatusBarItem Grid.Column="2" Background="Black">
<TextBlock Name="RefreshThumbCaption">База іконок:</TextBlock> <Button Name="ValidateBtn"
</StatusBarItem> Padding="2"
<StatusBarItem Grid.Column="3" Background="Black"> ToolTip="Підтвердити валідність. Клавіша: [A]"
<ProgressBar x:Name="RefreshThumbBar" Background="Black" BorderBrush="Black" Cursor="Hand"
Width="150" Click="ValidateAnnotationsClick">
Height="15" <StackPanel Orientation="Horizontal">
HorizontalAlignment="Stretch" <Image>
Background="#252525" <Image.Source>
BorderBrush="#252525" <DrawingImage>
Foreground="LightBlue" <DrawingImage.Drawing>
Maximum="100" <DrawingGroup ClipGeometry="M0,0 V320 H320 V0 H0 Z">
Minimum="0" <GeometryDrawing Brush="LightGray" Geometry="m30.71 7.29-6-6a1 1 0 0 0 -.71-.29h-2v8a2 2 0 0 1 -2 2h-8a2 2 0 0
Value="0"> 1 -2-2v-8h-6a3 3 0 0 0 -3 3v24a3 3 0 0 0 3 3h2v-9a3 3 0 0 1 3-3h14a3 3 0 0 1 3 3v9h2a3 3 0 0 0 3-3v-20a1 1 0 0 0 -.29-.71z" />
</ProgressBar> <GeometryDrawing Brush="LightGray" Geometry="m12 1h8v8h-8z" />
<GeometryDrawing Brush="LightGray" Geometry="m23 21h-14a1 1 0 0 0 -1 1v9h16v-9a1 1 0 0 0 -1-1z" />
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
<TextBlock Text="Підтвердити валідність" Foreground="White" Padding="8 0 0 0"></TextBlock>
</StackPanel>
</Button>
</StatusBarItem> </StatusBarItem>
<Separator Grid.Column="4"/> <Separator Grid.Column="4"/>
<StatusBarItem Grid.Column="5" Background="Black"> <StatusBarItem Grid.Column="5" Background="Black">
+30 -15
View File
@@ -1,5 +1,4 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
@@ -8,6 +7,8 @@ using Azaion.Common.Database;
using Azaion.Common.DTO; using Azaion.Common.DTO;
using Azaion.Common.DTO.Config; using Azaion.Common.DTO.Config;
using Azaion.Common.Services; using Azaion.Common.Services;
using Azaion.CommonSecurity.DTO;
using Azaion.CommonSecurity.Services;
using LinqToDB; using LinqToDB;
using MediatR; using MediatR;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@@ -26,13 +27,15 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
private Dictionary<int, List<Annotation>> _annotationsDict; private Dictionary<int, List<Annotation>> _annotationsDict;
public ObservableCollection<AnnotationImageView> SelectedAnnotations { get; set; } = new(); public ObservableCollection<AnnotationImageView> SelectedAnnotations { get; set; } = new();
private ObservableCollection<DetectionClass> AllAnnotationClasses { get; set; } = new(); public ObservableCollection<DetectionClass> AllAnnotationClasses { get; set; } = new();
public Dictionary<string, LabelInfo> LabelsCache { get; set; } = new(); private Dictionary<string, LabelInfo> LabelsCache { get; set; } = new();
private int _tempSelectedClassIdx = 0; private int _tempSelectedClassIdx = 0;
private readonly IGalleryService _galleryService; private readonly IGalleryService _galleryService;
private readonly IDbFactory _dbFactory; private readonly IDbFactory _dbFactory;
private readonly IMediator _mediator;
private readonly AzaionApiClient _apiClient;
public bool ThumbnailLoading { get; set; } public bool ThumbnailLoading { get; set; }
@@ -44,13 +47,17 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
ILogger<DatasetExplorer> logger, ILogger<DatasetExplorer> logger,
IGalleryService galleryService, IGalleryService galleryService,
FormState formState, FormState formState,
IDbFactory dbFactory) IDbFactory dbFactory,
IMediator mediator,
AzaionApiClient apiClient)
{ {
_directoriesConfig = directoriesConfig.Value; _directoriesConfig = directoriesConfig.Value;
_annotationConfig = annotationConfig.Value; _annotationConfig = annotationConfig.Value;
_logger = logger; _logger = logger;
_galleryService = galleryService; _galleryService = galleryService;
_dbFactory = dbFactory; _dbFactory = dbFactory;
_mediator = mediator;
_apiClient = apiClient;
InitializeComponent(); InitializeComponent();
Loaded += OnLoaded; Loaded += OnLoaded;
@@ -73,14 +80,11 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
ThumbnailsView.SelectionChanged += (_, _) => ThumbnailsView.SelectionChanged += (_, _) =>
{ {
StatusText.Text = $"Обрано: {ThumbnailsView.SelectedItems.Count} | {ThumbnailsView.SelectedIndex} / {SelectedAnnotations.Count}"; StatusText.Text = $"Обрано: {ThumbnailsView.SelectedItems.Count} | {ThumbnailsView.SelectedIndex} / {SelectedAnnotations.Count}";
ValidateBtn.Visibility = ThumbnailsView.SelectedItems.Cast<AnnotationImageView>().Any(x => x.IsSeed)
? Visibility.Visible
: Visibility.Hidden;
}; };
ExplorerEditor.GetTimeFunc = () => Constants.GetTime(CurrentAnnotation!.Annotation.ImagePath); ExplorerEditor.GetTimeFunc = () => Constants.GetTime(CurrentAnnotation!.Annotation.ImagePath);
galleryService.ThumbnailsUpdate += thumbnailsPercentage =>
{
Dispatcher.Invoke(() => RefreshThumbBar.Value = thumbnailsPercentage);
};
} }
private async void OnLoaded(object sender, RoutedEventArgs e) private async void OnLoaded(object sender, RoutedEventArgs e)
@@ -135,7 +139,6 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
await ReloadThumbnails(); await ReloadThumbnails();
await LoadClassDistribution(); await LoadClassDistribution();
RefreshThumbBar.Value = _galleryService.ProcessedThumbnailsPercentage;
DataContext = this; DataContext = this;
} }
@@ -285,18 +288,30 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
SelectedAnnotations.Add(new AnnotationImageView(ann)); SelectedAnnotations.Add(new AnnotationImageView(ann));
} }
public async Task Handle(AnnotationCreatedEvent notification, CancellationToken cancellationToken)
private void AddThumbnail(Annotation annotation)
{ {
var annotation = notification.Annotation;
var selectedClass = ((DetectionClass?)LvClasses.SelectedItem)?.Id; var selectedClass = ((DetectionClass?)LvClasses.SelectedItem)?.Id;
if (selectedClass == null) if (selectedClass == null)
return; return;
//TODO: For editing existing need to handle updates
AddAnnotationToDict(annotation); AddAnnotationToDict(annotation);
if (annotation.Classes.Contains(selectedClass.Value)) if (annotation.Classes.Contains(selectedClass.Value))
{
SelectedAnnotations.Add(new AnnotationImageView(annotation)); SelectedAnnotations.Add(new AnnotationImageView(annotation));
} }
}
public async Task Handle(AnnotationCreatedEvent notification, CancellationToken cancellationToken) => private async void ValidateAnnotationsClick(object sender, RoutedEventArgs e)
AddThumbnail(notification.Annotation); {
try
{
await _mediator.Publish(new DatasetExplorerControlEvent(PlaybackControlEnum.ValidateAnnotations));
}
catch (Exception ex)
{
_logger.LogError(ex, ex.Message);
}
}
} }
+22 -7
View File
@@ -1,26 +1,32 @@
using System.IO; using System.IO;
using System.Windows.Input; using System.Windows.Input;
using Azaion.Common.DTO; using Azaion.Common.DTO;
using Azaion.Common.DTO.Config;
using Azaion.Common.DTO.Queue; using Azaion.Common.DTO.Queue;
using Azaion.Common.Services; using Azaion.Common.Services;
using MediatR; using MediatR;
using Microsoft.Extensions.Options;
namespace Azaion.Dataset; namespace Azaion.Dataset;
public class DatasetExplorerEventHandler( public class DatasetExplorerEventHandler(
DatasetExplorer datasetExplorer, DatasetExplorer datasetExplorer,
AnnotationService annotationService) : INotificationHandler<KeyEvent> AnnotationService annotationService)
: INotificationHandler<KeyEvent>,
INotificationHandler<DatasetExplorerControlEvent>
{ {
private readonly Dictionary<Key, PlaybackControlEnum> _keysControlEnumDict = new() private readonly Dictionary<Key, PlaybackControlEnum> _keysControlEnumDict = new()
{ {
{ Key.Enter, PlaybackControlEnum.SaveAnnotations }, { Key.Enter, PlaybackControlEnum.SaveAnnotations },
{ Key.Delete, PlaybackControlEnum.RemoveSelectedAnns }, { Key.Delete, PlaybackControlEnum.RemoveSelectedAnns },
{ Key.X, PlaybackControlEnum.RemoveAllAnns }, { Key.X, PlaybackControlEnum.RemoveAllAnns },
{ Key.Escape, PlaybackControlEnum.Close } { Key.Escape, PlaybackControlEnum.Close },
{ Key.A, PlaybackControlEnum.ValidateAnnotations}
}; };
public async Task Handle(DatasetExplorerControlEvent notification, CancellationToken cancellationToken)
{
await HandleControl(notification.PlaybackControl, cancellationToken);
}
public async Task Handle(KeyEvent keyEvent, CancellationToken cancellationToken) public async Task Handle(KeyEvent keyEvent, CancellationToken cancellationToken)
{ {
if (keyEvent.WindowEnum != WindowEnum.DatasetExplorer) if (keyEvent.WindowEnum != WindowEnum.DatasetExplorer)
@@ -37,11 +43,11 @@ public class DatasetExplorerEventHandler(
else else
{ {
if (datasetExplorer.Switcher.SelectedIndex == 1 && _keysControlEnumDict.TryGetValue(key, out var value)) if (datasetExplorer.Switcher.SelectedIndex == 1 && _keysControlEnumDict.TryGetValue(key, out var value))
await HandleControl(value); await HandleControl(value, cancellationToken);
} }
} }
private async Task HandleControl(PlaybackControlEnum controlEnum) private async Task HandleControl(PlaybackControlEnum controlEnum, CancellationToken cancellationToken = default)
{ {
switch (controlEnum) switch (controlEnum)
{ {
@@ -55,7 +61,7 @@ public class DatasetExplorerEventHandler(
var detections = datasetExplorer.ExplorerEditor.CurrentDetections var detections = datasetExplorer.ExplorerEditor.CurrentDetections
.Select(x => new Detection(fName, x.GetLabel(datasetExplorer.ExplorerEditor.RenderSize))) .Select(x => new Detection(fName, x.GetLabel(datasetExplorer.ExplorerEditor.RenderSize)))
.ToList(); .ToList();
await annotationService.SaveAnnotation(fName, extension, detections, SourceEnum.Manual); await annotationService.SaveAnnotation(fName, extension, detections, SourceEnum.Manual, token: cancellationToken);
datasetExplorer.SwitchTab(toEditor: false); datasetExplorer.SwitchTab(toEditor: false);
break; break;
case PlaybackControlEnum.RemoveSelectedAnns: case PlaybackControlEnum.RemoveSelectedAnns:
@@ -67,6 +73,15 @@ public class DatasetExplorerEventHandler(
case PlaybackControlEnum.Close: case PlaybackControlEnum.Close:
datasetExplorer.SwitchTab(toEditor: false); datasetExplorer.SwitchTab(toEditor: false);
break; break;
case PlaybackControlEnum.ValidateAnnotations:
var annotations = datasetExplorer.ThumbnailsView.SelectedItems.Cast<AnnotationImageView>()
.Select(x => x.Annotation)
.ToList();
foreach (var annotation in annotations)
{
await annotationService.ValidateAnnotation(annotation, cancellationToken);
}
break;
} }
} }
} }
+1 -8
View File
@@ -142,16 +142,9 @@ public partial class App
{ {
var args = (KeyEventArgs)e; var args = (KeyEventArgs)e;
var keyEvent = new KeyEvent(sender, args, _formState.ActiveWindow); var keyEvent = new KeyEvent(sender, args, _formState.ActiveWindow);
_ = ThrottleExt.Throttle(() => _mediator.Publish(keyEvent), TimeSpan.FromMilliseconds(50)); _ = ThrottleExt.ThrottleRunFirst(() => _mediator.Publish(keyEvent), TimeSpan.FromMilliseconds(50));
} }
private readonly Dictionary<string, WindowEnum> _uiElementToWindowEnum = new()
{
{ "LibVLCSharp.WPF.ForegroundWindow", WindowEnum.Annotator },
{ "Azaion.Annotator.Annotator", WindowEnum.Annotator },
{ "Azaion.Dataset.DatasetExplorer", WindowEnum.DatasetExplorer }
};
protected override async void OnExit(ExitEventArgs e) protected override async void OnExit(ExitEventArgs e)
{ {
base.OnExit(e); base.OnExit(e);
+2 -2
View File
@@ -118,11 +118,11 @@ public partial class MainSuite
private async Task SaveUserSettings() private async Task SaveUserSettings()
{ {
await ThrottleExt.Throttle(() => await ThrottleExt.ThrottleRunFirst(() =>
{ {
_configUpdater.Save(_appConfig); _configUpdater.Save(_appConfig);
return Task.CompletedTask; return Task.CompletedTask;
}, TimeSpan.FromSeconds(5)); }, TimeSpan.FromSeconds(2));
} }
private void OnFormClosed(object? sender, EventArgs e) private void OnFormClosed(object? sender, EventArgs e)