From 924bd14c315a4778ae7d1c0631383478c871fb4e Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sun, 20 Oct 2024 17:49:48 -0700 Subject: [PATCH] FaceFile for D2 --- .vscode/tasks.json | 10 +++++ Shared/Models/FaceEncoding.cs | 11 +++++ Shared/Models/FaceFile.cs | 33 +++++++++++++++ Shared/Models/FacePoint.cs | 39 +++++++++++++++++ Shared/Models/Location.cs | 42 ++++++++++++++++++ Shared/Models/MappingFromPerson.cs | 24 +++++++++++ Shared/Models/OutputResolution.cs | 5 +++ Shared/Models/Properties/IFacePoint.cs | 10 +++++ Shared/Models/Properties/ILocation.cs | 12 ++++++ Shared/Models/Stateless/FacePart.cs | 54 ++++++++++++++++++++++++ Shared/Models/Stateless/Methods/IDate.cs | 5 +++ Shared/Models/Stateless/XDate.cs | 16 +++++++ 12 files changed, 261 insertions(+) create mode 100644 Shared/Models/FaceEncoding.cs create mode 100644 Shared/Models/FaceFile.cs create mode 100644 Shared/Models/FacePoint.cs create mode 100644 Shared/Models/Location.cs create mode 100644 Shared/Models/MappingFromPerson.cs create mode 100644 Shared/Models/OutputResolution.cs create mode 100644 Shared/Models/Properties/IFacePoint.cs create mode 100644 Shared/Models/Properties/ILocation.cs create mode 100644 Shared/Models/Stateless/FacePart.cs diff --git a/.vscode/tasks.json b/.vscode/tasks.json index af07f66..bc2fa86 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -13,6 +13,16 @@ ], "problemMatcher": "$msCompile" }, + { + "label": "Format-Whitespaces", + "command": "dotnet", + "type": "process", + "args": [ + "format", + "whitespace" + ], + "problemMatcher": "$msCompile" + }, { "label": "User Secrets Set", "command": "dotnet", diff --git a/Shared/Models/FaceEncoding.cs b/Shared/Models/FaceEncoding.cs new file mode 100644 index 0000000..e5c5360 --- /dev/null +++ b/Shared/Models/FaceEncoding.cs @@ -0,0 +1,11 @@ +using System.Text.Json.Serialization; + +namespace View_by_Distance.Shared.Models; + +public record FaceEncoding(double[] RawEncoding, int Size); + +[JsonSourceGenerationOptions(WriteIndented = false)] +[JsonSerializable(typeof(FaceEncoding))] +public partial class FaceEncodingGenerationContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/Shared/Models/FaceFile.cs b/Shared/Models/FaceFile.cs new file mode 100644 index 0000000..4f1a3ef --- /dev/null +++ b/Shared/Models/FaceFile.cs @@ -0,0 +1,33 @@ +using System.Text.Json.Serialization; + +namespace View_by_Distance.Shared.Models; + +public record FaceFile(int? AreaPermyriad, + int? ConfidencePercent, + string? DMS, + DateTime DateTime, + FaceEncoding? FaceEncoding, + Dictionary? FaceParts, + Location? Location, + string? Maker, + MappingFromPerson? MappingFromPerson, + string? Model, + OutputResolution? OutputResolution); + +[JsonSourceGenerationOptions(WriteIndented = false)] +[JsonSerializable(typeof(FaceFile))] +public partial class FaceFileGenerationContext : JsonSerializerContext +{ +} + +[JsonSourceGenerationOptions(WriteIndented = false, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +[JsonSerializable(typeof(FaceFile[]))] +public partial class FaceFileCollectionGenerationContext : JsonSerializerContext +{ +} + +[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)] +[JsonSerializable(typeof(FaceFile[]))] +public partial class FaceFileCollectionWriteIndentedGenerationContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/Shared/Models/FacePoint.cs b/Shared/Models/FacePoint.cs new file mode 100644 index 0000000..094577a --- /dev/null +++ b/Shared/Models/FacePoint.cs @@ -0,0 +1,39 @@ +using System.Drawing; +using System.Text.Json.Serialization; + +namespace View_by_Distance.Shared.Models; + +[method: JsonConstructor] +public class FacePoint(int index, int x, int y) : Properties.IFacePoint +{ + public int Index { get; } = index; + public int X { get; } = x; + public int Y { get; } = y; + + private readonly Point _Point = new(x, y); + + public override bool Equals(object? obj) => obj is FacePoint point && Equals(point); + +#pragma warning disable IDE0070 + public override int GetHashCode() +#pragma warning restore IDE0070 + { + int hashCode = 1861411795; + hashCode = (hashCode * -1521134295) + _Point.GetHashCode(); + hashCode = (hashCode * -1521134295) + Index.GetHashCode(); + return hashCode; + } + + public bool Equals(FacePoint? facePoint) + { + return facePoint is not null + && X == facePoint.X + && Y == facePoint.Y + && Index == facePoint.Index; + } + + public static bool operator ==(FacePoint point1, FacePoint point2) => point1.Equals(point2); + + public static bool operator !=(FacePoint point1, FacePoint point2) => !(point1 == point2); + +} \ No newline at end of file diff --git a/Shared/Models/Location.cs b/Shared/Models/Location.cs new file mode 100644 index 0000000..d94c7e0 --- /dev/null +++ b/Shared/Models/Location.cs @@ -0,0 +1,42 @@ +using System.Text.Json.Serialization; + +namespace View_by_Distance.Shared.Models; + +[method: JsonConstructor] +public class Location(int bottom, double confidence, int left, int right, int top) : Properties.ILocation, IEquatable +{ + + public int Bottom { init; get; } = bottom; + public double Confidence { init; get; } = confidence; + public int Left { init; get; } = left; + public int Right { init; get; } = right; + public int Top { init; get; } = top; + + public override bool Equals(object? obj) => Equals(obj as Location); + +#pragma warning disable IDE0070 + public override int GetHashCode() +#pragma warning restore IDE0070 + { + int hashCode = -773114317; + hashCode = (hashCode * -1521134295) + Bottom.GetHashCode(); + hashCode = (hashCode * -1521134295) + Left.GetHashCode(); + hashCode = (hashCode * -1521134295) + Right.GetHashCode(); + hashCode = (hashCode * -1521134295) + Top.GetHashCode(); + return hashCode; + } + + public bool Equals(Location? location) + { + return location is not null + && Bottom == location.Bottom + && Left == location.Left + && Right == location.Right + && Top == location.Top; + } + + public static bool operator ==(Location location1, Location location2) => EqualityComparer.Default.Equals(location1, location2); + + public static bool operator !=(Location location1, Location location2) => !(location1 == location2); + +} \ No newline at end of file diff --git a/Shared/Models/MappingFromPerson.cs b/Shared/Models/MappingFromPerson.cs new file mode 100644 index 0000000..a66bd80 --- /dev/null +++ b/Shared/Models/MappingFromPerson.cs @@ -0,0 +1,24 @@ +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace View_by_Distance.Shared.Models; + +public record MappingFromPerson(int? ApproximateYears, + string DisplayDirectoryName, + long PersonKey, + string SegmentB) +{ + + public override string ToString() + { + string result = JsonSerializer.Serialize(this, MappingFromPersonGenerationContext.Default.MappingFromPerson); + return result; + } + +} + +[JsonSourceGenerationOptions(WriteIndented = true)] +[JsonSerializable(typeof(MappingFromPerson))] +public partial class MappingFromPersonGenerationContext : JsonSerializerContext +{ +} \ No newline at end of file diff --git a/Shared/Models/OutputResolution.cs b/Shared/Models/OutputResolution.cs new file mode 100644 index 0000000..4a8c65b --- /dev/null +++ b/Shared/Models/OutputResolution.cs @@ -0,0 +1,5 @@ +namespace View_by_Distance.Shared.Models; + +public record OutputResolution(int Height, + int Orientation, + int Width); \ No newline at end of file diff --git a/Shared/Models/Properties/IFacePoint.cs b/Shared/Models/Properties/IFacePoint.cs new file mode 100644 index 0000000..90039cc --- /dev/null +++ b/Shared/Models/Properties/IFacePoint.cs @@ -0,0 +1,10 @@ +namespace View_by_Distance.Shared.Models.Properties; + +public interface IFacePoint +{ + + public int Index { get; } + public int X { get; } + public int Y { get; } + +} \ No newline at end of file diff --git a/Shared/Models/Properties/ILocation.cs b/Shared/Models/Properties/ILocation.cs new file mode 100644 index 0000000..cd8291f --- /dev/null +++ b/Shared/Models/Properties/ILocation.cs @@ -0,0 +1,12 @@ +namespace View_by_Distance.Shared.Models.Properties; + +public interface ILocation +{ + + public int Bottom { init; get; } + public double Confidence { init; get; } + public int Left { init; get; } + public int Right { init; get; } + public int Top { init; get; } + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/FacePart.cs b/Shared/Models/Stateless/FacePart.cs new file mode 100644 index 0000000..5d07928 --- /dev/null +++ b/Shared/Models/Stateless/FacePart.cs @@ -0,0 +1,54 @@ +namespace View_by_Distance.Shared.Models.Stateless; + +/// +/// Specifies the part of face. +/// +public enum FacePart +{ + + /// + /// Specifies the chin. + /// + Chin = 0, + + /// + /// Specifies the left eyebrow. + /// + LeftEyebrow = 17, + + /// + /// Specifies the right eyebrow. + /// + RightEyebrow = 22, + + /// + /// Specifies the nose bridge. + /// + NoseBridge = 27, + + /// + /// Specifies the nose tip. + /// + NoseTip = 31, + + /// + /// Specifies the left eye. + /// + LeftEye = 36, + + /// + /// Specifies the right eye. + /// + RightEye = 42, + + /// + /// Specifies the top lip. + /// + TopLip = 48, + + /// + /// Specifies the bottom lip. + /// + BottomLip = 55 + +} \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/IDate.cs b/Shared/Models/Stateless/Methods/IDate.cs index 0a7d5e6..b009605 100644 --- a/Shared/Models/Stateless/Methods/IDate.cs +++ b/Shared/Models/Stateless/Methods/IDate.cs @@ -13,6 +13,11 @@ public interface IDate static (int Season, string seasonName) GetSeason(int dayOfYear) => XDate.GetSeason(dayOfYear); + (int Season, string seasonName) TestStatic_GetSeasonAB(int dayOfYear) => + GetSeasonAB(dayOfYear); + static (int Season, string seasonName) GetSeasonAB(int dayOfYear) => + XDate.GetSeasonAB(dayOfYear); + DateTime? TestStatic_GetDateTimeOriginal(ExifDirectory exifDirectory) => GetDateTimeOriginal(exifDirectory); static DateTime? GetDateTimeOriginal(ExifDirectory exifDirectory) => diff --git a/Shared/Models/Stateless/XDate.cs b/Shared/Models/Stateless/XDate.cs index 4672512..3fc29e7 100644 --- a/Shared/Models/Stateless/XDate.cs +++ b/Shared/Models/Stateless/XDate.cs @@ -19,6 +19,22 @@ internal abstract class XDate return result; } + internal static (int Season, string seasonName) GetSeasonAB(int dayOfYear) + { + (int Season, string seasonName) result = dayOfYear switch + { + < 78 => new(0, "WinterA"), + < 124 => new(1, "SpringA"), + < 171 => new(1, "SpringB"), + < 217 => new(2, "SummerA"), + < 264 => new(2, "SummerB"), + < 309 => new(3, "FallA"), + < 354 => new(3, "FallB"), + _ => new(4, "WinterB") + }; + return result; + } + internal static (bool?, string[]) IsWrongYear(string[] segments, string year) { bool? result;