Removed old GetRectangle

RectangleIntersectMinimums
AddUserSecrets
This commit is contained in:
Mike Phares 2023-06-19 21:33:04 -07:00
parent 2ff966d6b0
commit 8863fd763f
20 changed files with 328 additions and 498 deletions

View File

@ -22,6 +22,7 @@ completedColumns:
- [setup-photo-prism-again-in-wsl-docker](tasks/setup-photo-prism-again-in-wsl-docker.md) - [setup-photo-prism-again-in-wsl-docker](tasks/setup-photo-prism-again-in-wsl-docker.md)
- [run-scan-originals](tasks/run-scan-originals.md) - [run-scan-originals](tasks/run-scan-originals.md)
- [find-incorrectly-mapped-faces](tasks/find-incorrectly-mapped-faces.md) - [find-incorrectly-mapped-faces](tasks/find-incorrectly-mapped-faces.md)
- [shrink-percent](tasks/shrink-percent.md)
## Done ## Done

View File

@ -0,0 +1,13 @@
---
created: 2023-06-12T15:44:11.932Z
updated: 2023-06-12T15:45:59.891Z
assigned: ""
progress: 0
tags: []
---
# shrink-percent
## Sub-tasks
- [x] shrink percent of the intersect rectangle 0.99

View File

@ -17,12 +17,13 @@ public partial class E_Distance
private readonly bool _DistanceRenameToMatch; private readonly bool _DistanceRenameToMatch;
private readonly float[] _RangeFaceConfidence; private readonly float[] _RangeFaceConfidence;
private readonly bool _DistanceMoveUnableToMatch; private readonly bool _DistanceMoveUnableToMatch;
private readonly float _RectangleIntersectMinimum;
private readonly List<string> _AllMappedFaceFiles; private readonly List<string> _AllMappedFaceFiles;
private readonly List<string> _AllMappedFaceFileNames; private readonly List<string> _AllMappedFaceFileNames;
private readonly double _RangeDistanceToleranceAverage; private readonly double _RangeDistanceToleranceAverage;
private readonly List<string> _DuplicateMappedFaceFiles; private readonly List<string> _DuplicateMappedFaceFiles;
public E_Distance(bool distanceMoveUnableToMatch, bool distanceRenameToMatch, int faceConfidencePercent, float[] rangeDistanceTolerance, float[] rangeFaceConfidence) public E_Distance(bool distanceMoveUnableToMatch, bool distanceRenameToMatch, int faceConfidencePercent, float[] rangeDistanceTolerance, float[] rangeFaceConfidence, float[] rectangleIntersectMinimum)
{ {
_Debug = new(); _Debug = new();
_Moved = new(); _Moved = new();
@ -35,6 +36,7 @@ public partial class E_Distance
_DistanceRenameToMatch = distanceRenameToMatch; _DistanceRenameToMatch = distanceRenameToMatch;
_FaceConfidencePercent = faceConfidencePercent; _FaceConfidencePercent = faceConfidencePercent;
_DistanceMoveUnableToMatch = distanceMoveUnableToMatch; _DistanceMoveUnableToMatch = distanceMoveUnableToMatch;
_RectangleIntersectMinimum = rectangleIntersectMinimum.Max();
_RangeDistanceToleranceAverage = rangeDistanceTolerance.Average(); _RangeDistanceToleranceAverage = rangeDistanceTolerance.Average();
} }
@ -242,7 +244,7 @@ public partial class E_Distance
throw new NotSupportedException(); throw new NotSupportedException();
if (filteredFaces.Any()) if (filteredFaces.Any())
{ {
intersectFaces = Shared.Models.Stateless.Methods.ILocation.FilterByIntersect(filteredFaces, locationContainer.NormalizedRectangle); intersectFaces = Shared.Models.Stateless.Methods.ILocation.FilterByIntersect(filteredFaces, locationContainer.NormalizedRectangle, _RectangleIntersectMinimum);
if (intersectFaces.Any()) if (intersectFaces.Any())
checkFaces.AddRange(GetClosestFaceByDistanceIgnoringTolerance(mappingFromItem, intersectFaces, modelsFaceEncoding)); checkFaces.AddRange(GetClosestFaceByDistanceIgnoringTolerance(mappingFromItem, intersectFaces, modelsFaceEncoding));
} }

View File

@ -140,12 +140,6 @@ public class D_Face
#pragma warning disable CA1416 #pragma warning disable CA1416
private static (int width, int height) Get(string file)
{
using Bitmap source = new(file);
return new(source.Width, source.Height);
}
private PropertyItem GetPropertyItem(int id, string value) private PropertyItem GetPropertyItem(int id, string value)
{ {
PropertyItem result = (PropertyItem)_ConstructorInfo.Invoke(null); PropertyItem result = (PropertyItem)_ConstructorInfo.Invoke(null);
@ -304,7 +298,6 @@ public class D_Face
{ {
List<LocationContainer<MetadataExtractor.Directory>> results = new(); List<LocationContainer<MetadataExtractor.Directory>> results = new();
string? json; string? json;
int width, height;
Location? location; Location? location;
Rectangle? rectangle; Rectangle? rectangle;
List<int> skip = new(); List<int> skip = new();
@ -327,14 +320,12 @@ public class D_Face
if (face.Location is not null && face.OutputResolution is not null) if (face.Location is not null && face.OutputResolution is not null)
continue; continue;
json = Metadata.Models.Stateless.Methods.IMetadata.GetOutputResolution(locationContainer.Directories); json = Metadata.Models.Stateless.Methods.IMetadata.GetOutputResolution(locationContainer.Directories);
if (json is not null) if (json is null)
{ continue;
outputResolutionCheck = JsonSerializer.Deserialize<OutputResolution>(json); outputResolutionCheck = JsonSerializer.Deserialize<OutputResolution>(json);
if (outputResolutionCheck is not null && (outputResolutionCheck.Width != outputResolutionWidth || outputResolutionCheck.Height != outputResolutionHeight)) if (outputResolutionCheck is null || outputResolutionCheck.Width != outputResolutionWidth || outputResolutionCheck.Height != outputResolutionHeight)
continue; continue;
} rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(ILocation.Digits, locationContainer.NormalizedRectangle, outputResolutionCheck);
(width, height) = Get(locationContainer.File);
rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(height, ILocation.Digits, ILocation.Factor, locationContainer.NormalizedRectangle, outputResolutionHeight, outputResolutionWidth, width);
if (rectangle is null) if (rectangle is null)
continue; continue;
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(outputResolutionHeight, rectangle.Value, outputResolutionWidth); location = Shared.Models.Stateless.Methods.ILocation.GetLocation(outputResolutionHeight, rectangle.Value, outputResolutionWidth);

View File

@ -106,7 +106,7 @@ public partial class DlibDotNet
_FaceParts = new D2_FaceParts(imageCodecInfo, encoderParameters, filenameExtension, configuration.CheckDFaceAndUpWriteDates, configuration.OverrideForFaceLandmarkImages); _FaceParts = new D2_FaceParts(imageCodecInfo, encoderParameters, filenameExtension, configuration.CheckDFaceAndUpWriteDates, configuration.OverrideForFaceLandmarkImages);
} }
_MapConfiguration = Get(configuration, _Faces.FileNameExtension, _Faces.HiddenFileNameExtension, _FaceParts.FileNameExtension); _MapConfiguration = Get(configuration, _Faces.FileNameExtension, _Faces.HiddenFileNameExtension, _FaceParts.FileNameExtension);
_Distance = new(configuration.DistanceMoveUnableToMatch, configuration.DistanceRenameToMatch, _Configuration.FaceConfidencePercent, configuration.RangeDistanceTolerance, configuration.RangeFaceConfidence); _Distance = new(configuration.DistanceMoveUnableToMatch, configuration.DistanceRenameToMatch, _Configuration.FaceConfidencePercent, configuration.RangeDistanceTolerance, configuration.RangeFaceConfidence, configuration.RectangleIntersectMinimums);
if (_PropertyRootExistedBefore || !_ArgZeroIsConfigurationRootDirectory) if (_PropertyRootExistedBefore || !_ArgZeroIsConfigurationRootDirectory)
{ {
_GenealogicalDataCommunicationFooterLines = null; _GenealogicalDataCommunicationFooterLines = null;
@ -783,7 +783,7 @@ public partial class DlibDotNet
} }
Dictionary<int, Dictionary<int, Mapping>> idToNormalizedRectangleToMapping = Map.Models.Stateless.Methods.IMapLogic.GetIdToNormalizedRectangleToFace(distinctFilteredMappingCollection); Dictionary<int, Dictionary<int, Mapping>> idToNormalizedRectangleToMapping = Map.Models.Stateless.Methods.IMapLogic.GetIdToNormalizedRectangleToFace(distinctFilteredMappingCollection);
if (Directory.Exists(fPhotoPrismContentDirectory)) if (Directory.Exists(fPhotoPrismContentDirectory))
F_PhotoPrism.WriteMatches(fPhotoPrismContentDirectory, _Configuration.MappingDefaultName, _Configuration.PersonBirthdayFormat, ticks, distinctFilteredFaces, mapLogic); F_PhotoPrism.WriteMatches(fPhotoPrismContentDirectory, _Configuration.MappingDefaultName, _Configuration.PersonBirthdayFormat, _Configuration.RectangleIntersectMinimums, ticks, distinctFilteredFaces, mapLogic);
if (_Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution)) if (_Configuration.SaveShortcutsForOutputResolutions.Contains(outputResolution))
mapLogic.SaveShortcutsForOutputResolutionsDuringMapLogic(containers, personKeyToIds, dFacesContentDirectory, distinctFilteredMappingCollection); mapLogic.SaveShortcutsForOutputResolutionsDuringMapLogic(containers, personKeyToIds, dFacesContentDirectory, distinctFilteredMappingCollection);
if (!string.IsNullOrEmpty(_Configuration.PersonCharacters)) if (!string.IsNullOrEmpty(_Configuration.PersonCharacters))

View File

@ -67,6 +67,7 @@ public class Configuration
[Display(Name = "Face Distance Tolerance"), Required] public float[] RangeDistanceTolerance { get; set; } [Display(Name = "Face Distance Tolerance"), Required] public float[] RangeDistanceTolerance { get; set; }
[Display(Name = "Face Area Permille Tolerance"), Required] public float[] RangeFaceAreaTolerance { get; set; } [Display(Name = "Face Area Permille Tolerance"), Required] public float[] RangeFaceAreaTolerance { get; set; }
[Display(Name = "Location Minimum Confidence"), Required] public float[] RangeFaceConfidence { get; set; } [Display(Name = "Location Minimum Confidence"), Required] public float[] RangeFaceConfidence { get; set; }
[Display(Name = "Rectangle Intersect Minimums"), Required] public float[] RectangleIntersectMinimums { get; set; }
[Display(Name = "Reverse"), Required] public bool? Reverse { get; set; } [Display(Name = "Reverse"), Required] public bool? Reverse { get; set; }
[Display(Name = "Save Blur Hash For Output Resolutions"), Required] public string[] SaveBlurHashForOutputResolutions { get; set; } [Display(Name = "Save Blur Hash For Output Resolutions"), Required] public string[] SaveBlurHashForOutputResolutions { get; set; }
[Display(Name = "Save Face Distances For Output Resolutions"), Required] public string[] SaveFaceDistancesForOutputResolutions { get; set; } [Display(Name = "Save Face Distances For Output Resolutions"), Required] public string[] SaveFaceDistancesForOutputResolutions { get; set; }
@ -200,6 +201,7 @@ public class Configuration
throw new NullReferenceException(nameof(configuration.RangeFaceConfidence)); throw new NullReferenceException(nameof(configuration.RangeFaceConfidence));
if (configuration.RangeDistanceTolerance is null || configuration.RangeDistanceTolerance.Length != 3) if (configuration.RangeDistanceTolerance is null || configuration.RangeDistanceTolerance.Length != 3)
throw new NullReferenceException(nameof(configuration.RangeDistanceTolerance)); throw new NullReferenceException(nameof(configuration.RangeDistanceTolerance));
configuration.RectangleIntersectMinimums ??= Array.Empty<float>();
if (configuration.Reverse is null) if (configuration.Reverse is null)
throw new NullReferenceException(nameof(configuration.Reverse)); throw new NullReferenceException(nameof(configuration.Reverse));
configuration.SaveBlurHashForOutputResolutions ??= Array.Empty<string>(); configuration.SaveBlurHashForOutputResolutions ??= Array.Empty<string>();
@ -289,6 +291,7 @@ public class Configuration
configuration.RangeDistanceTolerance, configuration.RangeDistanceTolerance,
configuration.RangeFaceAreaTolerance, configuration.RangeFaceAreaTolerance,
configuration.RangeFaceConfidence, configuration.RangeFaceConfidence,
configuration.RectangleIntersectMinimums,
configuration.Reverse.Value, configuration.Reverse.Value,
configuration.SaveBlurHashForOutputResolutions, configuration.SaveBlurHashForOutputResolutions,
configuration.SaveFaceDistancesForOutputResolutions, configuration.SaveFaceDistancesForOutputResolutions,

View File

@ -63,6 +63,7 @@ public class Configuration
public float[] RangeDistanceTolerance { init; get; } public float[] RangeDistanceTolerance { init; get; }
public float[] RangeFaceAreaTolerance { init; get; } public float[] RangeFaceAreaTolerance { init; get; }
public float[] RangeFaceConfidence { init; get; } public float[] RangeFaceConfidence { init; get; }
public float[] RectangleIntersectMinimums { init; get; }
public bool Reverse { init; get; } public bool Reverse { init; get; }
public string[] SaveBlurHashForOutputResolutions { init; get; } public string[] SaveBlurHashForOutputResolutions { init; get; }
public string[] SaveFaceDistancesForOutputResolutions { init; get; } public string[] SaveFaceDistancesForOutputResolutions { init; get; }
@ -141,6 +142,7 @@ public class Configuration
float[] rangeDistanceTolerance, float[] rangeDistanceTolerance,
float[] rangeFaceAreaPermyriadTolerance, float[] rangeFaceAreaPermyriadTolerance,
float[] rangeFaceConfidence, float[] rangeFaceConfidence,
float[] rectangleIntersectMinimums,
bool reverse, bool reverse,
string[] saveBlurHashForOutputResolutions, string[] saveBlurHashForOutputResolutions,
string[] saveFaceDistancesForOutputResolutions, string[] saveFaceDistancesForOutputResolutions,
@ -218,6 +220,7 @@ public class Configuration
RangeDistanceTolerance = rangeDistanceTolerance; RangeDistanceTolerance = rangeDistanceTolerance;
RangeFaceAreaTolerance = rangeFaceAreaPermyriadTolerance; RangeFaceAreaTolerance = rangeFaceAreaPermyriadTolerance;
RangeFaceConfidence = rangeFaceConfidence; RangeFaceConfidence = rangeFaceConfidence;
RectangleIntersectMinimums = rectangleIntersectMinimums;
Reverse = reverse; Reverse = reverse;
SaveBlurHashForOutputResolutions = saveBlurHashForOutputResolutions; SaveBlurHashForOutputResolutions = saveBlurHashForOutputResolutions;
SaveFaceDistancesForOutputResolutions = saveFaceDistancesForOutputResolutions; SaveFaceDistancesForOutputResolutions = saveFaceDistancesForOutputResolutions;

View File

@ -155,6 +155,9 @@
0.2, 0.2,
0.8 0.8
], ],
"RectangleIntersectMinimums": [
0.99
],
"IgnoreRelativePaths": [], "IgnoreRelativePaths": [],
"MixedYearRelativePaths": [], "MixedYearRelativePaths": [],
"SaveFaceDistancesForOutputResolutions": [], "SaveFaceDistancesForOutputResolutions": [],

View File

@ -169,17 +169,19 @@ public class F_PhotoPrism
} }
} }
public static void WriteMatches(string fPhotoPrismContentDirectory, string mappingDefaultName, string personBirthdayFormat, long ticks, List<Face> distinctFilteredFaces, Shared.Models.Methods.IMapLogic mapLogic) public static void WriteMatches(string fPhotoPrismContentDirectory, string mappingDefaultName, string personBirthdayFormat, float[] rectangleIntersectMinimums, long ticks, List<Face> distinctFilteredFaces, Shared.Models.Methods.IMapLogic mapLogic)
{ {
string file; string file;
string text; string text;
double percent;
int? normalizedRectangle; int? normalizedRectangle;
List<string> subjects = new(); List<string> subjects = new();
StringBuilder stringBuilder = new();
PersonContainer[]? personContainers; PersonContainer[]? personContainers;
StringBuilder stringBuilder = new();
System.Drawing.Rectangle dlibRectangle; System.Drawing.Rectangle dlibRectangle;
System.Drawing.Rectangle? prismRectangle; System.Drawing.Rectangle? prismRectangle;
System.Drawing.Rectangle intersectRectangle; System.Drawing.Rectangle intersectRectangle;
float rectangleIntersectMinimum = rectangleIntersectMinimums.Min();
Dictionary<int, PersonContainer[]>? normalizedRectangleToPersonContainers; Dictionary<int, PersonContainer[]>? normalizedRectangleToPersonContainers;
(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)[] sortedCollection; (MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)[] sortedCollection;
List<(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)> collection = new(); List<(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)> collection = new();
@ -201,14 +203,14 @@ public class F_PhotoPrism
{ {
foreach (Shared.Models.Marker marker in mappingFromPhotoPrism.Markers) foreach (Shared.Models.Marker marker in mappingFromPhotoPrism.Markers)
{ {
prismRectangle = ILocation.GetRectangle(face.OutputResolution, mappingFromPhotoPrism.DatabaseFile, marker); prismRectangle = ILocation.GetRectangle(mappingFromPhotoPrism.DatabaseFile, marker, face.OutputResolution);
if (prismRectangle is null) if (prismRectangle is null)
continue; continue;
intersectRectangle = System.Drawing.Rectangle.Intersect(dlibRectangle, prismRectangle.Value); intersectRectangle = System.Drawing.Rectangle.Intersect(dlibRectangle, prismRectangle.Value);
if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0) if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0)
continue; continue;
double percent = (double)intersectRectangle.Width * intersectRectangle.Height / (dlibRectangle.Width * dlibRectangle.Height); percent = (double)intersectRectangle.Width * intersectRectangle.Height / (dlibRectangle.Width * dlibRectangle.Height);
if (percent < 0.000001) if (percent < rectangleIntersectMinimum)
continue; continue;
collection.Add(new(mappingFromPhotoPrism, marker, percent)); collection.Add(new(mappingFromPhotoPrism, marker, percent));
} }
@ -220,10 +222,10 @@ public class F_PhotoPrism
} }
if (subjects.Any()) if (subjects.Any())
{ {
file = Path.Combine(fPhotoPrismContentDirectory, $"{ticks}-subject_alias_update.sql"); file = Path.Combine(fPhotoPrismContentDirectory, $"{ticks}-{rectangleIntersectMinimum}-subject_alias_update.sql");
text = string.Join(Environment.NewLine, subjects.Distinct()); text = string.Join(Environment.NewLine, subjects.Distinct());
_ = IPath.WriteAllText(file, text, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null); _ = IPath.WriteAllText(file, text, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
file = Path.Combine(fPhotoPrismContentDirectory, $"{ticks}-marker_name_update.sql"); file = Path.Combine(fPhotoPrismContentDirectory, $"{ticks}-{rectangleIntersectMinimum}-marker_name_update.sql");
text = stringBuilder.ToString(); text = stringBuilder.ToString();
_ = IPath.WriteAllText(file, text, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null); _ = IPath.WriteAllText(file, text, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
} }

View File

@ -10,20 +10,20 @@ public interface ILocation
static Models.Location? GetLocation(int height, Rectangle rectangle, int width) => static Models.Location? GetLocation(int height, Rectangle rectangle, int width) =>
Location.GetLocation(height, rectangle, width); Location.GetLocation(height, rectangle, width);
List<Models.Face> TestStatic_FilterByIntersect(Models.Face[] faces, int normalizedRectangle) => List<Models.Face> TestStatic_FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) =>
FilterByIntersect(faces, normalizedRectangle); FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum);
static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle) => static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) =>
Location.FilterByIntersect(faces, normalizedRectangle); Location.FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum);
Rectangle? TestStatic_GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) => Rectangle? TestStatic_GetRectangle(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
GetRectangle(outputResolution, databaseFile, marker); GetRectangle(databaseFile, marker, outputResolution);
static Rectangle? GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) => static Rectangle? GetRectangle(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
Location.GetRectangle(outputResolution, databaseFile, marker); Location.GetRectangle(databaseFile, marker, outputResolution);
Models.Location? TestStatic_GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) => Models.Location? TestStatic_GetLocation(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
GetLocation(outputResolution, databaseFile, marker); GetLocation(databaseFile, marker, outputResolution);
static Models.Location? GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) => static Models.Location? GetLocation(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
Location.GetLocation(outputResolution, databaseFile, marker); Location.GetLocation(databaseFile, marker, outputResolution);
List<Models.Location> TestStatic_GetLocations<T>(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces, List<LocationContainer<T>> containers) => List<Models.Location> TestStatic_GetLocations<T>(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces, List<LocationContainer<T>> containers) =>
GetLocations(mappingFromPhotoPrismCollection, faces, containers); GetLocations(mappingFromPhotoPrismCollection, faces, containers);
@ -35,15 +35,10 @@ public interface ILocation
static Rectangle? GetNormalizedRectangle(int locationDigits, int normalizedRectangle) => static Rectangle? GetNormalizedRectangle(int locationDigits, int normalizedRectangle) =>
Location.GetNormalizedRectangle(locationDigits, normalizedRectangle.ToString()); Location.GetNormalizedRectangle(locationDigits, normalizedRectangle.ToString());
Rectangle? TestStatic_GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) => Rectangle? TestStatic_GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) =>
GetRectangle(checkRectangle, locationDigits, locationFactor, normalizedRectangle, outputResolution, useOldWay); GetRectangle(locationDigits, normalizedRectangle, outputResolution);
static Rectangle? GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) => static Rectangle? GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) =>
Location.GetRectangle(checkRectangle, OutputResolution.Get(outputResolution).Height, locationDigits, locationFactor, normalizedRectangle.ToString(), OutputResolution.Get(outputResolution).Width, useOldWay); Location.GetRectangle(locationDigits, normalizedRectangle.ToString(), outputResolution);
Rectangle? TestStatic_GetRectangle(int height, int locationDigits, int locationFactor, int normalizedRectangle, int outputResolutionHeight, int outputResolutionWidth, int width) =>
GetRectangle(height, locationDigits, locationFactor, normalizedRectangle, outputResolutionHeight, outputResolutionWidth, width);
static Rectangle? GetRectangle(int height, int locationDigits, int locationFactor, int normalizedRectangle, int outputResolutionHeight, int outputResolutionWidth, int width) =>
Location.GetRectangle(height, locationDigits, locationFactor, normalizedRectangle.ToString(), outputResolutionHeight, outputResolutionWidth, width);
string TestStatic_GetLeftPadded(int locationDigits, string value) => string TestStatic_GetLeftPadded(int locationDigits, string value) =>
GetLeftPadded(locationDigits, value); GetLeftPadded(locationDigits, value);
@ -60,11 +55,6 @@ public interface ILocation
static string GetLeftPadded(int locationDigits, int value) => static string GetLeftPadded(int locationDigits, int value) =>
GetLeftPadded(locationDigits, value.ToString()); GetLeftPadded(locationDigits, value.ToString());
(int?, int?) TestStatic_GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedRectangle) =>
GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedRectangle) =>
Location.GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
Models.Location? TestStatic_GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) => Models.Location? TestStatic_GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
GetLocation(location, locationDigits, locationFactor, height, width, zCount); GetLocation(location, locationDigits, locationFactor, height, width, zCount);
static Models.Location? GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) => static Models.Location? GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>

View File

@ -108,30 +108,6 @@ internal abstract class Location
return result; return result;
} }
internal static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedRectangle)
{
int? x;
int? y;
int center = 2;
decimal factor = locationFactor;
int each = (locationDigits - 1) / center;
string segmentA = normalizedRectangle[..each];
string segmentB = normalizedRectangle[each..^1];
if (!int.TryParse(segmentA, out int xNormalized) || !int.TryParse(segmentB, out int yNormalized))
{
x = null;
y = null;
}
else
{
decimal xValue = xNormalized / factor * width;
decimal yValue = yNormalized / factor * height;
x = (int)Math.Round(xValue, 0);
y = (int)Math.Round(yValue, 0);
}
return new(x, y);
}
internal static int GetConfidencePercent(int faceConfidencePercent, float[] rangeFaceConfidence, double confidence) internal static int GetConfidencePercent(int faceConfidencePercent, float[] rangeFaceConfidence, double confidence)
{ {
int result = (int)(confidence / rangeFaceConfidence[1] * faceConfidencePercent); int result = (int)(confidence / rangeFaceConfidence[1] * faceConfidencePercent);
@ -162,7 +138,7 @@ internal abstract class Location
return result; return result;
} }
private static Rectangle? GetRectangle(int locationDigits, int height, string normalizedRectangle, int width) internal static Rectangle? GetRectangle(int height, int locationDigits, string normalizedRectangle, int width)
{ {
Rectangle? result; Rectangle? result;
Rectangle? rectangle = GetNormalizedRectangle(locationDigits, normalizedRectangle); Rectangle? rectangle = GetNormalizedRectangle(locationDigits, normalizedRectangle);
@ -176,42 +152,15 @@ internal abstract class Location
return result; return result;
} }
internal static Rectangle? GetRectangle(Rectangle checkRectangle, int height, int locationDigits, int locationFactor, string normalizedRectangle, int width, bool useOldWay) internal static Rectangle? GetRectangle(int locationDigits, string normalizedRectangle, Models.OutputResolution outputResolution)
{ {
Rectangle? result; Rectangle? result;
if (useOldWay) if (normalizedRectangle.Length != locationDigits || normalizedRectangle[0] is not '4' and not '8')
{ throw new NotSupportedException("Old way has been removed!");
(int? x, int? y) = GetXY(locationDigits, locationFactor, width, height, normalizedRectangle); (int width, int height) = OutputResolution.Get(outputResolution);
if (x is null || y is null) result = GetRectangle(height, locationDigits, normalizedRectangle, width);
throw new Exception(); if (result is null)
result = new(x.Value - (checkRectangle.Width / 2), y.Value - (checkRectangle.Height / 2), checkRectangle.Width, checkRectangle.Height); throw new NullReferenceException(nameof(result));
}
else
{
if (normalizedRectangle.Length != locationDigits)
result = null;
else
{
result = GetRectangle(locationDigits, height, normalizedRectangle, width);
if (result is null)
throw new NullReferenceException(nameof(result));
}
}
return result;
}
internal static Rectangle? GetRectangle(int height, int locationDigits, int locationFactor, string normalizedRectangle, int outputResolutionHeight, int outputResolutionWidth, int width)
{
Rectangle? result;
if (normalizedRectangle.Length == locationDigits && normalizedRectangle[0] is '4' or '8')
result = GetRectangle(locationDigits, outputResolutionHeight, normalizedRectangle, outputResolutionWidth);
else
{
(int? x, int? y) = GetXY(locationDigits, locationFactor, outputResolutionWidth, outputResolutionHeight, normalizedRectangle);
if (x is null || y is null)
throw new Exception();
result = new(x.Value - (width / 2), y.Value - (height / 2), width, height);
}
return result; return result;
} }
@ -221,7 +170,7 @@ internal abstract class Location
return result; return result;
} }
internal static Rectangle? GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) internal static Rectangle? GetRectangle(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution)
{ {
Rectangle? result; Rectangle? result;
bool matches = Matches(outputResolution, databaseFile); bool matches = Matches(outputResolution, databaseFile);
@ -255,10 +204,10 @@ internal abstract class Location
return result; return result;
} }
internal static Models.Location? GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) internal static Models.Location? GetLocation(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution)
{ {
Models.Location? result; Models.Location? result;
Rectangle? rectangle = GetRectangle(outputResolution, databaseFile, marker); Rectangle? rectangle = GetRectangle(databaseFile, marker, outputResolution);
if (rectangle is null) if (rectangle is null)
result = null; result = null;
else else
@ -300,7 +249,7 @@ internal abstract class Location
foreach (Marker marker in mappingFromPhotoPrism.Markers) foreach (Marker marker in mappingFromPhotoPrism.Markers)
{ {
any = false; any = false;
prismRectangle = GetRectangle(outputResolution, mappingFromPhotoPrism.DatabaseFile, marker); prismRectangle = GetRectangle(mappingFromPhotoPrism.DatabaseFile, marker, outputResolution);
if (prismRectangle is null) if (prismRectangle is null)
break; break;
location = GetLocation(mappingFromPhotoPrism.DatabaseFile, marker, prismRectangle.Value); location = GetLocation(mappingFromPhotoPrism.DatabaseFile, marker, prismRectangle.Value);
@ -341,10 +290,9 @@ internal abstract class Location
return results; return results;
} }
internal static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle) internal static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum)
{ {
List<Models.Face> results = new(); List<Models.Face> results = new();
bool useOldWay;
double? percent; double? percent;
Rectangle checkRectangle; Rectangle checkRectangle;
Rectangle? sourceRectangle; Rectangle? sourceRectangle;
@ -354,20 +302,16 @@ internal abstract class Location
if (face.Location is null || face.OutputResolution is null) if (face.Location is null || face.OutputResolution is null)
continue; continue;
checkRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top); checkRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top);
for (int i = 1; i < 3; i++) sourceRectangle = GetRectangle(Stateless.ILocation.Digits, normalizedRectangle.ToString(), face.OutputResolution);
{ if (sourceRectangle is null)
useOldWay = i == 1; continue;
sourceRectangle = ILocation.GetRectangle(checkRectangle, Stateless.ILocation.Digits, Stateless.ILocation.Factor, normalizedRectangle, face.OutputResolution, useOldWay); intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value);
if (sourceRectangle is null) if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0)
continue; continue;
intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value); percent = (double)intersectRectangle.Width * intersectRectangle.Height / (checkRectangle.Width * checkRectangle.Height);
if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0) if (percent < rectangleIntersectMinimum)
continue; continue;
percent = (double)intersectRectangle.Width * intersectRectangle.Height / (checkRectangle.Width * checkRectangle.Height); results.Add(face);
if (percent < 0.000001)
continue;
results.Add(face);
}
} }
return results; return results;
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
@ -6,6 +6,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
<UserSecretsId>e8c3d25d-9715-4b35-9010-1cdc74840190</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<VSTestLogger>trx</VSTestLogger> <VSTestLogger>trx</VSTestLogger>

View File

@ -39,7 +39,8 @@ public partial class UnitTestCalculations
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables() .AddEnvironmentVariables()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true); .AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
.AddUserSecrets<UnitTestCalculations>();
configurationRoot = configurationBuilder.Build(); configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot); appSettings = Models.Binder.AppSettings.Get(configurationRoot);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
@ -93,6 +94,7 @@ public partial class UnitTestCalculations
throw new NullReferenceException(nameof(age)); throw new NullReferenceException(nameof(age));
Assert.IsNotNull(age); Assert.IsNotNull(age);
Assert.IsTrue(age.Value > 42.6092); Assert.IsTrue(age.Value > 42.6092);
NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
@ -114,6 +116,7 @@ public partial class UnitTestCalculations
Assert.IsTrue($"({l}{d.ToString("0.00")[1..]})" == "(637967784888423594.62)"); Assert.IsTrue($"({l}{d.ToString("0.00")[1..]})" == "(637967784888423594.62)");
d = 0.45; d = 0.45;
Assert.IsTrue($"({l}{d.ToString("0.00")[1..]})" == "(637967784888423594.45)"); Assert.IsTrue($"({l}{d.ToString("0.00")[1..]})" == "(637967784888423594.45)");
NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
@ -123,6 +126,7 @@ public partial class UnitTestCalculations
Assert.IsTrue(successful == "_ Manual Copy Successful"); Assert.IsTrue(successful == "_ Manual Copy Successful");
string verify = $"_ {nameof(Shared.Models.Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title)} Verify"; string verify = $"_ {nameof(Shared.Models.Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title)} Verify";
Assert.IsTrue(verify == "_ Manual Copy Verify"); Assert.IsTrue(verify == "_ Manual Copy Verify");
NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
@ -154,6 +158,7 @@ public partial class UnitTestCalculations
// "7680x4320 - Hog - Large" // "7680x4320 - Hog - Large"
// [8] [string]: // [8] [string]:
// "()" // "()"
NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
@ -170,6 +175,7 @@ public partial class UnitTestCalculations
Location location = new(bottom, confidence, left, right, top); Location location = new(bottom, confidence, left, right, top);
_ = new Location(confidence, height, location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, width, 1); _ = new Location(confidence, height, location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, width, 1);
_ = new Location(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); _ = new Location(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
@ -186,7 +192,7 @@ public partial class UnitTestCalculations
width = 100; width = 100;
height = 100; height = 100;
areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, bottom, height, left, right, top, width); areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, bottom, height, left, right, top, width);
Assert.IsTrue(areaPermyriad == 1000); Assert.IsTrue(areaPermyriad == 10000);
left = 0; left = 0;
right = 50; right = 50;
top = 0; top = 0;
@ -195,7 +201,7 @@ public partial class UnitTestCalculations
height = 100; height = 100;
location = new(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); location = new(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, height, location, width); areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, height, location, width);
Assert.IsTrue(areaPermyriad == 250); Assert.IsTrue(areaPermyriad == 2500);
left = 0; left = 0;
right = 25; right = 25;
top = 0; top = 0;
@ -205,30 +211,8 @@ public partial class UnitTestCalculations
location = new(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); location = new(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
OutputResolution outputResolution = new(height, 0, width); OutputResolution outputResolution = new(height, 0, width);
areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, location, outputResolution); areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, location, outputResolution);
Assert.IsTrue(areaPermyriad == 62); Assert.IsTrue(areaPermyriad == 625);
} NonThrowTryCatch();
[TestMethod]
public void TestNormalizedRectangle()
{
int? x, y;
int normalizedRectangle;
int bottom, height, left, right, top, width;
string normalizedRectanglePadded;
width = 2048;
height = 1365;
normalizedRectanglePadded = "617214031";
(x, y) = ILocation.GetXY(Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, width, height, normalizedRectanglePadded);
if (x is null || y is null)
throw new Exception();
Assert.IsTrue(x.Value == 1264);
Assert.IsTrue(y.Value == 192);
left = x.Value;
right = x.Value + 125;
top = y.Value;
bottom = y.Value + 100;
normalizedRectangle = ILocation.GetNormalizedRectangle(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, right, top, width);
Assert.IsTrue(normalizedRectangle == 461140607);
} }
[TestMethod] [TestMethod]
@ -241,6 +225,7 @@ public partial class UnitTestCalculations
y2 = 10f; y2 = 10f;
double distance = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2)); double distance = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
Assert.IsTrue(distance == 1.4142135623730951); Assert.IsTrue(distance == 1.4142135623730951);
NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
@ -266,6 +251,7 @@ public partial class UnitTestCalculations
value = 1.6f; value = 1.6f;
check = ILocation.GetConfidencePercent(faceConfidencePercent, new float[] { minimum, target, maximum }, value); check = ILocation.GetConfidencePercent(faceConfidencePercent, new float[] { minimum, target, maximum }, value);
Assert.IsTrue(check == 200); Assert.IsTrue(check == 200);
NonThrowTryCatch();
} }
[TestMethod] [TestMethod]

View File

@ -36,7 +36,9 @@ public class UnitTestExample
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero); isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables() .AddEnvironmentVariables()
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true); .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
.AddUserSecrets<UnitTestExample>();
configurationRoot = configurationBuilder.Build(); configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot); appSettings = Models.Binder.AppSettings.Get(configurationRoot);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))

View File

@ -38,7 +38,8 @@ public partial class UnitTestHardCoded
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables() .AddEnvironmentVariables()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true); .AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
.AddUserSecrets<UnitTestHardCoded>();
configurationRoot = configurationBuilder.Build(); configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot); appSettings = Models.Binder.AppSettings.Get(configurationRoot);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
@ -83,10 +84,13 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodDel() public void TestMethodDel()
{ {
string source = @"F:\Tmp\Phares\Compare\Images 2022-09-15 - 7390c13 - III - Results\E) Distance\2022-09-15\7680 x 4320\7680x4320 - Hog - Large\()\(637992984751968513)"; string directory = @"F:\Tmp\Phares\Compare\Images 2022-09-15 - 7390c13 - III - Results\E) Distance\2022-09-15\7680 x 4320\7680x4320 - Hog - Large\()\(637992984751968513)";
for (int i = 1; i < 11; i++) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
_ = IPath.DeleteEmptyDirectories(source); {
Assert.IsTrue(true); for (int i = 1; i < 11; i++)
_ = IPath.DeleteEmptyDirectories(directory);
Assert.IsTrue(true);
}
NonThrowTryCatch(); NonThrowTryCatch();
} }
@ -114,50 +118,16 @@ public partial class UnitTestHardCoded
NonThrowTryCatch(); NonThrowTryCatch();
} }
[TestMethod]
public void TestMethodDamn()
{
// string name;
// string[] directories;
// string? directoryName;
// string checkDirectory;
// string sourceDirectory = @"F:\Tmp\Phares\Compare\Images 2022-09-15 - 7390c13 - III - Results\E) Distance\2022-09-15\7680 x 4320\7680x4320 - Hog - Large\()";
// directories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly);
// foreach (string directory in directories)
// {
// directoryName = Path.GetDirectoryName(directory);
// if (directoryName is null)
// continue;
// name = Path.GetFileName(directory);
// if (name.Length is 1 or 20)
// continue;
// checkDirectory = Path.Combine(directoryName, "b", name);
// Directory.Move(directory, checkDirectory);
// }
// directories = Directory.GetDirectories(Path.Combine(sourceDirectory, "b"), "*", SearchOption.TopDirectoryOnly);
// foreach (string directory in directories)
// {
// directoryName = Path.GetDirectoryName(directory);
// if (directoryName is null)
// continue;
// name = Path.GetFileName(directory);
// if (name.Length is 1 or 20)
// continue;
// checkDirectory = Path.Combine(directoryName, $"{name[..^4]})");
// if (Directory.Exists(checkDirectory))
// continue;
// Directory.Move(directory, checkDirectory);
// }
// Assert.IsTrue(true);
}
[TestMethod] [TestMethod]
public void TestMethodDel2() public void TestMethodDel2()
{ {
string source = @"F:\Tmp\Phares\Compare\Images 2022-09-15 - 7390c13 - III - Results\E) Distance\2022-09-15\7680 x 4320\7680x4320 - Hog - Large\()\(637992984751968513)"; string directory = @"F:\Tmp\Phares\Compare\Images 2022-09-15 - 7390c13 - III - Results\E) Distance\2022-09-15\7680 x 4320\7680x4320 - Hog - Large\()\(637992984751968513)";
for (int i = 1; i < 11; i++) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
_ = IPath.DeleteEmptyDirectories(source); {
Assert.IsTrue(true); for (int i = 1; i < 11; i++)
_ = IPath.DeleteEmptyDirectories(directory);
Assert.IsTrue(true);
}
NonThrowTryCatch(); NonThrowTryCatch();
} }
@ -230,87 +200,100 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRenameAbandoned() public void TestMethodRenameAbandoned()
{ {
string checkFile; string directory = @"D:\1) Images A\Images-1e85c0ba-Results\A2) People\1e85c0ba\{}\!\Abandoned";
string source = @"D:\1) Images A\Images-1e85c0ba-Results\A2) People\1e85c0ba\{}\!\Abandoned"; if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
string[] files = Directory.GetFiles(source, "*.abd", SearchOption.TopDirectoryOnly);
foreach (string file in files)
{ {
checkFile = file[..^4]; string checkFile;
if (File.Exists(checkFile)) string[] files = Directory.GetFiles(directory, "*.abd", SearchOption.TopDirectoryOnly);
continue; foreach (string file in files)
File.Move(file, checkFile); {
checkFile = file[..^4];
if (File.Exists(checkFile))
continue;
File.Move(file, checkFile);
}
Assert.IsTrue(true);
} }
Assert.IsTrue(true);
NonThrowTryCatch(); NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
public void TestMethodRenameDelete() public void TestMethodRenameDelete()
{ {
string checkFile; string directory = @"D:\1) Images A\Images-1e85c0ba-Results\A) Property\1e85c0ba\{}";
string source = @"D:\1) Images A\Images-1e85c0ba-Results\A) Property\1e85c0ba\{}"; if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
string[] files = Directory.GetFiles(source, "*.del", SearchOption.AllDirectories);
foreach (string file in files)
{ {
checkFile = file[..^4]; string checkFile;
if (File.Exists(checkFile)) string[] files = Directory.GetFiles(directory, "*.del", SearchOption.AllDirectories);
continue; foreach (string file in files)
File.Move(file, checkFile); {
checkFile = file[..^4];
if (File.Exists(checkFile))
continue;
File.Move(file, checkFile);
}
Assert.IsTrue(true);
} }
Assert.IsTrue(true);
NonThrowTryCatch(); NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
public void TestMethodRenameOld() public void TestMethodRenameOld()
{ {
string checkFile; string directory = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba-Results\E) Distance\1e85c0ba\()";
string source = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba-Results\E) Distance\1e85c0ba\()"; if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
string[] files = Directory.GetFiles(source, "*.old", SearchOption.AllDirectories);
foreach (string file in files)
{ {
checkFile = file[..^4]; string checkFile;
if (File.Exists(checkFile)) string[] files = Directory.GetFiles(directory, "*.old", SearchOption.AllDirectories);
continue; foreach (string file in files)
File.Move(file, checkFile); {
checkFile = file[..^4];
if (File.Exists(checkFile))
continue;
File.Move(file, checkFile);
}
Assert.IsTrue(true);
} }
Assert.IsTrue(true);
NonThrowTryCatch(); NonThrowTryCatch();
} }
[TestMethod] [TestMethod]
public void TestMethodAncestryGenealogicalDataCommunication() public void TestMethodAncestryGenealogicalDataCommunication()
{ {
List<string> mappedLines; string directory = "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])";
Dictionary<string, List<string>> individuals; if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
GenealogicalDataCommunication genealogicalDataCommunication;
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
List<(bool, string)> genealogicalDataCommunicationFiles = new()
{ {
new(false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Roberts/Roberts Family Tree.ged"), List<string> mappedLines;
new(false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Phares/Phares Jr Family Tree.ged"), Dictionary<string, List<string>> individuals;
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160708345114583/638160708345114583.ged"), GenealogicalDataCommunication genealogicalDataCommunication;
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160728606500015/638160728606500015.ged"), GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160738845419877/638160738845419877.ged"), List<(bool, string)> genealogicalDataCommunicationFiles = new()
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160743318283885/638160743318283885.ged"),
new(false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Porterfield/Porterfield Family Tree.ged"),
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160708345114583/638160708345114583-Export.ged"),
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160738845419877/638160738845419877-Export.ged"),
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160743318283885/638160743318283885-Export.ged"),
};
foreach ((bool requireNickName, string genealogicalDataCommunicationFile) in genealogicalDataCommunicationFiles)
{
(_, individuals, _) = IGenealogicalDataCommunication.GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
foreach (KeyValuePair<string, List<string>> keyValuePair in individuals)
{ {
genealogicalDataCommunicationLines = IGenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(keyValuePair.Value); new(false, Path.Combine(directory, "Ancestry-Roberts/Roberts Family Tree.ged")),
Assert.IsNotNull(genealogicalDataCommunicationLines.Name); new(false, Path.Combine(directory, "Ancestry-Phares/Phares Jr Family Tree.ged")),
genealogicalDataCommunication = IGenealogicalDataCommunication.GetGenealogicalDataCommunication(genealogicalDataCommunicationLines); new(true, Path.Combine(directory, "Code-638160708345114583/638160708345114583.ged")),
Assert.IsNotNull(genealogicalDataCommunication.Name); new(true, Path.Combine(directory, "Code-638160728606500015/638160728606500015.ged")),
new(true, Path.Combine(directory, "Code-638160738845419877/638160738845419877.ged")),
new(true, Path.Combine(directory, "Code-638160743318283885/638160743318283885.ged")),
new(false, Path.Combine(directory, "Ancestry-Porterfield/Porterfield Family Tree.ged")),
new(true, Path.Combine(directory, "Code-638160708345114583/638160708345114583-Export.ged")),
new(true, Path.Combine(directory, "Code-638160738845419877/638160738845419877-Export.ged")),
new(true, Path.Combine(directory, "Code-638160743318283885/638160743318283885-Export.ged")),
};
foreach ((bool requireNickName, string genealogicalDataCommunicationFile) in genealogicalDataCommunicationFiles)
{
(_, individuals, _) = IGenealogicalDataCommunication.GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
foreach (KeyValuePair<string, List<string>> keyValuePair in individuals)
{
genealogicalDataCommunicationLines = IGenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(keyValuePair.Value);
Assert.IsNotNull(genealogicalDataCommunicationLines.Name);
genealogicalDataCommunication = IGenealogicalDataCommunication.GetGenealogicalDataCommunication(genealogicalDataCommunicationLines);
Assert.IsNotNull(genealogicalDataCommunication.Name);
}
mappedLines = IGenealogicalDataCommunication.GetMappedLines(genealogicalDataCommunicationFile, requireNickName);
if (IPath.WriteAllText($"{genealogicalDataCommunicationFile}.cln", string.Join(Environment.NewLine, mappedLines), updateDateWhenMatches: false, compareBeforeWrite: true))
continue;
} }
mappedLines = IGenealogicalDataCommunication.GetMappedLines(genealogicalDataCommunicationFile, requireNickName);
if (IPath.WriteAllText($"{genealogicalDataCommunicationFile}.cln", string.Join(Environment.NewLine, mappedLines), updateDateWhenMatches: false, compareBeforeWrite: true))
continue;
} }
NonThrowTryCatch(); NonThrowTryCatch();
} }
@ -318,71 +301,74 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodAncestryGenealogicalDataCommunicationCleanToExport() public void TestMethodAncestryGenealogicalDataCommunicationCleanToExport()
{ {
int age;
long personKey;
string ageGroup;
string fileName;
string? directory;
bool first = true;
PersonName? personName;
string personKeyFormatted;
bool isDefaultName = false;
DateTime dateTime = DateTime.Now; DateTime dateTime = DateTime.Now;
Dictionary<string, List<string>> individuals; string saveDirectory = "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])";
GenealogicalDataCommunication genealogicalDataCommunication; if (Directory.Exists(Path.GetPathRoot(saveDirectory)) && Directory.Exists(saveDirectory))
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
string saveDirectory = $"D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-{dateTime.Ticks}";
List<(bool, bool, string)> genealogicalDataCommunicationFiles = new()
{ {
new(false, false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Roberts/Roberts Family Tree.ged.cln"), int age;
new(false, false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Phares/Phares Jr Family Tree.ged.cln"), long personKey;
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160708345114583/638160708345114583.ged.cln"), string ageGroup;
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160728606500015/638160728606500015.ged.cln"), string fileName;
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160738845419877/638160738845419877.ged.cln"), string? directory;
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160743318283885/638160743318283885.ged.cln"), bool first = true;
new(false, false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Porterfield/Porterfield Family Tree.ged.cln"), PersonName? personName;
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160708345114583/638160708345114583-Export.ged.cln"), string personKeyFormatted;
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160738845419877/638160738845419877-Export.ged.cln"), bool isDefaultName = false;
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160743318283885/638160743318283885-Export.ged.cln"), Dictionary<string, List<string>> individuals;
}; GenealogicalDataCommunication genealogicalDataCommunication;
foreach ((bool verify, bool requireNickName, string genealogicalDataCommunicationFile) in genealogicalDataCommunicationFiles) GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
{ List<(bool, bool, string)> genealogicalDataCommunicationFiles = new()
fileName = Path.GetFileNameWithoutExtension(genealogicalDataCommunicationFile).Split(' ')[0];
(_, individuals, _) = IGenealogicalDataCommunication.GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
foreach (KeyValuePair<string, List<string>> keyValuePair in individuals)
{ {
genealogicalDataCommunicationLines = IGenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(keyValuePair.Value); new(false, false, Path.Combine(saveDirectory, "Ancestry-Roberts/Roberts Family Tree.ged.cln")),
Assert.IsNotNull(genealogicalDataCommunicationLines.Name); new(false, false, Path.Combine(saveDirectory, "Ancestry-Phares/Phares Jr Family Tree.ged.cln")),
genealogicalDataCommunication = IGenealogicalDataCommunication.GetGenealogicalDataCommunication(genealogicalDataCommunicationLines); new(true, true, Path.Combine(saveDirectory, "Code-638160708345114583/638160708345114583.ged.cln")),
Assert.IsNotNull(genealogicalDataCommunication.Name); new(true, true, Path.Combine(saveDirectory, "Code-638160728606500015/638160728606500015.ged.cln")),
if (genealogicalDataCommunication.Birth is null) new(true, true, Path.Combine(saveDirectory, "Code-638160738845419877/638160738845419877.ged.cln")),
continue; new(true, true, Path.Combine(saveDirectory, "Code-638160743318283885/638160743318283885.ged.cln")),
personName = IPersonName.GetPersonName(genealogicalDataCommunication); new(false, false, Path.Combine(saveDirectory, "Ancestry-Porterfield/Porterfield Family Tree.ged.cln")),
if (personName is null) new(true, true, Path.Combine(saveDirectory, "Code-638160708345114583/638160708345114583-Export.ged.cln")),
continue; new(true, true, Path.Combine(saveDirectory, "Code-638160738845419877/638160738845419877-Export.ged.cln")),
personKey = genealogicalDataCommunication.Birth.Value.Ticks; new(true, true, Path.Combine(saveDirectory, "Code-638160743318283885/638160743318283885-Export.ged.cln")),
(age, _) = IAge.GetAge(dateTime.Ticks, personKey); };
personKeyFormatted = IPersonBirthday.GetFormatted(_PropertyConfiguration.PersonBirthdayFormat, personKey); foreach ((bool verify, bool requireNickName, string genealogicalDataCommunicationFile) in genealogicalDataCommunicationFiles)
if (age < 25) {
ageGroup = "1) Less-25"; fileName = Path.GetFileNameWithoutExtension(genealogicalDataCommunicationFile).Split(' ')[0];
else if (age < 50) (_, individuals, _) = IGenealogicalDataCommunication.GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
ageGroup = "2) Less-50"; foreach (KeyValuePair<string, List<string>> keyValuePair in individuals)
else if (age < 100) {
ageGroup = "3) Less-100"; genealogicalDataCommunicationLines = IGenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(keyValuePair.Value);
else if (age < 200) Assert.IsNotNull(genealogicalDataCommunicationLines.Name);
ageGroup = "4) Less-200"; genealogicalDataCommunication = IGenealogicalDataCommunication.GetGenealogicalDataCommunication(genealogicalDataCommunicationLines);
else Assert.IsNotNull(genealogicalDataCommunication.Name);
ageGroup = "5) Else"; if (genealogicalDataCommunication.Birth is null)
directory = Path.Combine(saveDirectory, fileName, ageGroup, $"{personName.First.Value} {personName.Last.Value}^{age}", personKeyFormatted); continue;
if (!Directory.Exists(directory)) personName = IPersonName.GetPersonName(genealogicalDataCommunication);
_ = Directory.CreateDirectory(directory); if (personName is null)
IGenealogicalDataCommunication.WriteFile(personKeyFormatted, personName, keyValuePair.Value, isDefaultName, directory, genealogicalDataCommunication, verify, first); continue;
personKey = genealogicalDataCommunication.Birth.Value.Ticks;
(age, _) = IAge.GetAge(dateTime.Ticks, personKey);
personKeyFormatted = IPersonBirthday.GetFormatted(_PropertyConfiguration.PersonBirthdayFormat, personKey);
if (age < 25)
ageGroup = "1) Less-25";
else if (age < 50)
ageGroup = "2) Less-50";
else if (age < 100)
ageGroup = "3) Less-100";
else if (age < 200)
ageGroup = "4) Less-200";
else
ageGroup = "5) Else";
directory = Path.Combine(saveDirectory, fileName, ageGroup, $"{personName.First.Value} {personName.Last.Value}^{age}", personKeyFormatted);
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
IGenealogicalDataCommunication.WriteFile(personKeyFormatted, personName, keyValuePair.Value, isDefaultName, directory, genealogicalDataCommunication, verify, first);
}
} }
} }
NonThrowTryCatch(); NonThrowTryCatch();
} }
private static string[] GetFamily() => new string[]{ private static string[] GetFamily() => new string[] {
"UBertha Scott (Barry Scott) 10/2/1900-8/19/1993", "UBertha Scott (Barry Scott) 10/2/1900-8/19/1993",
"MEarl Daniel Herman 1/5/1918-10/19/1962", "MEarl Daniel Herman 1/5/1918-10/19/1962",
"FGlendola Koch 8/10/1919-5/16/1910", "FGlendola Koch 8/10/1919-5/16/1910",
@ -592,7 +578,7 @@ public partial class UnitTestHardCoded
"MDevan Hazen 8/14/1999", "MDevan Hazen 8/14/1999",
"MEthan Hazen 8/14/1999", "MEthan Hazen 8/14/1999",
"FApril Hill 6/9/1980", "FApril Hill 6/9/1980",
"MRandall Hill 1/16/1978", // https://www.facebook.com/randall.d.hill/about_contact_and_basic_info // https://www.facebook.com/photo.php?fbid=10154576010477639&set=pb.530957638.-2207520000.&type=3 // https://scontent-lax3-1.xx.fbcdn.net/v/t1.18169-9/16265790_10154576010477639_102119672782426718_n.jpg?_nc_cat=102&ccb=1-7&_nc_sid=174925&_nc_ohc=cWEECl9DMhoAX_qlUB-&_nc_ht=scontent-lax3-1.xx&oh=00_AfC4PZ-tytVowtRSu1AJtkxRkQb0_j0WSDk4MKquqs0img&oe=64531181 "MRandall Hill 1/16/1978", // https://www.facebook.com/randall.directory.hill/about_contact_and_basic_info // https://www.facebook.com/photo.php?fbid=10154576010477639&set=pb.530957638.-2207520000.&type=3 // https://scontent-lax3-1.xx.fbcdn.net/v/t1.18169-9/16265790_10154576010477639_102119672782426718_n.jpg?_nc_cat=102&ccb=1-7&_nc_sid=174925&_nc_ohc=cWEECl9DMhoAX_qlUB-&_nc_ht=scontent-lax3-1.xx&oh=00_AfC4PZ-tytVowtRSu1AJtkxRkQb0_j0WSDk4MKquqs0img&oe=64531181
"FBrenda Olson 8/27/1958", // https://www.facebook.com/barbara.olson.96/about_contact_and_basic_info "FBrenda Olson 8/27/1958", // https://www.facebook.com/barbara.olson.96/about_contact_and_basic_info
"MChris Olson 11/13/1951", "MChris Olson 11/13/1951",
"FShilo Zeches 4/9/1980", "FShilo Zeches 4/9/1980",
@ -675,66 +661,70 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodFamily() public void TestMethodFamily()
{ {
int age;
string name;
long personKey;
DateTime? death;
string ageGroup;
bool first = true;
string? directory;
bool verify = false;
string[] dateSegments;
DateTime parseDateTime;
PersonName? personName;
string[] spaceSegments;
string personKeyFormatted;
bool isDefaultName = false;
PersonBirthday personBirthday;
string[] family = GetFamily();
DateTime dateTime = DateTime.Now; DateTime dateTime = DateTime.Now;
GenealogicalDataCommunication genealogicalDataCommunication;
string saveDirectory = $"D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Norman-{dateTime.Ticks}"; string saveDirectory = $"D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Norman-{dateTime.Ticks}";
foreach (string familyMember in family) if (Directory.Exists(Path.GetPathRoot(saveDirectory)) && Directory.Exists(saveDirectory))
{ {
spaceSegments = familyMember[1..].Split(' '); int age;
dateSegments = spaceSegments[^1].Split('-'); string name;
name = string.Join(' ', spaceSegments[..^1]); long personKey;
if (!DateTime.TryParse(dateSegments[0], out parseDateTime)) DateTime? death;
continue; string ageGroup;
personName = IPerson.GetPersonName(name); bool first = true;
if (personName is null) string? directory;
continue; bool verify = false;
personBirthday = new(parseDateTime); string[] dateSegments;
personKey = personBirthday.Value.Ticks; DateTime parseDateTime;
personKeyFormatted = IPersonBirthday.GetFormatted(_PropertyConfiguration.PersonBirthdayFormat, personKey); PersonName? personName;
(age, _) = IAge.GetAge(dateTime.Ticks, personKey); string[] spaceSegments;
if (dateSegments.Length == 1) string personKeyFormatted;
death = null; bool isDefaultName = false;
else PersonBirthday personBirthday;
string[] family = GetFamily();
GenealogicalDataCommunication genealogicalDataCommunication;
foreach (string familyMember in family)
{ {
spaceSegments = familyMember[1..].Split(' ');
dateSegments = spaceSegments[^1].Split('-');
name = string.Join(' ', spaceSegments[..^1]);
if (!DateTime.TryParse(dateSegments[0], out parseDateTime)) if (!DateTime.TryParse(dateSegments[0], out parseDateTime))
continue; continue;
death = parseDateTime; personName = IPerson.GetPersonName(name);
if (personName is null)
continue;
personBirthday = new(parseDateTime);
personKey = personBirthday.Value.Ticks;
personKeyFormatted = IPersonBirthday.GetFormatted(_PropertyConfiguration.PersonBirthdayFormat, personKey);
(age, _) = IAge.GetAge(dateTime.Ticks, personKey);
if (dateSegments.Length == 1)
death = null;
else
{
if (!DateTime.TryParse(dateSegments[0], out parseDateTime))
continue;
death = parseDateTime;
}
if (age < 25)
ageGroup = "1) Less-25";
else if (age < 50)
ageGroup = "2) Less-50";
else if (age < 100)
ageGroup = "3) Less-100";
else if (age < 200)
ageGroup = "4) Less-200";
else
ageGroup = "5) Else";
directory = Path.Combine(saveDirectory, "Norman", ageGroup, $"{personName.First.Value} {personName.Last.Value}^{age}", personKeyFormatted);
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
genealogicalDataCommunication = new(null, null, null, null, null, null, null, 'U', personBirthday.Value, death, null);
IGenealogicalDataCommunication.WriteFile(personKeyFormatted, personName, null, isDefaultName, directory, genealogicalDataCommunication, verify, first);
} }
if (age < 25)
ageGroup = "1) Less-25";
else if (age < 50)
ageGroup = "2) Less-50";
else if (age < 100)
ageGroup = "3) Less-100";
else if (age < 200)
ageGroup = "4) Less-200";
else
ageGroup = "5) Else";
directory = Path.Combine(saveDirectory, "Norman", ageGroup, $"{personName.First.Value} {personName.Last.Value}^{age}", personKeyFormatted);
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
genealogicalDataCommunication = new(null, null, null, null, null, null, null, 'U', personBirthday.Value, death, null);
IGenealogicalDataCommunication.WriteFile(personKeyFormatted, personName, null, isDefaultName, directory, genealogicalDataCommunication, verify, first);
} }
NonThrowTryCatch(); NonThrowTryCatch();
} }
[Ignore]
[TestMethod] [TestMethod]
public void TestMethodGroup() public void TestMethodGroup()
{ {
@ -761,14 +751,18 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRename() public void TestMethodRename()
{ {
// string[] directories = Directory.GetDirectories(@"D:\2) Images B\Not-Copy-Copy-1e85c0ba", "*;*", SearchOption.AllDirectories); // string directory = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba";
string[] directories = Directory.GetDirectories(@"D:\1) Images A\Images-1e85c0ba", "*;*", SearchOption.AllDirectories); string directory = @"D:\1) Images A\Images-1e85c0ba";
// string[] directories = Directory.GetDirectories(@"D:\2) Images B\Not-Copy-Copy-1e85c0ba", "*", SearchOption.AllDirectories); // string directory = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba";
foreach (string directory in directories.OrderByDescending(l => l.Length - l.Replace(@"\", string.Empty).Length)) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
{ {
if (!directory.EndsWith(";9")) string[] directories = Directory.GetDirectories(directory, "*;*", SearchOption.AllDirectories);
continue; foreach (string subDirectory in directories.OrderByDescending(l => l.Length - l.Replace(@"\", string.Empty).Length))
Directory.Move(directory, $"{directory[..^2]} !9"); {
if (!subDirectory.EndsWith(";9"))
continue;
Directory.Move(subDirectory, $"{subDirectory[..^2]} !9");
}
} }
NonThrowTryCatch(); NonThrowTryCatch();
} }
@ -776,9 +770,13 @@ public partial class UnitTestHardCoded
[TestMethod] [TestMethod]
public void TestMethodRenameForUnkown() public void TestMethodRenameForUnkown()
{ {
string[] files = Directory.GetFiles(@"D:\1) Images A\Images-1e85c0ba-Results\E) Distance\1e85c0ba\(Bad-2023-06-18-less-0.4)", "*.unk", SearchOption.AllDirectories); string directory = @"D:\1) Images A\Images-1e85c0ba-Results\E) Distance\1e85c0ba\(RectInt-2023-06-19-less-0.99)";
foreach (string file in files) if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
File.Move(file, file[..^4]); {
string[] files = Directory.GetFiles(directory, "*.unk", SearchOption.AllDirectories);
foreach (string file in files)
File.Move(file, file[..^4]);
}
NonThrowTryCatch(); NonThrowTryCatch();
} }

View File

@ -1,113 +0,0 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Phares.Shared;
using Serilog;
using System.Diagnostics;
using System.Reflection;
using View_by_Distance.Shared.Models.Stateless.Methods;
using View_by_Distance.Tests.Models;
namespace View_by_Distance.Tests;
[TestClass]
public class UnitTestIsEnvironment
{
private readonly ILogger _Logger;
private readonly AppSettings _AppSettings;
private readonly string _WorkingDirectory;
private readonly IConfigurationRoot _ConfigurationRoot;
public UnitTestIsEnvironment()
{
ILogger logger;
AppSettings appSettings;
string workingDirectory;
IConfigurationRoot configurationRoot;
LoggerConfiguration loggerConfiguration = new();
Assembly assembly = Assembly.GetExecutingAssembly();
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddJsonFile("appsettings.Development.json");
configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
throw new Exception("Working directory name must have a value!");
workingDirectory = IWorkingDirectory.GetWorkingDirectory(assembly.GetName().Name, appSettings.WorkingDirectoryName);
Environment.SetEnvironmentVariable(nameof(workingDirectory), workingDirectory);
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
Log.Logger = loggerConfiguration.CreateLogger();
logger = Log.ForContext<UnitTestIsEnvironment>();
logger.Information("Complete");
_Logger = logger;
_AppSettings = appSettings;
_WorkingDirectory = workingDirectory;
_ConfigurationRoot = configurationRoot;
}
private static void NonThrowTryCatch()
{
try
{ throw new Exception(); }
catch (Exception) { }
}
[TestMethod]
public void TestMethodNull()
{
Assert.IsFalse(_Logger is null);
Assert.IsFalse(_AppSettings is null);
Assert.IsFalse(_WorkingDirectory is null);
Assert.IsFalse(_ConfigurationRoot is null);
}
[TestMethod]
public void TestMethodTest()
{
List<string> jsonFiles = new();
foreach (IConfigurationProvider configurationProvider in _ConfigurationRoot.Providers)
{
if (configurationProvider is not JsonConfigurationProvider jsonConfigurationProvider || jsonConfigurationProvider.Source.Path is null)
continue;
jsonFiles.Add(jsonConfigurationProvider.Source.Path);
}
Assert.IsTrue(jsonFiles.Any());
foreach (string jsonFile in jsonFiles)
_ = new IsEnvironment(jsonFile);
}
[TestMethod]
[TestCategory(nameof(IsEnvironment.Name.WindowsDevelopment))]
public void TestMethodTestCategory()
{
MethodBase? methodBase = new StackFrame().GetMethod();
if (methodBase is not null)
{
TestCategoryAttribute? testCategoryAttribute = methodBase.GetCustomAttribute<TestCategoryAttribute>();
if (testCategoryAttribute is not null)
{
foreach (string testCategory in testCategoryAttribute.TestCategories)
_ = new IsEnvironment(testCategory);
}
}
}
[TestMethod]
public void TestMethodHardcoded()
{
_ = new IsEnvironment(isDevelopment: true, isStaging: false, isProduction: false);
_ = new IsEnvironment(isDevelopment: false, isStaging: true, isProduction: false);
_ = new IsEnvironment(isDevelopment: false, isStaging: false, isProduction: true);
}
[TestMethod]
public void TestMethodAssembly()
{
Assembly assembly = Assembly.GetExecutingAssembly();
bool debuggerWasAttachedAtLineZero = Debugger.IsAttached || assembly.Location.Contains(@"\bin\Debug");
IsEnvironment isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
_ = IsEnvironment.GetEnvironmentName(isEnvironment);
}
}

View File

@ -42,7 +42,8 @@ public class UnitTestResize
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables() .AddEnvironmentVariables()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true); .AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
.AddUserSecrets<UnitTestResize>();
configurationRoot = configurationBuilder.Build(); configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot); appSettings = Models.Binder.AppSettings.Get(configurationRoot);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
@ -6,7 +6,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RuntimeIdentifier>win-x64</RuntimeIdentifier> <RuntimeIdentifier>win-x64</RuntimeIdentifier>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>
</PropertyGroup> <UserSecretsId>ecbdc76d-6037-4046-86a4-1a7626a3d342</UserSecretsId>
</PropertyGroup>
<PropertyGroup> <PropertyGroup>
<VSTestLogger>trx</VSTestLogger> <VSTestLogger>trx</VSTestLogger>
<VSTestCollect>XPlat Code Coverage</VSTestCollect> <VSTestCollect>XPlat Code Coverage</VSTestCollect>

View File

@ -37,7 +37,8 @@ public class UnitTestExample
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables() .AddEnvironmentVariables()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true); .AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
.AddUserSecrets<UnitTestExample>();
configurationRoot = configurationBuilder.Build(); configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot); appSettings = Models.Binder.AppSettings.Get(configurationRoot);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))

View File

@ -44,7 +44,8 @@ public class UnitTestFace
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder() IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
.AddEnvironmentVariables() .AddEnvironmentVariables()
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true); .AddJsonFile(isEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true)
.AddUserSecrets<UnitTestFace>();
configurationRoot = configurationBuilder.Build(); configurationRoot = configurationBuilder.Build();
appSettings = Models.Binder.AppSettings.Get(configurationRoot); appSettings = Models.Binder.AppSettings.Get(configurationRoot);
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName)) if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
@ -154,7 +155,7 @@ public class UnitTestFace
const int ToleranceAfterFactor = 600; const int ToleranceAfterFactor = 600;
Assert.IsTrue(DistanceDigits == 3); Assert.IsTrue(DistanceDigits == 3);
Assert.IsTrue(DistanceFactor == 1000); Assert.IsTrue(DistanceFactor == 1000);
Assert.IsTrue(_Configuration.RangeDistanceTolerance[1] == 0.6d); Assert.IsTrue(_Configuration.RangeDistanceTolerance[1] == 0.6f);
Assert.IsTrue(ToleranceAfterFactor == 600); Assert.IsTrue(ToleranceAfterFactor == 600);
double valueA = 0.00001d; double valueA = 0.00001d;
int checkA = (int)(Math.Round(valueA, _Configuration.LocationDigits) * _Configuration.LocationFactor); int checkA = (int)(Math.Round(valueA, _Configuration.LocationDigits) * _Configuration.LocationFactor);
@ -260,10 +261,10 @@ public class UnitTestFace
FaceRecognition faceRecognition = new(_Configuration.NumberOfJitters, _Configuration.NumberOfTimesToUpsample, model, modelParameter, predictorModel); FaceRecognition faceRecognition = new(_Configuration.NumberOfJitters, _Configuration.NumberOfTimesToUpsample, model, modelParameter, predictorModel);
List<(Location Location, FaceRecognitionDotNet.FaceEncoding? FaceEncoding, Dictionary<FacePart, FacePoint[]>? FaceParts)> collection; List<(Location Location, FaceRecognitionDotNet.FaceEncoding? FaceEncoding, Dictionary<FacePart, FacePoint[]>? FaceParts)> collection;
collection = faceRecognition.GetCollection(image, locations: new(), includeFaceEncoding: true, includeFaceParts: true); collection = faceRecognition.GetCollection(image, locations: new(), includeFaceEncoding: true, includeFaceParts: true);
Assert.IsTrue(collection.Count == 2); Assert.IsTrue(collection.Count == 1);
List<FaceDistance> faceDistanceEncodings = (from l in collection where l.FaceEncoding is not null select new FaceDistance(l.FaceEncoding)).ToList(); List<FaceDistance> faceDistanceEncodings = (from l in collection where l.FaceEncoding is not null select new FaceDistance(l.FaceEncoding)).ToList();
List<FaceDistance> faceDistanceLengths = FaceRecognition.FaceDistances(faceDistanceEncodings, faceDistanceEncodings[0]); List<FaceDistance> faceDistanceLengths = FaceRecognition.FaceDistances(faceDistanceEncodings, faceDistanceEncodings[0]);
Assert.IsTrue(faceDistanceLengths.Count == 2); Assert.IsTrue(faceDistanceLengths.Count == 1);
Assert.IsNotNull(sourceFileName); Assert.IsNotNull(sourceFileName);
NonThrowTryCatch(); NonThrowTryCatch();
} }