FaceFile for D2

This commit is contained in:
Mike Phares 2024-10-20 17:49:48 -07:00
parent 7b00fcaae8
commit 924bd14c31
12 changed files with 261 additions and 0 deletions

10
.vscode/tasks.json vendored
View File

@ -13,6 +13,16 @@
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
}, },
{
"label": "Format-Whitespaces",
"command": "dotnet",
"type": "process",
"args": [
"format",
"whitespace"
],
"problemMatcher": "$msCompile"
},
{ {
"label": "User Secrets Set", "label": "User Secrets Set",
"command": "dotnet", "command": "dotnet",

View File

@ -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
{
}

33
Shared/Models/FaceFile.cs Normal file
View File

@ -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<Stateless.FacePart, FacePoint[]>? 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
{
}

View File

@ -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);
}

42
Shared/Models/Location.cs Normal file
View File

@ -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<Location>
{
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<Location>.Default.Equals(location1, location2);
public static bool operator !=(Location location1, Location location2) => !(location1 == location2);
}

View File

@ -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
{
}

View File

@ -0,0 +1,5 @@
namespace View_by_Distance.Shared.Models;
public record OutputResolution(int Height,
int Orientation,
int Width);

View File

@ -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; }
}

View File

@ -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; }
}

View File

@ -0,0 +1,54 @@
namespace View_by_Distance.Shared.Models.Stateless;
/// <summary>
/// Specifies the part of face.
/// </summary>
public enum FacePart
{
/// <summary>
/// Specifies the chin.
/// </summary>
Chin = 0,
/// <summary>
/// Specifies the left eyebrow.
/// </summary>
LeftEyebrow = 17,
/// <summary>
/// Specifies the right eyebrow.
/// </summary>
RightEyebrow = 22,
/// <summary>
/// Specifies the nose bridge.
/// </summary>
NoseBridge = 27,
/// <summary>
/// Specifies the nose tip.
/// </summary>
NoseTip = 31,
/// <summary>
/// Specifies the left eye.
/// </summary>
LeftEye = 36,
/// <summary>
/// Specifies the right eye.
/// </summary>
RightEye = 42,
/// <summary>
/// Specifies the top lip.
/// </summary>
TopLip = 48,
/// <summary>
/// Specifies the bottom lip.
/// </summary>
BottomLip = 55
}

View File

@ -13,6 +13,11 @@ public interface IDate
static (int Season, string seasonName) GetSeason(int dayOfYear) => static (int Season, string seasonName) GetSeason(int dayOfYear) =>
XDate.GetSeason(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) => DateTime? TestStatic_GetDateTimeOriginal(ExifDirectory exifDirectory) =>
GetDateTimeOriginal(exifDirectory); GetDateTimeOriginal(exifDirectory);
static DateTime? GetDateTimeOriginal(ExifDirectory exifDirectory) => static DateTime? GetDateTimeOriginal(ExifDirectory exifDirectory) =>

View File

@ -19,6 +19,22 @@ internal abstract class XDate
return result; 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) internal static (bool?, string[]) IsWrongYear(string[] segments, string year)
{ {
bool? result; bool? result;