Removed old GetRectangle
RectangleIntersectMinimums AddUserSecrets
This commit is contained in:
parent
2ff966d6b0
commit
8863fd763f
@ -22,6 +22,7 @@ completedColumns:
|
||||
- [setup-photo-prism-again-in-wsl-docker](tasks/setup-photo-prism-again-in-wsl-docker.md)
|
||||
- [run-scan-originals](tasks/run-scan-originals.md)
|
||||
- [find-incorrectly-mapped-faces](tasks/find-incorrectly-mapped-faces.md)
|
||||
- [shrink-percent](tasks/shrink-percent.md)
|
||||
|
||||
## Done
|
||||
|
||||
|
13
.kanbn/tasks/shrink-percent.md
Normal file
13
.kanbn/tasks/shrink-percent.md
Normal 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
|
@ -17,12 +17,13 @@ public partial class E_Distance
|
||||
private readonly bool _DistanceRenameToMatch;
|
||||
private readonly float[] _RangeFaceConfidence;
|
||||
private readonly bool _DistanceMoveUnableToMatch;
|
||||
private readonly float _RectangleIntersectMinimum;
|
||||
private readonly List<string> _AllMappedFaceFiles;
|
||||
private readonly List<string> _AllMappedFaceFileNames;
|
||||
private readonly double _RangeDistanceToleranceAverage;
|
||||
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();
|
||||
_Moved = new();
|
||||
@ -35,6 +36,7 @@ public partial class E_Distance
|
||||
_DistanceRenameToMatch = distanceRenameToMatch;
|
||||
_FaceConfidencePercent = faceConfidencePercent;
|
||||
_DistanceMoveUnableToMatch = distanceMoveUnableToMatch;
|
||||
_RectangleIntersectMinimum = rectangleIntersectMinimum.Max();
|
||||
_RangeDistanceToleranceAverage = rangeDistanceTolerance.Average();
|
||||
}
|
||||
|
||||
@ -242,7 +244,7 @@ public partial class E_Distance
|
||||
throw new NotSupportedException();
|
||||
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())
|
||||
checkFaces.AddRange(GetClosestFaceByDistanceIgnoringTolerance(mappingFromItem, intersectFaces, modelsFaceEncoding));
|
||||
}
|
||||
|
@ -140,12 +140,6 @@ public class D_Face
|
||||
|
||||
#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)
|
||||
{
|
||||
PropertyItem result = (PropertyItem)_ConstructorInfo.Invoke(null);
|
||||
@ -304,7 +298,6 @@ public class D_Face
|
||||
{
|
||||
List<LocationContainer<MetadataExtractor.Directory>> results = new();
|
||||
string? json;
|
||||
int width, height;
|
||||
Location? location;
|
||||
Rectangle? rectangle;
|
||||
List<int> skip = new();
|
||||
@ -327,14 +320,12 @@ public class D_Face
|
||||
if (face.Location is not null && face.OutputResolution is not null)
|
||||
continue;
|
||||
json = Metadata.Models.Stateless.Methods.IMetadata.GetOutputResolution(locationContainer.Directories);
|
||||
if (json is not null)
|
||||
{
|
||||
outputResolutionCheck = JsonSerializer.Deserialize<OutputResolution>(json);
|
||||
if (outputResolutionCheck is not null && (outputResolutionCheck.Width != outputResolutionWidth || outputResolutionCheck.Height != outputResolutionHeight))
|
||||
continue;
|
||||
}
|
||||
(width, height) = Get(locationContainer.File);
|
||||
rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(height, ILocation.Digits, ILocation.Factor, locationContainer.NormalizedRectangle, outputResolutionHeight, outputResolutionWidth, width);
|
||||
if (json is null)
|
||||
continue;
|
||||
outputResolutionCheck = JsonSerializer.Deserialize<OutputResolution>(json);
|
||||
if (outputResolutionCheck is null || outputResolutionCheck.Width != outputResolutionWidth || outputResolutionCheck.Height != outputResolutionHeight)
|
||||
continue;
|
||||
rectangle = Shared.Models.Stateless.Methods.ILocation.GetRectangle(ILocation.Digits, locationContainer.NormalizedRectangle, outputResolutionCheck);
|
||||
if (rectangle is null)
|
||||
continue;
|
||||
location = Shared.Models.Stateless.Methods.ILocation.GetLocation(outputResolutionHeight, rectangle.Value, outputResolutionWidth);
|
||||
|
@ -106,7 +106,7 @@ public partial class DlibDotNet
|
||||
_FaceParts = new D2_FaceParts(imageCodecInfo, encoderParameters, filenameExtension, configuration.CheckDFaceAndUpWriteDates, configuration.OverrideForFaceLandmarkImages);
|
||||
}
|
||||
_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)
|
||||
{
|
||||
_GenealogicalDataCommunicationFooterLines = null;
|
||||
@ -783,7 +783,7 @@ public partial class DlibDotNet
|
||||
}
|
||||
Dictionary<int, Dictionary<int, Mapping>> idToNormalizedRectangleToMapping = Map.Models.Stateless.Methods.IMapLogic.GetIdToNormalizedRectangleToFace(distinctFilteredMappingCollection);
|
||||
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))
|
||||
mapLogic.SaveShortcutsForOutputResolutionsDuringMapLogic(containers, personKeyToIds, dFacesContentDirectory, distinctFilteredMappingCollection);
|
||||
if (!string.IsNullOrEmpty(_Configuration.PersonCharacters))
|
||||
|
@ -67,6 +67,7 @@ public class Configuration
|
||||
[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 = "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 = "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; }
|
||||
@ -200,6 +201,7 @@ public class Configuration
|
||||
throw new NullReferenceException(nameof(configuration.RangeFaceConfidence));
|
||||
if (configuration.RangeDistanceTolerance is null || configuration.RangeDistanceTolerance.Length != 3)
|
||||
throw new NullReferenceException(nameof(configuration.RangeDistanceTolerance));
|
||||
configuration.RectangleIntersectMinimums ??= Array.Empty<float>();
|
||||
if (configuration.Reverse is null)
|
||||
throw new NullReferenceException(nameof(configuration.Reverse));
|
||||
configuration.SaveBlurHashForOutputResolutions ??= Array.Empty<string>();
|
||||
@ -289,6 +291,7 @@ public class Configuration
|
||||
configuration.RangeDistanceTolerance,
|
||||
configuration.RangeFaceAreaTolerance,
|
||||
configuration.RangeFaceConfidence,
|
||||
configuration.RectangleIntersectMinimums,
|
||||
configuration.Reverse.Value,
|
||||
configuration.SaveBlurHashForOutputResolutions,
|
||||
configuration.SaveFaceDistancesForOutputResolutions,
|
||||
|
@ -63,6 +63,7 @@ public class Configuration
|
||||
public float[] RangeDistanceTolerance { init; get; }
|
||||
public float[] RangeFaceAreaTolerance { init; get; }
|
||||
public float[] RangeFaceConfidence { init; get; }
|
||||
public float[] RectangleIntersectMinimums { init; get; }
|
||||
public bool Reverse { init; get; }
|
||||
public string[] SaveBlurHashForOutputResolutions { init; get; }
|
||||
public string[] SaveFaceDistancesForOutputResolutions { init; get; }
|
||||
@ -141,6 +142,7 @@ public class Configuration
|
||||
float[] rangeDistanceTolerance,
|
||||
float[] rangeFaceAreaPermyriadTolerance,
|
||||
float[] rangeFaceConfidence,
|
||||
float[] rectangleIntersectMinimums,
|
||||
bool reverse,
|
||||
string[] saveBlurHashForOutputResolutions,
|
||||
string[] saveFaceDistancesForOutputResolutions,
|
||||
@ -218,6 +220,7 @@ public class Configuration
|
||||
RangeDistanceTolerance = rangeDistanceTolerance;
|
||||
RangeFaceAreaTolerance = rangeFaceAreaPermyriadTolerance;
|
||||
RangeFaceConfidence = rangeFaceConfidence;
|
||||
RectangleIntersectMinimums = rectangleIntersectMinimums;
|
||||
Reverse = reverse;
|
||||
SaveBlurHashForOutputResolutions = saveBlurHashForOutputResolutions;
|
||||
SaveFaceDistancesForOutputResolutions = saveFaceDistancesForOutputResolutions;
|
||||
|
@ -155,6 +155,9 @@
|
||||
0.2,
|
||||
0.8
|
||||
],
|
||||
"RectangleIntersectMinimums": [
|
||||
0.99
|
||||
],
|
||||
"IgnoreRelativePaths": [],
|
||||
"MixedYearRelativePaths": [],
|
||||
"SaveFaceDistancesForOutputResolutions": [],
|
||||
|
@ -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 text;
|
||||
double percent;
|
||||
int? normalizedRectangle;
|
||||
List<string> subjects = new();
|
||||
StringBuilder stringBuilder = new();
|
||||
PersonContainer[]? personContainers;
|
||||
StringBuilder stringBuilder = new();
|
||||
System.Drawing.Rectangle dlibRectangle;
|
||||
System.Drawing.Rectangle? prismRectangle;
|
||||
System.Drawing.Rectangle intersectRectangle;
|
||||
float rectangleIntersectMinimum = rectangleIntersectMinimums.Min();
|
||||
Dictionary<int, PersonContainer[]>? normalizedRectangleToPersonContainers;
|
||||
(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)[] sortedCollection;
|
||||
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)
|
||||
{
|
||||
prismRectangle = ILocation.GetRectangle(face.OutputResolution, mappingFromPhotoPrism.DatabaseFile, marker);
|
||||
prismRectangle = ILocation.GetRectangle(mappingFromPhotoPrism.DatabaseFile, marker, face.OutputResolution);
|
||||
if (prismRectangle is null)
|
||||
continue;
|
||||
intersectRectangle = System.Drawing.Rectangle.Intersect(dlibRectangle, prismRectangle.Value);
|
||||
if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0)
|
||||
continue;
|
||||
double percent = (double)intersectRectangle.Width * intersectRectangle.Height / (dlibRectangle.Width * dlibRectangle.Height);
|
||||
if (percent < 0.000001)
|
||||
percent = (double)intersectRectangle.Width * intersectRectangle.Height / (dlibRectangle.Width * dlibRectangle.Height);
|
||||
if (percent < rectangleIntersectMinimum)
|
||||
continue;
|
||||
collection.Add(new(mappingFromPhotoPrism, marker, percent));
|
||||
}
|
||||
@ -220,10 +222,10 @@ public class F_PhotoPrism
|
||||
}
|
||||
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());
|
||||
_ = 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();
|
||||
_ = IPath.WriteAllText(file, text, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
}
|
||||
|
@ -10,20 +10,20 @@ public interface ILocation
|
||||
static Models.Location? GetLocation(int height, Rectangle rectangle, int width) =>
|
||||
Location.GetLocation(height, rectangle, width);
|
||||
|
||||
List<Models.Face> TestStatic_FilterByIntersect(Models.Face[] faces, int normalizedRectangle) =>
|
||||
FilterByIntersect(faces, normalizedRectangle);
|
||||
static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle) =>
|
||||
Location.FilterByIntersect(faces, normalizedRectangle);
|
||||
List<Models.Face> TestStatic_FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) =>
|
||||
FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum);
|
||||
static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle, float rectangleIntersectMinimum) =>
|
||||
Location.FilterByIntersect(faces, normalizedRectangle, rectangleIntersectMinimum);
|
||||
|
||||
Rectangle? TestStatic_GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
GetRectangle(outputResolution, databaseFile, marker);
|
||||
static Rectangle? GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
Location.GetRectangle(outputResolution, databaseFile, marker);
|
||||
Rectangle? TestStatic_GetRectangle(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
|
||||
GetRectangle(databaseFile, marker, outputResolution);
|
||||
static Rectangle? GetRectangle(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
|
||||
Location.GetRectangle(databaseFile, marker, outputResolution);
|
||||
|
||||
Models.Location? TestStatic_GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
GetLocation(outputResolution, databaseFile, marker);
|
||||
static Models.Location? GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
Location.GetLocation(outputResolution, databaseFile, marker);
|
||||
Models.Location? TestStatic_GetLocation(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
|
||||
GetLocation(databaseFile, marker, outputResolution);
|
||||
static Models.Location? GetLocation(DatabaseFile databaseFile, Marker marker, Models.OutputResolution outputResolution) =>
|
||||
Location.GetLocation(databaseFile, marker, outputResolution);
|
||||
|
||||
List<Models.Location> TestStatic_GetLocations<T>(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces, List<LocationContainer<T>> containers) =>
|
||||
GetLocations(mappingFromPhotoPrismCollection, faces, containers);
|
||||
@ -35,15 +35,10 @@ public interface ILocation
|
||||
static Rectangle? GetNormalizedRectangle(int locationDigits, int normalizedRectangle) =>
|
||||
Location.GetNormalizedRectangle(locationDigits, normalizedRectangle.ToString());
|
||||
|
||||
Rectangle? TestStatic_GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) =>
|
||||
GetRectangle(checkRectangle, locationDigits, locationFactor, normalizedRectangle, outputResolution, useOldWay);
|
||||
static Rectangle? GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) =>
|
||||
Location.GetRectangle(checkRectangle, OutputResolution.Get(outputResolution).Height, locationDigits, locationFactor, normalizedRectangle.ToString(), OutputResolution.Get(outputResolution).Width, useOldWay);
|
||||
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);
|
||||
Rectangle? TestStatic_GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) =>
|
||||
GetRectangle(locationDigits, normalizedRectangle, outputResolution);
|
||||
static Rectangle? GetRectangle(int locationDigits, int normalizedRectangle, Models.OutputResolution outputResolution) =>
|
||||
Location.GetRectangle(locationDigits, normalizedRectangle.ToString(), outputResolution);
|
||||
|
||||
string TestStatic_GetLeftPadded(int locationDigits, string value) =>
|
||||
GetLeftPadded(locationDigits, value);
|
||||
@ -60,11 +55,6 @@ public interface ILocation
|
||||
static string GetLeftPadded(int locationDigits, int value) =>
|
||||
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) =>
|
||||
GetLocation(location, locationDigits, locationFactor, height, width, zCount);
|
||||
static Models.Location? GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
|
||||
|
@ -108,30 +108,6 @@ internal abstract class Location
|
||||
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)
|
||||
{
|
||||
int result = (int)(confidence / rangeFaceConfidence[1] * faceConfidencePercent);
|
||||
@ -162,7 +138,7 @@ internal abstract class Location
|
||||
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? rectangle = GetNormalizedRectangle(locationDigits, normalizedRectangle);
|
||||
@ -176,42 +152,15 @@ internal abstract class Location
|
||||
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;
|
||||
if (useOldWay)
|
||||
{
|
||||
(int? x, int? y) = GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
|
||||
if (x is null || y is null)
|
||||
throw new Exception();
|
||||
result = new(x.Value - (checkRectangle.Width / 2), y.Value - (checkRectangle.Height / 2), checkRectangle.Width, checkRectangle.Height);
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (normalizedRectangle.Length != locationDigits || normalizedRectangle[0] is not '4' and not '8')
|
||||
throw new NotSupportedException("Old way has been removed!");
|
||||
(int width, int height) = OutputResolution.Get(outputResolution);
|
||||
result = GetRectangle(height, locationDigits, normalizedRectangle, width);
|
||||
if (result is null)
|
||||
throw new NullReferenceException(nameof(result));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -221,7 +170,7 @@ internal abstract class Location
|
||||
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;
|
||||
bool matches = Matches(outputResolution, databaseFile);
|
||||
@ -255,10 +204,10 @@ internal abstract class Location
|
||||
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;
|
||||
Rectangle? rectangle = GetRectangle(outputResolution, databaseFile, marker);
|
||||
Rectangle? rectangle = GetRectangle(databaseFile, marker, outputResolution);
|
||||
if (rectangle is null)
|
||||
result = null;
|
||||
else
|
||||
@ -300,7 +249,7 @@ internal abstract class Location
|
||||
foreach (Marker marker in mappingFromPhotoPrism.Markers)
|
||||
{
|
||||
any = false;
|
||||
prismRectangle = GetRectangle(outputResolution, mappingFromPhotoPrism.DatabaseFile, marker);
|
||||
prismRectangle = GetRectangle(mappingFromPhotoPrism.DatabaseFile, marker, outputResolution);
|
||||
if (prismRectangle is null)
|
||||
break;
|
||||
location = GetLocation(mappingFromPhotoPrism.DatabaseFile, marker, prismRectangle.Value);
|
||||
@ -341,10 +290,9 @@ internal abstract class Location
|
||||
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();
|
||||
bool useOldWay;
|
||||
double? percent;
|
||||
Rectangle checkRectangle;
|
||||
Rectangle? sourceRectangle;
|
||||
@ -354,20 +302,16 @@ internal abstract class Location
|
||||
if (face.Location is null || face.OutputResolution is null)
|
||||
continue;
|
||||
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++)
|
||||
{
|
||||
useOldWay = i == 1;
|
||||
sourceRectangle = ILocation.GetRectangle(checkRectangle, Stateless.ILocation.Digits, Stateless.ILocation.Factor, normalizedRectangle, face.OutputResolution, useOldWay);
|
||||
if (sourceRectangle is null)
|
||||
continue;
|
||||
intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value);
|
||||
if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0)
|
||||
continue;
|
||||
percent = (double)intersectRectangle.Width * intersectRectangle.Height / (checkRectangle.Width * checkRectangle.Height);
|
||||
if (percent < 0.000001)
|
||||
continue;
|
||||
results.Add(face);
|
||||
}
|
||||
sourceRectangle = GetRectangle(Stateless.ILocation.Digits, normalizedRectangle.ToString(), face.OutputResolution);
|
||||
if (sourceRectangle is null)
|
||||
continue;
|
||||
intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value);
|
||||
if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0)
|
||||
continue;
|
||||
percent = (double)intersectRectangle.Width * intersectRectangle.Height / (checkRectangle.Width * checkRectangle.Height);
|
||||
if (percent < rectangleIntersectMinimum)
|
||||
continue;
|
||||
results.Add(face);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
@ -6,6 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<UserSecretsId>e8c3d25d-9715-4b35-9010-1cdc74840190</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<VSTestLogger>trx</VSTestLogger>
|
||||
|
@ -39,7 +39,8 @@ public partial class UnitTestCalculations
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.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();
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
@ -93,6 +94,7 @@ public partial class UnitTestCalculations
|
||||
throw new NullReferenceException(nameof(age));
|
||||
Assert.IsNotNull(age);
|
||||
Assert.IsTrue(age.Value > 42.6092);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -114,6 +116,7 @@ public partial class UnitTestCalculations
|
||||
Assert.IsTrue($"({l}{d.ToString("0.00")[1..]})" == "(637967784888423594.62)");
|
||||
d = 0.45;
|
||||
Assert.IsTrue($"({l}{d.ToString("0.00")[1..]})" == "(637967784888423594.45)");
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -123,6 +126,7 @@ public partial class UnitTestCalculations
|
||||
Assert.IsTrue(successful == "_ Manual Copy Successful");
|
||||
string verify = $"_ {nameof(Shared.Models.Stateless.IMapLogic.ManualCopy).Humanize(LetterCasing.Title)} Verify";
|
||||
Assert.IsTrue(verify == "_ Manual Copy Verify");
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -154,6 +158,7 @@ public partial class UnitTestCalculations
|
||||
// "7680x4320 - Hog - Large"
|
||||
// [8] [string]:
|
||||
// "()"
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -170,6 +175,7 @@ public partial class UnitTestCalculations
|
||||
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(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -186,7 +192,7 @@ public partial class UnitTestCalculations
|
||||
width = 100;
|
||||
height = 100;
|
||||
areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, bottom, height, left, right, top, width);
|
||||
Assert.IsTrue(areaPermyriad == 1000);
|
||||
Assert.IsTrue(areaPermyriad == 10000);
|
||||
left = 0;
|
||||
right = 50;
|
||||
top = 0;
|
||||
@ -195,7 +201,7 @@ public partial class UnitTestCalculations
|
||||
height = 100;
|
||||
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);
|
||||
Assert.IsTrue(areaPermyriad == 250);
|
||||
Assert.IsTrue(areaPermyriad == 2500);
|
||||
left = 0;
|
||||
right = 25;
|
||||
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);
|
||||
OutputResolution outputResolution = new(height, 0, width);
|
||||
areaPermyriad = IMapping.GetAreaPermyriad(faceAreaPermyriad, location, outputResolution);
|
||||
Assert.IsTrue(areaPermyriad == 62);
|
||||
}
|
||||
|
||||
[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);
|
||||
Assert.IsTrue(areaPermyriad == 625);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -241,6 +225,7 @@ public partial class UnitTestCalculations
|
||||
y2 = 10f;
|
||||
double distance = Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
|
||||
Assert.IsTrue(distance == 1.4142135623730951);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
@ -266,6 +251,7 @@ public partial class UnitTestCalculations
|
||||
value = 1.6f;
|
||||
check = ILocation.GetConfidencePercent(faceConfidencePercent, new float[] { minimum, target, maximum }, value);
|
||||
Assert.IsTrue(check == 200);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
@ -36,7 +36,9 @@ public class UnitTestExample
|
||||
isEnvironment = new(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: debuggerWasAttachedAtLineZero, nullASPNetCoreEnvironmentIsProduction: !debuggerWasAttachedAtLineZero);
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.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();
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
|
@ -38,7 +38,8 @@ public partial class UnitTestHardCoded
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.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();
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
@ -83,10 +84,13 @@ public partial class UnitTestHardCoded
|
||||
[TestMethod]
|
||||
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)";
|
||||
for (int i = 1; i < 11; i++)
|
||||
_ = IPath.DeleteEmptyDirectories(source);
|
||||
Assert.IsTrue(true);
|
||||
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)";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
for (int i = 1; i < 11; i++)
|
||||
_ = IPath.DeleteEmptyDirectories(directory);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -114,50 +118,16 @@ public partial class UnitTestHardCoded
|
||||
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]
|
||||
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)";
|
||||
for (int i = 1; i < 11; i++)
|
||||
_ = IPath.DeleteEmptyDirectories(source);
|
||||
Assert.IsTrue(true);
|
||||
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)";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
for (int i = 1; i < 11; i++)
|
||||
_ = IPath.DeleteEmptyDirectories(directory);
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
@ -230,87 +200,100 @@ public partial class UnitTestHardCoded
|
||||
[TestMethod]
|
||||
public void TestMethodRenameAbandoned()
|
||||
{
|
||||
string checkFile;
|
||||
string source = @"D:\1) Images A\Images-1e85c0ba-Results\A2) People\1e85c0ba\{}\!\Abandoned";
|
||||
string[] files = Directory.GetFiles(source, "*.abd", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
string directory = @"D:\1) Images A\Images-1e85c0ba-Results\A2) People\1e85c0ba\{}\!\Abandoned";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
checkFile = file[..^4];
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
string checkFile;
|
||||
string[] files = Directory.GetFiles(directory, "*.abd", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
checkFile = file[..^4];
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
Assert.IsTrue(true);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethodRenameDelete()
|
||||
{
|
||||
string checkFile;
|
||||
string source = @"D:\1) Images A\Images-1e85c0ba-Results\A) Property\1e85c0ba\{}";
|
||||
string[] files = Directory.GetFiles(source, "*.del", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
string directory = @"D:\1) Images A\Images-1e85c0ba-Results\A) Property\1e85c0ba\{}";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
checkFile = file[..^4];
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
string checkFile;
|
||||
string[] files = Directory.GetFiles(directory, "*.del", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
{
|
||||
checkFile = file[..^4];
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
Assert.IsTrue(true);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethodRenameOld()
|
||||
{
|
||||
string checkFile;
|
||||
string source = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba-Results\E) Distance\1e85c0ba\()";
|
||||
string[] files = Directory.GetFiles(source, "*.old", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
string directory = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba-Results\E) Distance\1e85c0ba\()";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
checkFile = file[..^4];
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
string checkFile;
|
||||
string[] files = Directory.GetFiles(directory, "*.old", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
{
|
||||
checkFile = file[..^4];
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
Assert.IsTrue(true);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethodAncestryGenealogicalDataCommunication()
|
||||
{
|
||||
List<string> mappedLines;
|
||||
Dictionary<string, List<string>> individuals;
|
||||
GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
|
||||
List<(bool, string)> genealogicalDataCommunicationFiles = new()
|
||||
string directory = "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
new(false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Roberts/Roberts Family Tree.ged"),
|
||||
new(false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Phares/Phares Jr Family Tree.ged"),
|
||||
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160708345114583/638160708345114583.ged"),
|
||||
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160728606500015/638160728606500015.ged"),
|
||||
new(true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160738845419877/638160738845419877.ged"),
|
||||
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)
|
||||
List<string> mappedLines;
|
||||
Dictionary<string, List<string>> individuals;
|
||||
GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
|
||||
List<(bool, string)> genealogicalDataCommunicationFiles = new()
|
||||
{
|
||||
genealogicalDataCommunicationLines = IGenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(keyValuePair.Value);
|
||||
Assert.IsNotNull(genealogicalDataCommunicationLines.Name);
|
||||
genealogicalDataCommunication = IGenealogicalDataCommunication.GetGenealogicalDataCommunication(genealogicalDataCommunicationLines);
|
||||
Assert.IsNotNull(genealogicalDataCommunication.Name);
|
||||
new(false, Path.Combine(directory, "Ancestry-Roberts/Roberts Family Tree.ged")),
|
||||
new(false, Path.Combine(directory, "Ancestry-Phares/Phares Jr Family Tree.ged")),
|
||||
new(true, Path.Combine(directory, "Code-638160708345114583/638160708345114583.ged")),
|
||||
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();
|
||||
}
|
||||
@ -318,71 +301,74 @@ public partial class UnitTestHardCoded
|
||||
[TestMethod]
|
||||
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;
|
||||
Dictionary<string, List<string>> individuals;
|
||||
GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
|
||||
string saveDirectory = $"D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-{dateTime.Ticks}";
|
||||
List<(bool, bool, string)> genealogicalDataCommunicationFiles = new()
|
||||
string saveDirectory = "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])";
|
||||
if (Directory.Exists(Path.GetPathRoot(saveDirectory)) && Directory.Exists(saveDirectory))
|
||||
{
|
||||
new(false, false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Roberts/Roberts Family Tree.ged.cln"),
|
||||
new(false, false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Phares/Phares Jr Family Tree.ged.cln"),
|
||||
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160708345114583/638160708345114583.ged.cln"),
|
||||
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160728606500015/638160728606500015.ged.cln"),
|
||||
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160738845419877/638160738845419877.ged.cln"),
|
||||
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160743318283885/638160743318283885.ged.cln"),
|
||||
new(false, false, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Ancestry-Porterfield/Porterfield Family Tree.ged.cln"),
|
||||
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160708345114583/638160708345114583-Export.ged.cln"),
|
||||
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160738845419877/638160738845419877-Export.ged.cln"),
|
||||
new(true, true, "D:/1) Images A/Images-1e85c0ba-Results/A2) People/1e85c0ba/([])/Code-638160743318283885/638160743318283885-Export.ged.cln"),
|
||||
};
|
||||
foreach ((bool verify, bool requireNickName, string genealogicalDataCommunicationFile) in genealogicalDataCommunicationFiles)
|
||||
{
|
||||
fileName = Path.GetFileNameWithoutExtension(genealogicalDataCommunicationFile).Split(' ')[0];
|
||||
(_, individuals, _) = IGenealogicalDataCommunication.GetIndividuals(genealogicalDataCommunicationFile, requireNickName);
|
||||
foreach (KeyValuePair<string, List<string>> keyValuePair in individuals)
|
||||
int age;
|
||||
long personKey;
|
||||
string ageGroup;
|
||||
string fileName;
|
||||
string? directory;
|
||||
bool first = true;
|
||||
PersonName? personName;
|
||||
string personKeyFormatted;
|
||||
bool isDefaultName = false;
|
||||
Dictionary<string, List<string>> individuals;
|
||||
GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines genealogicalDataCommunicationLines;
|
||||
List<(bool, bool, string)> genealogicalDataCommunicationFiles = new()
|
||||
{
|
||||
genealogicalDataCommunicationLines = IGenealogicalDataCommunication.GetGenealogicalDataCommunicationLines(keyValuePair.Value);
|
||||
Assert.IsNotNull(genealogicalDataCommunicationLines.Name);
|
||||
genealogicalDataCommunication = IGenealogicalDataCommunication.GetGenealogicalDataCommunication(genealogicalDataCommunicationLines);
|
||||
Assert.IsNotNull(genealogicalDataCommunication.Name);
|
||||
if (genealogicalDataCommunication.Birth is null)
|
||||
continue;
|
||||
personName = IPersonName.GetPersonName(genealogicalDataCommunication);
|
||||
if (personName is null)
|
||||
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);
|
||||
new(false, false, Path.Combine(saveDirectory, "Ancestry-Roberts/Roberts Family Tree.ged.cln")),
|
||||
new(false, false, Path.Combine(saveDirectory, "Ancestry-Phares/Phares Jr Family Tree.ged.cln")),
|
||||
new(true, true, Path.Combine(saveDirectory, "Code-638160708345114583/638160708345114583.ged.cln")),
|
||||
new(true, true, Path.Combine(saveDirectory, "Code-638160728606500015/638160728606500015.ged.cln")),
|
||||
new(true, true, Path.Combine(saveDirectory, "Code-638160738845419877/638160738845419877.ged.cln")),
|
||||
new(true, true, Path.Combine(saveDirectory, "Code-638160743318283885/638160743318283885.ged.cln")),
|
||||
new(false, false, Path.Combine(saveDirectory, "Ancestry-Porterfield/Porterfield Family Tree.ged.cln")),
|
||||
new(true, true, Path.Combine(saveDirectory, "Code-638160708345114583/638160708345114583-Export.ged.cln")),
|
||||
new(true, true, Path.Combine(saveDirectory, "Code-638160738845419877/638160738845419877-Export.ged.cln")),
|
||||
new(true, true, Path.Combine(saveDirectory, "Code-638160743318283885/638160743318283885-Export.ged.cln")),
|
||||
};
|
||||
foreach ((bool verify, bool requireNickName, string genealogicalDataCommunicationFile) in genealogicalDataCommunicationFiles)
|
||||
{
|
||||
fileName = Path.GetFileNameWithoutExtension(genealogicalDataCommunicationFile).Split(' ')[0];
|
||||
(_, 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);
|
||||
if (genealogicalDataCommunication.Birth is null)
|
||||
continue;
|
||||
personName = IPersonName.GetPersonName(genealogicalDataCommunication);
|
||||
if (personName is null)
|
||||
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();
|
||||
}
|
||||
|
||||
private static string[] GetFamily() => new string[]{
|
||||
private static string[] GetFamily() => new string[] {
|
||||
"UBertha Scott (Barry Scott) 10/2/1900-8/19/1993",
|
||||
"MEarl Daniel Herman 1/5/1918-10/19/1962",
|
||||
"FGlendola Koch 8/10/1919-5/16/1910",
|
||||
@ -592,7 +578,7 @@ public partial class UnitTestHardCoded
|
||||
"MDevan Hazen 8/14/1999",
|
||||
"MEthan Hazen 8/14/1999",
|
||||
"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
|
||||
"MChris Olson 11/13/1951",
|
||||
"FShilo Zeches 4/9/1980",
|
||||
@ -675,66 +661,70 @@ public partial class UnitTestHardCoded
|
||||
[TestMethod]
|
||||
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;
|
||||
GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
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(' ');
|
||||
dateSegments = spaceSegments[^1].Split('-');
|
||||
name = string.Join(' ', spaceSegments[..^1]);
|
||||
if (!DateTime.TryParse(dateSegments[0], out parseDateTime))
|
||||
continue;
|
||||
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
|
||||
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();
|
||||
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))
|
||||
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();
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void TestMethodGroup()
|
||||
{
|
||||
@ -761,14 +751,18 @@ public partial class UnitTestHardCoded
|
||||
[TestMethod]
|
||||
public void TestMethodRename()
|
||||
{
|
||||
// string[] directories = Directory.GetDirectories(@"D:\2) Images B\Not-Copy-Copy-1e85c0ba", "*;*", SearchOption.AllDirectories);
|
||||
string[] directories = Directory.GetDirectories(@"D:\1) Images A\Images-1e85c0ba", "*;*", SearchOption.AllDirectories);
|
||||
// string[] directories = Directory.GetDirectories(@"D:\2) Images B\Not-Copy-Copy-1e85c0ba", "*", SearchOption.AllDirectories);
|
||||
foreach (string directory in directories.OrderByDescending(l => l.Length - l.Replace(@"\", string.Empty).Length))
|
||||
// string directory = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba";
|
||||
string directory = @"D:\1) Images A\Images-1e85c0ba";
|
||||
// string directory = @"D:\2) Images B\Not-Copy-Copy-1e85c0ba";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
if (!directory.EndsWith(";9"))
|
||||
continue;
|
||||
Directory.Move(directory, $"{directory[..^2]} !9");
|
||||
string[] directories = Directory.GetDirectories(directory, "*;*", SearchOption.AllDirectories);
|
||||
foreach (string subDirectory in directories.OrderByDescending(l => l.Length - l.Replace(@"\", string.Empty).Length))
|
||||
{
|
||||
if (!subDirectory.EndsWith(";9"))
|
||||
continue;
|
||||
Directory.Move(subDirectory, $"{subDirectory[..^2]} !9");
|
||||
}
|
||||
}
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
@ -776,9 +770,13 @@ public partial class UnitTestHardCoded
|
||||
[TestMethod]
|
||||
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);
|
||||
foreach (string file in files)
|
||||
File.Move(file, file[..^4]);
|
||||
string directory = @"D:\1) Images A\Images-1e85c0ba-Results\E) Distance\1e85c0ba\(RectInt-2023-06-19-less-0.99)";
|
||||
if (Directory.Exists(Path.GetPathRoot(directory)) && Directory.Exists(directory))
|
||||
{
|
||||
string[] files = Directory.GetFiles(directory, "*.unk", SearchOption.AllDirectories);
|
||||
foreach (string file in files)
|
||||
File.Move(file, file[..^4]);
|
||||
}
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -42,7 +42,8 @@ public class UnitTestResize
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.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();
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<IsPackable>false</IsPackable>
|
||||
@ -6,7 +6,8 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<UserSecretsId>ecbdc76d-6037-4046-86a4-1a7626a3d342</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<VSTestLogger>trx</VSTestLogger>
|
||||
<VSTestCollect>XPlat Code Coverage</VSTestCollect>
|
||||
|
@ -37,7 +37,8 @@ public class UnitTestExample
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.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();
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
|
@ -44,7 +44,8 @@ public class UnitTestFace
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.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();
|
||||
appSettings = Models.Binder.AppSettings.Get(configurationRoot);
|
||||
if (string.IsNullOrEmpty(appSettings.WorkingDirectoryName))
|
||||
@ -154,7 +155,7 @@ public class UnitTestFace
|
||||
const int ToleranceAfterFactor = 600;
|
||||
Assert.IsTrue(DistanceDigits == 3);
|
||||
Assert.IsTrue(DistanceFactor == 1000);
|
||||
Assert.IsTrue(_Configuration.RangeDistanceTolerance[1] == 0.6d);
|
||||
Assert.IsTrue(_Configuration.RangeDistanceTolerance[1] == 0.6f);
|
||||
Assert.IsTrue(ToleranceAfterFactor == 600);
|
||||
double valueA = 0.00001d;
|
||||
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);
|
||||
List<(Location Location, FaceRecognitionDotNet.FaceEncoding? FaceEncoding, Dictionary<FacePart, FacePoint[]>? FaceParts)> collection;
|
||||
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> faceDistanceLengths = FaceRecognition.FaceDistances(faceDistanceEncodings, faceDistanceEncodings[0]);
|
||||
Assert.IsTrue(faceDistanceLengths.Count == 2);
|
||||
Assert.IsTrue(faceDistanceLengths.Count == 1);
|
||||
Assert.IsNotNull(sourceFileName);
|
||||
NonThrowTryCatch();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user