add MediaHash. Step1

This commit is contained in:
Oleksandr Bezdieniezhnykh
2025-11-17 07:46:05 +02:00
parent d355f81c63
commit fd95d2ba2c
27 changed files with 421 additions and 288 deletions
+13 -16
View File
@@ -22,18 +22,19 @@ public class Annotation
DetectionClassesDict = detectionClassesDict;
}
[Key("n")] public string Name { get; set; } = null!;
[Key("mn")] public string OriginalMediaName { get; set; } = null!;
[IgnoreMember]public TimeSpan Time { get; set; }
[IgnoreMember]public string ImageExtension { get; set; } = null!;
[IgnoreMember]public DateTime CreatedDate { get; set; }
[IgnoreMember]public string CreatedEmail { get; set; } = null!;
[IgnoreMember]public RoleEnum CreatedRole { get; set; }
[IgnoreMember]public SourceEnum Source { get; set; }
[IgnoreMember]public AnnotationStatus AnnotationStatus { get; set; }
[Key("n")] public string Name { get; set; } = null!;
[Key("hash")] public string MediaHash { get; set; } = null!;
[Key("mn")] public string OriginalMediaName { get; set; } = null!;
[IgnoreMember] public TimeSpan Time { get; set; }
[IgnoreMember] public string ImageExtension { get; set; } = null!;
[IgnoreMember] public DateTime CreatedDate { get; set; }
[IgnoreMember] public string CreatedEmail { get; set; } = null!;
[IgnoreMember] public RoleEnum CreatedRole { get; set; }
[IgnoreMember] public SourceEnum Source { get; set; }
[IgnoreMember] public AnnotationStatus AnnotationStatus { get; set; }
[IgnoreMember]public DateTime ValidateDate { get; set; }
[IgnoreMember]public string ValidateEmail { get; set; } = null!;
[IgnoreMember] public DateTime ValidateDate { get; set; }
[IgnoreMember] public string ValidateEmail { get; set; } = null!;
[Key("d")] public IEnumerable<Detection> Detections { get; set; } = null!;
[Key("t")] public long Milliseconds { get; set; }
@@ -93,13 +94,9 @@ public class Annotation
return _className;
}
}
#endregion Calculated
public override string ToString() => $"Annotation: {Name}{TimeStr}: {ClassName}";
}
[MessagePackObject]
@@ -17,15 +17,21 @@ public static class AnnotationsDbSchemaHolder
annotationBuilder.HasTableName(Constants.ANNOTATIONS_TABLENAME)
.HasPrimaryKey(x => x.Name)
.Association(a => a.Detections, (a, d) => a.Name == d.AnnotationName)
.Property(x => x.Time).HasDataType(DataType.Int64).HasConversion(ts => ts.Ticks, t => new TimeSpan(t));
.Property(x => x.Time)
.HasDataType(DataType.Int64)
.HasConversion(ts => ts.Ticks, t => new TimeSpan(t));
annotationBuilder
.Ignore(x => x.Milliseconds)
.Ignore(x => x.Classes)
.Ignore(x => x.Classes)
.Ignore(x => x.ImagePath)
.Ignore(x => x.LabelPath)
.Ignore(x => x.ThumbPath);
.Ignore(x => x.ThumbPath)
.Ignore(x => x.ClassName)
.Ignore(x => x.Colors)
.Ignore(x => x.SplitTile)
.Ignore(x => x.IsSplit)
.Ignore(x => x.TimeStr);
builder.Entity<Detection>()
.HasTableName(Constants.DETECTIONS_TABLENAME);
@@ -38,7 +44,11 @@ public static class AnnotationsDbSchemaHolder
.HasConversion(list => JsonConvert.SerializeObject(list), str => JsonConvert.DeserializeObject<List<string>>(str) ?? new List<string>());
builder.Entity<MediaFile>()
.HasTableName(Constants.MEDIAFILE_TABLENAME);
.HasTableName(Constants.MEDIAFILE_TABLENAME)
.HasPrimaryKey(x => x.Hash)
.Association(a => a.Annotations, (mf, a) =>
mf.Name == a.OriginalMediaName ||
mf.Hash == a.MediaHash);
builder.Build();
}
+4 -5
View File
@@ -44,11 +44,10 @@ public class DbFactory : IDbFactory
_memoryConnection = new SQLiteConnection(MemoryConnStr);
_memoryConnection.Open();
_memoryDataOptions = new DataOptions()
.UseDataProvider(SQLiteTools.GetDataProvider())
.UseConnection(_memoryConnection)
.UseMappingSchema(AnnotationsDbSchemaHolder.MappingSchema)
.UseTracing(TraceLevel.Info, t => logger.LogInformation(t.SqlText));
.UseDataProvider(SQLiteTools.GetDataProvider())
.UseConnection(_memoryConnection)
.UseMappingSchema(AnnotationsDbSchemaHolder.MappingSchema)
.UseTracing(TraceLevel.Info, t => logger.LogInformation(t.SqlText));
_fileConnection = new SQLiteConnection(FileConnStr);
_fileDataOptions = new DataOptions()
+36 -4
View File
@@ -1,12 +1,43 @@
using System.IO;
using Azaion.Common.Extensions;
using Azaion.Common.Services;
namespace Azaion.Common.Database;
public class MediaFile
{
public string Name { get; set; } = null!;
public string Hash { get; set; } = null!;
public string MediaUrl { get; set; } = null!;
public string Name { get; set; } = null!;
public DateTime? LastProcessedDate { get; set; }
public MediaStatus Status { get; set; } = MediaStatus.New;
public int? RecognisedObjects { get; set; }
public MediaTypes MediaType { get; set; } = MediaTypes.None;
public MediaStatus Status { get; set; } = MediaStatus.None;
public IEnumerable<Annotation> Annotations { get; set; } = null!;
public MediaFile() { }
public MediaFile(string path)
{
var fileInfo = new FileInfo(path);
var mediaType = Constants.DefaultVideoFormats.Contains(fileInfo.Extension, StringComparer.OrdinalIgnoreCase)
? MediaTypes.Video
: Constants.DefaultImageFormats.Contains(fileInfo.Extension, StringComparer.OrdinalIgnoreCase)
? MediaTypes.Image
: MediaTypes.None;
Hash = fileInfo.CalcHash();
MediaUrl = path;
Name = path.ToFName();
MediaType = mediaType;
Status = MediaStatus.New;
LastProcessedDate = null;
}
}
public enum MediaTypes
{
None = 0,
Video = 1,
Image = 2
}
public enum MediaStatus
@@ -15,6 +46,7 @@ public enum MediaStatus
New,
AIProcessing,
AIProcessed,
ManualConfirmed,
ManualCreated,
Confirmed,
Error
}