mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 06:56:29 +00:00
add offset
fixes add visual validation border and validate functionality
This commit is contained in:
@@ -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 += (_, _) =>
|
||||
{
|
||||
@@ -238,7 +238,7 @@ public partial class Annotator
|
||||
_appConfig.AnnotationConfig.LeftPanelWidth = MainGrid.ColumnDefinitions.FirstOrDefault()!.Width.Value;
|
||||
_appConfig.AnnotationConfig.RightPanelWidth = MainGrid.ColumnDefinitions.LastOrDefault()!.Width.Value;
|
||||
|
||||
await ThrottleExt.Throttle(() =>
|
||||
await ThrottleExt.ThrottleRunFirst(() =>
|
||||
{
|
||||
_configUpdater.Save(_appConfig);
|
||||
return Task.CompletedTask;
|
||||
@@ -478,21 +478,21 @@ public partial class Annotator
|
||||
|
||||
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 StopClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Stop));
|
||||
private void PauseClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Pause));
|
||||
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 NextFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.NextFrame));
|
||||
private void PreviousFrameClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.PreviousFrame));
|
||||
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 RemoveAllClick(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.RemoveAllAnns));
|
||||
private void TurnOffVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOffVolume));
|
||||
private void TurnOnVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.TurnOnVolume));
|
||||
private void RemoveSelectedClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.RemoveSelectedAnns));
|
||||
private void RemoveAllClick(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.RemoveAllAnns));
|
||||
private void TurnOffVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.TurnOffVolume));
|
||||
private void TurnOnVolume(object sender, RoutedEventArgs e) => _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.TurnOnVolume));
|
||||
|
||||
private void OpenHelpWindowClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
@@ -517,7 +517,7 @@ public partial class Annotator
|
||||
if (LvFiles.SelectedIndex == -1)
|
||||
LvFiles.SelectedIndex = 0;
|
||||
|
||||
await _mediator.Publish(new PlaybackControlEvent(PlaybackControlEnum.Play));
|
||||
await _mediator.Publish(new AnnotatorControlEvent(PlaybackControlEnum.Play));
|
||||
_mediaPlayer.SetPause(true);
|
||||
|
||||
var manualCancellationSource = new CancellationTokenSource();
|
||||
|
||||
@@ -26,7 +26,7 @@ public class AnnotatorEventHandler(
|
||||
:
|
||||
INotificationHandler<KeyEvent>,
|
||||
INotificationHandler<AnnClassSelectedEvent>,
|
||||
INotificationHandler<PlaybackControlEvent>,
|
||||
INotificationHandler<AnnotatorControlEvent>,
|
||||
INotificationHandler<VolumeChangedEvent>
|
||||
{
|
||||
private const int STEP = 20;
|
||||
@@ -105,7 +105,7 @@ public class AnnotatorEventHandler(
|
||||
#endregion
|
||||
}
|
||||
|
||||
public async Task Handle(PlaybackControlEvent notification, CancellationToken cancellationToken = default)
|
||||
public async Task Handle(AnnotatorControlEvent notification, CancellationToken cancellationToken = default)
|
||||
{
|
||||
await ControlPlayback(notification.PlaybackControl, cancellationToken);
|
||||
mainWindow.VideoView.Focus();
|
||||
|
||||
@@ -1,14 +1,7 @@
|
||||
using System.Windows.Input;
|
||||
using Azaion.Common.DTO;
|
||||
using MediatR;
|
||||
using MediatR;
|
||||
|
||||
namespace Azaion.Annotator.DTO;
|
||||
|
||||
public class PlaybackControlEvent(PlaybackControlEnum playbackControlEnum) : INotification
|
||||
{
|
||||
public PlaybackControlEnum PlaybackControl { get; set; } = playbackControlEnum;
|
||||
}
|
||||
|
||||
public class VolumeChangedEvent(int volume) : INotification
|
||||
{
|
||||
public int Volume { get; set; } = volume;
|
||||
|
||||
@@ -85,11 +85,8 @@ public class Constants
|
||||
|
||||
#region Queue
|
||||
|
||||
public const string MQ_DIRECT_TYPE = "direct";
|
||||
public const string MQ_ANNOTATIONS_QUEUE = "azaion-annotations";
|
||||
public const string MQ_ANNOTATIONS_CONFIRM_QUEUE = "azaion-annotations-confirm";
|
||||
public const string ANNOTATION_PRODUCER = "AnnotationsProducer";
|
||||
public const string ANNOTATION_CONFIRM_PRODUCER = "AnnotationsConfirmProducer";
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediatR;
|
||||
using Azaion.Common.Database;
|
||||
using MediatR;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Azaion.Common.Database;
|
||||
using Azaion.Common.Extensions;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
@@ -27,6 +28,7 @@ public class AnnotationImageView(Annotation annotation) : INotifyPropertyChanged
|
||||
}
|
||||
|
||||
public string ImageName => Path.GetFileName(Annotation.ImagePath);
|
||||
public bool IsSeed => Annotation.AnnotationStatus == AnnotationStatus.Created;
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -186,7 +186,7 @@ public class YoloLabel : Label
|
||||
|
||||
public class Detection : YoloLabel
|
||||
{
|
||||
public string AnnotationName { get; set; }
|
||||
public string AnnotationName { get; set; } = null!;
|
||||
public double? Probability { get; set; }
|
||||
|
||||
//For db
|
||||
|
||||
@@ -15,5 +15,6 @@ public enum PlaybackControlEnum
|
||||
TurnOnVolume = 10,
|
||||
Previous = 11,
|
||||
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;
|
||||
using MessagePack;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System.IO;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.DTO.Queue;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
public class Annotation
|
||||
{
|
||||
@@ -46,9 +45,4 @@ public enum AnnotationStatus
|
||||
None = 0,
|
||||
Created = 10,
|
||||
Validated = 20
|
||||
}
|
||||
|
||||
public class AnnotationName
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
public class AnnotationName
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
}
|
||||
@@ -9,4 +9,5 @@ public class AnnotationsDb(DataOptions dataOptions) : DataConnection(dataOptions
|
||||
public ITable<Annotation> Annotations => this.GetTable<Annotation>();
|
||||
public ITable<AnnotationName> AnnotationsQueue => this.GetTable<AnnotationName>();
|
||||
public ITable<Detection> Detections => this.GetTable<Detection>();
|
||||
public ITable<QueueOffset> QueueOffsets => this.GetTable<QueueOffset>();
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using LinqToDB;
|
||||
using LinqToDB.Data;
|
||||
using LinqToDB.DataProvider.SQLite;
|
||||
using LinqToDB.Mapping;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -63,6 +64,20 @@ public class DbFactory : IDbFactory
|
||||
db.CreateTable<Annotation>();
|
||||
db.CreateTable<AnnotationName>();
|
||||
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)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Azaion.Common.Database;
|
||||
|
||||
public class QueueOffset
|
||||
{
|
||||
public string QueueName { get; set; } = null!;
|
||||
public ulong Offset { get; set; }
|
||||
}
|
||||
@@ -2,18 +2,34 @@
|
||||
|
||||
public static class ThrottleExt
|
||||
{
|
||||
private static bool _throttleOn;
|
||||
public static async Task Throttle(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default)
|
||||
private static bool _throttleRunFirstOn;
|
||||
public static async Task ThrottleRunFirst(this Func<Task> func, TimeSpan? throttleTime = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (_throttleOn)
|
||||
if (_throttleRunFirstOn)
|
||||
return;
|
||||
|
||||
_throttleOn = true;
|
||||
_throttleRunFirstOn = true;
|
||||
await func();
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(throttleTime ?? TimeSpan.FromMilliseconds(500), cancellationToken);
|
||||
_throttleOn = false;
|
||||
_throttleRunFirstOn = false;
|
||||
}, 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using Azaion.Common.Database;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.DTO.Queue;
|
||||
using Azaion.Common.Extensions;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using Azaion.CommonSecurity.Services;
|
||||
using LinqToDB;
|
||||
@@ -25,6 +26,7 @@ public class AnnotationService
|
||||
private readonly FailsafeAnnotationsProducer _producer;
|
||||
private readonly IGalleryService _galleryService;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IHardwareService _hardwareService;
|
||||
private readonly QueueConfig _queueConfig;
|
||||
private Consumer _consumer = null!;
|
||||
|
||||
@@ -33,19 +35,21 @@ public class AnnotationService
|
||||
FailsafeAnnotationsProducer producer,
|
||||
IOptions<QueueConfig> queueConfig,
|
||||
IGalleryService galleryService,
|
||||
IMediator mediator)
|
||||
IMediator mediator,
|
||||
IHardwareService hardwareService)
|
||||
{
|
||||
_apiClient = apiClient;
|
||||
_dbFactory = dbFactory;
|
||||
_producer = producer;
|
||||
_galleryService = galleryService;
|
||||
_mediator = mediator;
|
||||
_hardwareService = hardwareService;
|
||||
_queueConfig = queueConfig.Value;
|
||||
|
||||
Task.Run(async () => await Init()).Wait();
|
||||
}
|
||||
|
||||
private async Task Init()
|
||||
private async Task Init(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var consumerSystem = await StreamSystem.Create(new StreamSystemConfig
|
||||
{
|
||||
@@ -53,11 +57,28 @@ public class AnnotationService
|
||||
UserName = _queueConfig.ConsumerUsername,
|
||||
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)
|
||||
{
|
||||
OffsetSpec = new OffsetTypeFirst(),
|
||||
MessageHandler = async (stream, _, _, message) =>
|
||||
await Consume(MessagePackSerializer.Deserialize<AnnotationCreatedMessage>(message.Data.Contents)),
|
||||
Reference = _hardwareService.GetHardware().Hash,
|
||||
OffsetSpec = new OffsetTypeOffset(offset + 1),
|
||||
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) =>
|
||||
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)
|
||||
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,
|
||||
RoleEnum createdRole,
|
||||
RoleEnum userRole,
|
||||
string createdEmail,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
//Flow for roles:
|
||||
// Operator:
|
||||
// sourceEnum: (manual, ai) <AnnotationCreatedMessage>
|
||||
// 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
|
||||
// Operator or (AI from any role) -> Created
|
||||
// Validator, Admin & Manual -> Validated
|
||||
|
||||
var classes = detections.Select(x => x.ClassNumber).Distinct().ToList() ?? [];
|
||||
AnnotationStatus status;
|
||||
|
||||
var annotation = await _dbFactory.Run(async db =>
|
||||
{
|
||||
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.Created;
|
||||
|
||||
@@ -110,7 +131,6 @@ public class AnnotationService
|
||||
if (ann != null)
|
||||
await db.Annotations
|
||||
.Where(x => x.Name == fName)
|
||||
.Set(x => x.Classes, classes)
|
||||
.Set(x => x.Source, source)
|
||||
.Set(x => x.AnnotationStatus, status)
|
||||
.UpdateAsync(token: token);
|
||||
@@ -122,7 +142,7 @@ public class AnnotationService
|
||||
Name = fName,
|
||||
ImageExtension = imageExtension,
|
||||
CreatedEmail = createdEmail,
|
||||
CreatedRole = createdRole,
|
||||
CreatedRole = userRole,
|
||||
AnnotationStatus = status,
|
||||
Source = source,
|
||||
Detections = detections
|
||||
@@ -142,5 +162,10 @@ public class AnnotationService
|
||||
await _producer.SendToQueue(annotation, token);
|
||||
|
||||
await _mediator.Publish(new AnnotationCreatedEvent(annotation), token);
|
||||
await ThrottleExt.ThrottleRunAfter(() =>
|
||||
{
|
||||
_dbFactory.SaveToDisk();
|
||||
return Task.CompletedTask;
|
||||
}, TimeSpan.FromSeconds(5), token);
|
||||
}
|
||||
}
|
||||
@@ -150,11 +150,6 @@ public class GalleryService(
|
||||
};
|
||||
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.SelectMany(x => x.Detections));
|
||||
});
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace Azaion.CommonSecurity.DTO;
|
||||
using Azaion.Common.Extensions;
|
||||
|
||||
namespace Azaion.CommonSecurity.DTO;
|
||||
|
||||
public enum RoleEnum
|
||||
{
|
||||
@@ -10,3 +12,9 @@ public enum RoleEnum
|
||||
ResourceUploader = 50, //Uploading dll and ai models
|
||||
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 DUMMY_DIR = "dummy";
|
||||
#region ApiConfig
|
||||
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,22 +13,37 @@
|
||||
|
||||
<Window.Resources>
|
||||
<DataTemplate x:Key="ThumbnailTemplate" DataType="{x:Type dto:AnnotationImageView}">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
<RowDefinition Height="32"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Image
|
||||
Grid.Row="0"
|
||||
Source="{Binding Thumbnail}"
|
||||
Width="480"
|
||||
Height="270"
|
||||
Margin="2" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Foreground="LightGray"
|
||||
Text="{Binding ImageName}" />
|
||||
</Grid>
|
||||
<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.RowDefinitions>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
<RowDefinition Height="32"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
<Image
|
||||
Grid.Row="0"
|
||||
Source="{Binding Thumbnail}"
|
||||
Width="480"
|
||||
Height="270"
|
||||
Margin="2" />
|
||||
<TextBlock
|
||||
Grid.Row="1"
|
||||
Foreground="LightGray"
|
||||
Text="{Binding ImageName}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
</DataTemplate>
|
||||
</Window.Resources>
|
||||
|
||||
@@ -109,20 +124,29 @@
|
||||
</ItemsPanelTemplate>
|
||||
</StatusBar.ItemsPanel>
|
||||
<StatusBarItem Grid.Column="2" Background="Black">
|
||||
<TextBlock Name="RefreshThumbCaption">База іконок:</TextBlock>
|
||||
</StatusBarItem>
|
||||
<StatusBarItem Grid.Column="3" Background="Black">
|
||||
<ProgressBar x:Name="RefreshThumbBar"
|
||||
Width="150"
|
||||
Height="15"
|
||||
HorizontalAlignment="Stretch"
|
||||
Background="#252525"
|
||||
BorderBrush="#252525"
|
||||
Foreground="LightBlue"
|
||||
Maximum="100"
|
||||
Minimum="0"
|
||||
Value="0">
|
||||
</ProgressBar>
|
||||
<Button Name="ValidateBtn"
|
||||
Padding="2"
|
||||
ToolTip="Підтвердити валідність. Клавіша: [A]"
|
||||
Background="Black" BorderBrush="Black" Cursor="Hand"
|
||||
Click="ValidateAnnotationsClick">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<Image>
|
||||
<Image.Source>
|
||||
<DrawingImage>
|
||||
<DrawingImage.Drawing>
|
||||
<DrawingGroup ClipGeometry="M0,0 V320 H320 V0 H0 Z">
|
||||
<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
|
||||
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" />
|
||||
<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>
|
||||
<Separator Grid.Column="4"/>
|
||||
<StatusBarItem Grid.Column="5" Background="Black">
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
@@ -8,6 +7,8 @@ using Azaion.Common.Database;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.Services;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using Azaion.CommonSecurity.Services;
|
||||
using LinqToDB;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -26,13 +27,15 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
|
||||
private Dictionary<int, List<Annotation>> _annotationsDict;
|
||||
|
||||
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 readonly IGalleryService _galleryService;
|
||||
private readonly IDbFactory _dbFactory;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly AzaionApiClient _apiClient;
|
||||
|
||||
public bool ThumbnailLoading { get; set; }
|
||||
|
||||
@@ -44,13 +47,17 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
|
||||
ILogger<DatasetExplorer> logger,
|
||||
IGalleryService galleryService,
|
||||
FormState formState,
|
||||
IDbFactory dbFactory)
|
||||
IDbFactory dbFactory,
|
||||
IMediator mediator,
|
||||
AzaionApiClient apiClient)
|
||||
{
|
||||
_directoriesConfig = directoriesConfig.Value;
|
||||
_annotationConfig = annotationConfig.Value;
|
||||
_logger = logger;
|
||||
_galleryService = galleryService;
|
||||
_dbFactory = dbFactory;
|
||||
_mediator = mediator;
|
||||
_apiClient = apiClient;
|
||||
|
||||
InitializeComponent();
|
||||
Loaded += OnLoaded;
|
||||
@@ -73,14 +80,11 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
|
||||
ThumbnailsView.SelectionChanged += (_, _) =>
|
||||
{
|
||||
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);
|
||||
galleryService.ThumbnailsUpdate += thumbnailsPercentage =>
|
||||
{
|
||||
Dispatcher.Invoke(() => RefreshThumbBar.Value = thumbnailsPercentage);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
private async void OnLoaded(object sender, RoutedEventArgs e)
|
||||
@@ -135,7 +139,6 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
|
||||
await ReloadThumbnails();
|
||||
await LoadClassDistribution();
|
||||
|
||||
RefreshThumbBar.Value = _galleryService.ProcessedThumbnailsPercentage;
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
@@ -285,18 +288,30 @@ public partial class DatasetExplorer : INotificationHandler<AnnotationCreatedEve
|
||||
SelectedAnnotations.Add(new AnnotationImageView(ann));
|
||||
}
|
||||
|
||||
|
||||
private void AddThumbnail(Annotation annotation)
|
||||
public async Task Handle(AnnotationCreatedEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var annotation = notification.Annotation;
|
||||
var selectedClass = ((DetectionClass?)LvClasses.SelectedItem)?.Id;
|
||||
if (selectedClass == null)
|
||||
return;
|
||||
|
||||
//TODO: For editing existing need to handle updates
|
||||
AddAnnotationToDict(annotation);
|
||||
if (annotation.Classes.Contains(selectedClass.Value))
|
||||
{
|
||||
SelectedAnnotations.Add(new AnnotationImageView(annotation));
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Handle(AnnotationCreatedEvent notification, CancellationToken cancellationToken) =>
|
||||
AddThumbnail(notification.Annotation);
|
||||
}
|
||||
private async void ValidateAnnotationsClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _mediator.Publish(new DatasetExplorerControlEvent(PlaybackControlEnum.ValidateAnnotations));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,32 @@
|
||||
using System.IO;
|
||||
using System.Windows.Input;
|
||||
using Azaion.Common.DTO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.DTO.Queue;
|
||||
using Azaion.Common.Services;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Azaion.Dataset;
|
||||
|
||||
public class DatasetExplorerEventHandler(
|
||||
DatasetExplorer datasetExplorer,
|
||||
AnnotationService annotationService) : INotificationHandler<KeyEvent>
|
||||
AnnotationService annotationService)
|
||||
: INotificationHandler<KeyEvent>,
|
||||
INotificationHandler<DatasetExplorerControlEvent>
|
||||
{
|
||||
private readonly Dictionary<Key, PlaybackControlEnum> _keysControlEnumDict = new()
|
||||
{
|
||||
{ Key.Enter, PlaybackControlEnum.SaveAnnotations },
|
||||
{ Key.Delete, PlaybackControlEnum.RemoveSelectedAnns },
|
||||
{ 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)
|
||||
{
|
||||
if (keyEvent.WindowEnum != WindowEnum.DatasetExplorer)
|
||||
@@ -37,11 +43,11 @@ public class DatasetExplorerEventHandler(
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -55,7 +61,7 @@ public class DatasetExplorerEventHandler(
|
||||
var detections = datasetExplorer.ExplorerEditor.CurrentDetections
|
||||
.Select(x => new Detection(fName, x.GetLabel(datasetExplorer.ExplorerEditor.RenderSize)))
|
||||
.ToList();
|
||||
await annotationService.SaveAnnotation(fName, extension, detections, SourceEnum.Manual);
|
||||
await annotationService.SaveAnnotation(fName, extension, detections, SourceEnum.Manual, token: cancellationToken);
|
||||
datasetExplorer.SwitchTab(toEditor: false);
|
||||
break;
|
||||
case PlaybackControlEnum.RemoveSelectedAnns:
|
||||
@@ -67,6 +73,15 @@ public class DatasetExplorerEventHandler(
|
||||
case PlaybackControlEnum.Close:
|
||||
datasetExplorer.SwitchTab(toEditor: false);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,16 +142,9 @@ public partial class App
|
||||
{
|
||||
var args = (KeyEventArgs)e;
|
||||
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)
|
||||
{
|
||||
base.OnExit(e);
|
||||
|
||||
@@ -118,11 +118,11 @@ public partial class MainSuite
|
||||
|
||||
private async Task SaveUserSettings()
|
||||
{
|
||||
await ThrottleExt.Throttle(() =>
|
||||
await ThrottleExt.ThrottleRunFirst(() =>
|
||||
{
|
||||
_configUpdater.Save(_appConfig);
|
||||
return Task.CompletedTask;
|
||||
}, TimeSpan.FromSeconds(5));
|
||||
}, TimeSpan.FromSeconds(2));
|
||||
}
|
||||
|
||||
private void OnFormClosed(object? sender, EventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user