mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 12:26:30 +00:00
queue + local sqlite WIP
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System.IO;
|
||||
using Azaion.Common.DTO.Config;
|
||||
using Azaion.Common.DTO.Queue;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class Annotation
|
||||
{
|
||||
private static string _labelsDir = null!;
|
||||
private static string _imagesDir = null!;
|
||||
|
||||
public static void InitializeDirs(DirectoriesConfig config)
|
||||
{
|
||||
_labelsDir = config.LabelsDirectory;
|
||||
_imagesDir = config.ImagesDirectory;
|
||||
}
|
||||
|
||||
public string Name { get; set; } = null!;
|
||||
public DateTime CreatedDate { get; set; }
|
||||
public List<int> Classes { get; set; } = null!;
|
||||
public string CreatedEmail { get; set; } = null!;
|
||||
public RoleEnum CreatedRole { get; set; }
|
||||
public SourceEnum Source { get; set; }
|
||||
public AnnotationStatus AnnotationStatus { get; set; }
|
||||
|
||||
public string ImagePath => Path.Combine(_imagesDir, $"{Name}.jpg");
|
||||
public string LabelPath => Path.Combine(_labelsDir, $"{Name}.txt");
|
||||
|
||||
}
|
||||
|
||||
public enum AnnotationStatus
|
||||
{
|
||||
None = 0,
|
||||
Created = 10,
|
||||
Validated = 20
|
||||
}
|
||||
|
||||
public class AnnotationName
|
||||
{
|
||||
public string Name { get; set; } = null!;
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class ApiCredentials(string email, string password) : EventArgs
|
||||
{
|
||||
public string Email { get; set; } = email;
|
||||
public string Password { get; set; } = password;
|
||||
}
|
||||
@@ -15,4 +15,9 @@ public class AnnotationConfig
|
||||
|
||||
public List<string> VideoFormats { get; set; } = null!;
|
||||
public List<string> ImageFormats { get; set; } = null!;
|
||||
|
||||
public string AnnotationsDbFile { get; set; } = null!;
|
||||
|
||||
public double LeftPanelWidth { get; set; }
|
||||
public double RightPanelWidth { get; set; }
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Azaion.Common.DTO.Config;
|
||||
|
||||
public class AnnotatorWindowConfig
|
||||
{
|
||||
public double LeftPanelWidth { get; set; }
|
||||
public double RightPanelWidth { get; set; }
|
||||
public bool ShowHelpOnStart { get; set; }
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Azaion.Common.DTO.Config;
|
||||
|
||||
public class ApiConfig
|
||||
{
|
||||
public string Url { get; set; } = null!;
|
||||
public int RetryCount {get;set;}
|
||||
public double TimeoutSeconds { get; set; }
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Azaion.CommonSecurity;
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Azaion.Common.DTO.Config;
|
||||
@@ -8,12 +10,12 @@ public class AppConfig
|
||||
{
|
||||
public ApiConfig ApiConfig { get; set; } = null!;
|
||||
|
||||
public QueueConfig QueueConfig { get; set; } = null!;
|
||||
|
||||
public DirectoriesConfig DirectoriesConfig { get; set; } = null!;
|
||||
|
||||
public AnnotationConfig AnnotationConfig { get; set; } = null!;
|
||||
|
||||
public AnnotatorWindowConfig AnnotatorWindowConfig { get; set; } = null!;
|
||||
|
||||
public AIRecognitionConfig AIRecognitionConfig { get; set; } = null!;
|
||||
|
||||
public ThumbnailConfig ThumbnailConfig { get; set; } = null!;
|
||||
@@ -30,7 +32,7 @@ public class ConfigUpdater : IConfigUpdater
|
||||
public void CheckConfig()
|
||||
{
|
||||
var exePath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory)!;
|
||||
var configFilePath = Path.Combine(exePath, Constants.CONFIG_PATH);
|
||||
var configFilePath = Path.Combine(exePath, SecurityConstants.CONFIG_PATH);
|
||||
|
||||
if (File.Exists(configFilePath))
|
||||
return;
|
||||
@@ -39,9 +41,9 @@ public class ConfigUpdater : IConfigUpdater
|
||||
{
|
||||
ApiConfig = new ApiConfig
|
||||
{
|
||||
Url = Constants.DEFAULT_API_URL,
|
||||
RetryCount = Constants.DEFAULT_API_RETRY_COUNT,
|
||||
TimeoutSeconds = Constants.DEFAULT_API_TIMEOUT_SECONDS
|
||||
Url = SecurityConstants.DEFAULT_API_URL,
|
||||
RetryCount = SecurityConstants.DEFAULT_API_RETRY_COUNT,
|
||||
TimeoutSeconds = SecurityConstants.DEFAULT_API_TIMEOUT_SECONDS
|
||||
},
|
||||
|
||||
AnnotationConfig = new AnnotationConfig
|
||||
@@ -49,12 +51,11 @@ public class ConfigUpdater : IConfigUpdater
|
||||
AnnotationClasses = Constants.DefaultAnnotationClasses,
|
||||
VideoFormats = Constants.DefaultVideoFormats,
|
||||
ImageFormats = Constants.DefaultImageFormats,
|
||||
},
|
||||
|
||||
AnnotatorWindowConfig = new AnnotatorWindowConfig
|
||||
{
|
||||
LeftPanelWidth = Constants.DEFAULT_LEFT_PANEL_WIDTH,
|
||||
RightPanelWidth = Constants.DEFAULT_RIGHT_PANEL_WIDTH
|
||||
RightPanelWidth = Constants.DEFAULT_RIGHT_PANEL_WIDTH,
|
||||
|
||||
AnnotationsDbFile = Constants.DEFAULT_ANNOTATIONS_DB_FILE
|
||||
},
|
||||
|
||||
DirectoriesConfig = new DirectoriesConfig
|
||||
@@ -86,6 +87,6 @@ public class ConfigUpdater : IConfigUpdater
|
||||
|
||||
public void Save(AppConfig config)
|
||||
{
|
||||
File.WriteAllText(Constants.CONFIG_PATH, JsonConvert.SerializeObject(config, Formatting.Indented), Encoding.UTF8);
|
||||
File.WriteAllText(SecurityConstants.CONFIG_PATH, JsonConvert.SerializeObject(config, Formatting.Indented), Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Azaion.Common.DTO.Config;
|
||||
|
||||
public class QueueConfig
|
||||
{
|
||||
public string Host { get; set; } = null!;
|
||||
public int Port { get; set; }
|
||||
|
||||
public string ProducerUsername { get; set; } = null!;
|
||||
public string ProducerPassword { get; set; } = null!;
|
||||
|
||||
public string ConsumerUsername { get; set; } = null!;
|
||||
public string ConsumerPassword { get; set; } = null!;
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class HardwareInfo
|
||||
{
|
||||
public string CPU { get; set; } = null!;
|
||||
public string GPU { get; set; } = null!;
|
||||
public string MacAddress { get; set; } = null!;
|
||||
public string Memory { get; set; } = null!;
|
||||
|
||||
public string Hash { get; set; } = null!;
|
||||
}
|
||||
@@ -158,19 +158,25 @@ public class YoloLabel : Label
|
||||
public static async Task<List<YoloLabel>> ReadFromFile(string filename, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var str = await File.ReadAllTextAsync(filename, cancellationToken);
|
||||
|
||||
return str.Split('\n')
|
||||
.Select(Parse)
|
||||
.Where(ann => ann != null)
|
||||
.ToList()!;
|
||||
return Deserialize(str);
|
||||
}
|
||||
|
||||
public static async Task WriteToFile(IEnumerable<YoloLabel> labels, string filename, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var labelsStr = string.Join(Environment.NewLine, labels.Select(x => x.ToString()));
|
||||
var labelsStr = Serialize(labels);
|
||||
await File.WriteAllTextAsync(filename, labelsStr, cancellationToken);
|
||||
}
|
||||
|
||||
public static string Serialize(IEnumerable<YoloLabel> labels) =>
|
||||
string.Join(Environment.NewLine, labels.Select(x => x.ToString()));
|
||||
|
||||
public static List<YoloLabel> Deserialize(string str) =>
|
||||
str.Split('\n')
|
||||
.Select(Parse)
|
||||
.Where(ann => ann != null)
|
||||
.ToList()!;
|
||||
|
||||
|
||||
public override string ToString() => $"{ClassNumber} {CenterX:F5} {CenterY:F5} {Width:F5} {Height:F5}".Replace(',', '.');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class LoginResponse
|
||||
{
|
||||
public string Token { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Azaion.CommonSecurity.DTO;
|
||||
|
||||
namespace Azaion.Common.DTO.Queue;
|
||||
using MessagePack;
|
||||
|
||||
[MessagePackObject]
|
||||
public class AnnotationCreatedMessage
|
||||
{
|
||||
[Key(0)] public DateTime CreatedDate { get; set; }
|
||||
[Key(1)] public string Name { get; set; } = null!;
|
||||
[Key(2)] public string Label { get; set; } = null!;
|
||||
[Key(3)] public byte[] Image { get; set; } = null!;
|
||||
[Key(4)] public RoleEnum CreatedRole { get; set; }
|
||||
[Key(5)] public string CreatedEmail { get; set; } = null!;
|
||||
[Key(6)] public SourceEnum Source { get; set; }
|
||||
[Key(7)] public AnnotationStatus Status { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public class AnnotationValidatedMessage
|
||||
{
|
||||
[Key(0)] public string Name { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Azaion.Common.DTO.Queue;
|
||||
|
||||
public enum SourceEnum
|
||||
{
|
||||
AI,
|
||||
Manual
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public enum RoleEnum
|
||||
{
|
||||
None = 0,
|
||||
Operator = 10, //only annotator is available. Could send annotations to queue.
|
||||
Validator = 20, //annotator + dataset explorer. This role allows to receive annotations from the queue.
|
||||
CompanionPC = 30,
|
||||
Admin = 40, //
|
||||
ResourceUploader = 50, //Uploading dll and ai models
|
||||
ApiAdmin = 1000 //everything
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace Azaion.Common.DTO;
|
||||
|
||||
public class User
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
public RoleEnum Role { get; set; }
|
||||
|
||||
public User(IEnumerable<Claim> claims)
|
||||
{
|
||||
var claimDict = claims.ToDictionary(x => x.Type, x => x.Value);
|
||||
|
||||
Id = Guid.Parse(claimDict[Constants.CLAIM_NAME_ID]);
|
||||
Email = claimDict[Constants.CLAIM_EMAIL];
|
||||
if (!Enum.TryParse(claimDict[Constants.CLAIM_ROLE], out RoleEnum role))
|
||||
role = RoleEnum.None;
|
||||
Role = role;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user