Files
Heimdall/src/Heimdall.Domain/Entities/Person.cs
T
arnaud.dartois 636154572b
Heimdall Gitea / Detect CI scope (push) Successful in 6s
Heimdall Gitea / Build and tests (push) Successful in 19m19s
Heimdall Gitea / Publish versioned release (push) Skipped
Heimdall Gitea / Build and scan server image (push) Successful in 6m13s
Heimdall Gitea / Build and scan agent image (push) Successful in 14m44s
Heimdall Gitea / Publish Docker Hub latest tags (push) Successful in 1m48s
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Successful in 19m9s
Heimdall Gitea / CI policy (push) Successful in 10s
Complete remaining Heimdall features and acceptance
Merge pull request #138

Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-06 11:14:49 +01:00

86 lines
3.1 KiB
C#

using Heimdall.Domain.Primitives;
namespace Heimdall.Domain.Entities;
/// <summary>
/// A person of interest — known individual monitored by the system.
/// Can be a family member, employee, or person on a watchlist.
/// Associated with detection events via face recognition (EventType.FaceRecognized).
/// </summary>
public class Person : Entity<Guid>, IAuditableEntity
{
public string DisplayName { get; private set; } = string.Empty;
public string? Notes { get; private set; }
public string? PhotoUrl { get; private set; } // Main portrait photo
public string? Category { get; private set; } // family, employee, watchlist, unknown
public bool IsWatchlisted { get; private set; }
public DateTime CreatedAt { get; set; }
public DateTime UpdatedAt { get; set; }
// Navigation
private readonly List<KnownFace> _faces = [];
public IReadOnlyCollection<KnownFace> Faces => _faces.AsReadOnly();
private Person() { } // EF Core
public Person(string displayName, string? category = null)
: base(Guid.NewGuid())
{
DisplayName = displayName;
Category = category;
}
public void Update(string displayName, string? notes, string? category, bool isWatchlisted)
{
DisplayName = displayName;
Notes = notes;
Category = category;
IsWatchlisted = isWatchlisted;
}
public void SetPhoto(string photoUrl) => PhotoUrl = photoUrl;
public void AddFace(KnownFace face) => _faces.Add(face);
}
/// <summary>
/// A registered face encoding for a known person.
/// Stored as a float array (128-d embedding from a face recognition model).
/// </summary>
public class KnownFace : Entity<Guid>
{
public const int MaxEmbeddingDimensions = 4096;
public Guid PersonId { get; private set; }
public string? ThumbnailUrl { get; private set; }
public float[] Embedding { get; private set; } = [];
public string? SourceEventId { get; private set; }
// Navigation
public Person Person { get; private set; } = null!;
private KnownFace() { } // EF Core
public KnownFace(Guid personId, float[] embedding, string? thumbnailUrl = null, string? sourceEventId = null)
: base(Guid.NewGuid())
{
if (personId == Guid.Empty)
throw new ArgumentException("Person ID is required.", nameof(personId));
if (!IsValidEmbedding(embedding))
throw new ArgumentException($"Embedding must contain between 1 and {MaxEmbeddingDimensions} finite values.", nameof(embedding));
if (thumbnailUrl?.Length > 2000)
throw new ArgumentException("Thumbnail URL exceeds the maximum length.", nameof(thumbnailUrl));
if (sourceEventId?.Length > 100)
throw new ArgumentException("Source event ID exceeds the maximum length.", nameof(sourceEventId));
PersonId = personId;
Embedding = embedding.ToArray();
ThumbnailUrl = thumbnailUrl;
SourceEventId = sourceEventId;
}
public static bool IsValidEmbedding(float[]? embedding) =>
embedding is { Length: > 0 and <= MaxEmbeddingDimensions } &&
embedding.All(float.IsFinite);
}