mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 22:16:30 +00:00
75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
using System.IO;
|
|
using Azaion.Common.DTO;
|
|
using Azaion.Common.DTO.Config;
|
|
using Azaion.Common.DTO.Queue;
|
|
using Azaion.CommonSecurity.DTO;
|
|
|
|
namespace Azaion.Common.Database;
|
|
|
|
public class Annotation
|
|
{
|
|
private static string _labelsDir = null!;
|
|
private static string _imagesDir = null!;
|
|
private static string _thumbDir = null!;
|
|
|
|
public static void InitializeDirs(DirectoriesConfig config)
|
|
{
|
|
_labelsDir = config.LabelsDirectory;
|
|
_imagesDir = config.ImagesDirectory;
|
|
_thumbDir = config.ThumbnailsDirectory;
|
|
}
|
|
|
|
public string Name { get; set; } = null!;
|
|
public string ImageExtension { get; set; } = null!;
|
|
public DateTime CreatedDate { get; set; }
|
|
public string CreatedEmail { get; set; } = null!;
|
|
public RoleEnum CreatedRole { get; set; }
|
|
public SourceEnum Source { get; set; }
|
|
public AnnotationStatus AnnotationStatus { get; set; }
|
|
|
|
public IEnumerable<Detection> Detections { get; set; } = null!;
|
|
|
|
public double Lat { get; set; }
|
|
public double Lon { get; set; }
|
|
|
|
#region Calculated
|
|
public List<int> Classes => Detections.Select(x => x.ClassNumber).ToList();
|
|
public string ImagePath => Path.Combine(_imagesDir, $"{Name}{ImageExtension}");
|
|
public string LabelPath => Path.Combine(_labelsDir, $"{Name}.txt");
|
|
public string ThumbPath => Path.Combine(_thumbDir, $"{Name}{Constants.THUMBNAIL_PREFIX}.jpg");
|
|
public string OriginalMediaName => $"{Name[..^7]}";
|
|
|
|
private TimeSpan? _time;
|
|
public TimeSpan Time
|
|
{
|
|
get
|
|
{
|
|
if (_time.HasValue)
|
|
return _time.Value;
|
|
|
|
var timeStr = Name.Split("_").LastOrDefault();
|
|
|
|
//For some reason, TimeSpan.ParseExact doesn't work on every platform.
|
|
if (!string.IsNullOrEmpty(timeStr) &&
|
|
timeStr.Length == 6 &&
|
|
int.TryParse(timeStr[..1], out var hours) &&
|
|
int.TryParse(timeStr[1..3], out var minutes) &&
|
|
int.TryParse(timeStr[3..5], out var seconds) &&
|
|
int.TryParse(timeStr[5..], out var milliseconds))
|
|
return new TimeSpan(0, hours, minutes, seconds, milliseconds * 100);
|
|
|
|
_time = TimeSpan.FromSeconds(0);
|
|
return _time.Value;
|
|
}
|
|
}
|
|
#endregion Calculated
|
|
}
|
|
|
|
|
|
|
|
public enum AnnotationStatus
|
|
{
|
|
None = 0,
|
|
Created = 10,
|
|
Validated = 20
|
|
} |