This commit is contained in:
2022-08-22 09:10:19 -07:00
parent f72fcee1db
commit bc2174b17a
150 changed files with 4323 additions and 6259 deletions

View File

@ -7,6 +7,7 @@ using System.Drawing.Imaging;
using System.Reflection;
using View_by_Distance.Metadata.Models;
using View_by_Distance.Resize.Models;
using View_by_Distance.Shared.Models;
using View_by_Distance.Shared.Models.Stateless;
using View_by_Distance.Shared.Models.Stateless.Methods;
using View_by_Distance.Tests.Models;
@ -48,8 +49,8 @@ public class UnitTestResize
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
Log.Logger = loggerConfiguration.CreateLogger();
logger = Log.ForContext<UnitTestResize>();
propertyConfiguration = Property.Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory);
configuration = Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory, propertyConfiguration);
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
logger.Information("Complete");
_Logger = logger;
_AppSettings = appSettings;
@ -72,12 +73,97 @@ public class UnitTestResize
Assert.IsFalse(_PropertyConfiguration is null);
}
private Property.Models.PropertyLogic GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel)
[TestMethod]
public void TestGetLocation()
{
Property.Models.PropertyLogic result;
double confidence = 0.1D;
int left, top, right, bottom, width, height;
left = 20;
top = 40;
right = 60;
bottom = 80;
width = 100;
height = 100;
Location location = new(bottom, confidence, left, null, right, top);
_ = new Location(confidence, height, location, width, 1);
_ = new Location(bottom, confidence, height, left, right, top, width, 1);
}
[TestMethod]
public void TestGetPixelPercentage()
{
int normalizedPixelPercentage;
int left, top, right, bottom, width, height;
left = 1;
top = 1;
right = 10;
bottom = 10;
width = 100;
height = 100;
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 40500);
left = 50;
top = 50;
right = 60;
bottom = 60;
width = 100;
height = 100;
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 545500);
}
[TestMethod]
public void TestGetPixelPercentageB()
{
int normalizedPixelPercentage;
int left, top, right, bottom, width, height;
left = 240;
top = 240;
right = 260;
bottom = 260;
width = 500;
height = 500;
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 499000);
left = 490;
top = 490;
right = 510;
bottom = 510;
width = 1000;
height = 1000;
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 499500);
}
[TestMethod]
public void TestGetPixelPercentageC()
{
int normalizedPixelPercentage;
int left, top, right, bottom, width, height;
left = 20;
top = 40;
right = 60;
bottom = 80;
width = 100;
height = 100;
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 1);
Assert.IsTrue(normalizedPixelPercentage == 594000);
left = 20;
top = 40;
right = 60;
bottom = 80;
width = 100;
height = 100;
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width, 10);
Assert.IsTrue(normalizedPixelPercentage == 594000);
}
private Property.Models.A_Property GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel)
{
Property.Models.A_Property result;
if (_Configuration?.PropertyConfiguration is null)
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, reverse, model, predictorModel);
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _Configuration.OutputExtension, reverse, model, predictorModel);
return result;
}
@ -88,21 +174,9 @@ public class UnitTestResize
// string sourceDirectoryName = "Mackenzie Prom 2017";
string sourceFileName = "Fall 2005 (113).jpg";
string sourceDirectoryName = "=2005.3 Fall";
if (_Configuration.ForceMetadataLastWriteTimeToCreationTime is null)
throw new NullReferenceException(nameof(_Configuration.ForceMetadataLastWriteTimeToCreationTime));
if (_Configuration.ForceResizeLastWriteTimeToCreationTime is null)
throw new NullReferenceException(nameof(_Configuration.ForceResizeLastWriteTimeToCreationTime));
if (_Configuration.OutputQuality is null)
throw new NullReferenceException(nameof(_Configuration.OutputQuality));
if (_Configuration.OverrideForResizeImages is null)
throw new NullReferenceException(nameof(_Configuration.OverrideForResizeImages));
if (_Configuration.PropertiesChangedForMetadata is null)
throw new NullReferenceException(nameof(_Configuration.PropertiesChangedForMetadata));
if (_Configuration.PropertiesChangedForResize is null)
throw new NullReferenceException(nameof(_Configuration.PropertiesChangedForResize));
Item item;
Model? model = null;
bool reverse = false;
Property.Models.Item item;
string original = "Original";
string aResultsFullGroupDirectory;
string bResultsFullGroupDirectory;
@ -110,13 +184,13 @@ public class UnitTestResize
List<string> parseExceptions = new();
PredictorModel? predictorModel = null;
bool isValidImageFormatExtension = true;
Property.Models.A_Property? property = null;
Shared.Models.Property? property = null;
Dictionary<string, int[]> imageResizeKeyValuePairs;
List<Tuple<string, DateTime>> subFileTuples = new();
List<KeyValuePair<string, string>> metadataCollection;
int length = _PropertyConfiguration.RootDirectory.Length;
string outputResolution = _Configuration.OutputResolutions[0];
Property.Models.PropertyLogic propertyLogic = GetPropertyLogic(reverse, model, predictorModel);
Property.Models.A_Property propertyLogic = GetPropertyLogic(reverse, model, predictorModel);
string sourceDirectory = Path.Combine(_PropertyConfiguration.RootDirectory, sourceDirectoryName);
_Logger.Information(_Configuration.ModelDirectory);
aResultsFullGroupDirectory = Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(
@ -126,9 +200,11 @@ public class UnitTestResize
cResultsFullGroupDirectory = Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(
_PropertyConfiguration, model, predictorModel, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false);
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_PropertyConfiguration, nameof(Property.Models.A_Property), "{}");
B_Metadata metadata = new(_Configuration.ForceMetadataLastWriteTimeToCreationTime.Value, _Configuration.PropertiesChangedForMetadata.Value);
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters) = C_Resize.GetTuple(_Configuration.OutputExtension, _Configuration.OutputQuality.Value);
C_Resize resize = new(_Configuration.ForceResizeLastWriteTimeToCreationTime.Value, _Configuration.OverrideForResizeImages.Value, _Configuration.PropertiesChangedForResize.Value, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters);
B_Metadata metadata = new(_Configuration.ForceMetadataLastWriteTimeToCreationTime, _Configuration.PropertiesChangedForMetadata);
_ = metadata.ToString();
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetTuple(_Configuration.OutputExtension, _Configuration.OutputQuality);
C_Resize resize = new(_Configuration.ForceResizeLastWriteTimeToCreationTime, _Configuration.OverrideForResizeImages, _Configuration.PropertiesChangedForResize, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters, filenameExtension);
_ = resize.ToString();
propertyLogic.AngleBracketCollection.AddRange(Property.Models.Stateless.IResult.GetDirectoryInfoCollection(
_PropertyConfiguration,
sourceDirectory,
@ -154,8 +230,8 @@ public class UnitTestResize
collectionDescription: string.Empty,
converted: true));
string sourceDirectoryFile = ".json";
Property.Models.FileHolder fileHolder = new(Path.Combine(sourceDirectory, sourceFileName));
string relativePath = Property.Models.Stateless.IPath.GetRelativePath(fileHolder.FullName, length);
FileHolder fileHolder = new(Path.Combine(sourceDirectory, sourceFileName));
string relativePath = IPath.GetRelativePath(fileHolder.FullName, length);
sourceDirectory = Path.Combine(aPropertySingletonDirectory, sourceDirectoryName);
item = new(sourceDirectoryFile, relativePath, fileHolder, isValidImageFormatExtension, property, false, false);
Assert.IsNotNull(item.ImageFileHolder);
@ -166,10 +242,10 @@ public class UnitTestResize
}
(int _, metadataCollection) = metadata.GetMetadataCollection(bResultsFullGroupDirectory, subFileTuples, parseExceptions, item);
imageResizeKeyValuePairs = resize.GetResizeKeyValuePairs(cResultsFullGroupDirectory, subFileTuples, parseExceptions, original, metadataCollection, item);
Property.Models.FileHolder resizedFileHolder = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(item.ImageFileHolder.FullName)));
item.SetResizedFileHolder(resizedFileHolder);
FileHolder resizedFileHolder = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(item.ImageFileHolder.FullName)));
item.SetResizedFileHolder(resize.FilenameExtension, resizedFileHolder);
resize.SaveResizedSubfile(outputResolution, cResultsFullGroupDirectory, subFileTuples, item, original, imageResizeKeyValuePairs);
item.SetResizedFileHolder(Property.Models.FileHolder.Refresh(resizedFileHolder));
item.SetResizedFileHolder(resize.FilenameExtension, IFileHolder.Refresh(resizedFileHolder));
}
}