Fix random logic

This commit is contained in:
2023-08-12 08:30:08 -07:00
parent b3da09c757
commit 2f5d309ed1
10 changed files with 68 additions and 45 deletions

View File

@ -438,7 +438,7 @@ public partial class DlibDotNet
string[] changesFrom = new string[] { nameof(A_Property) };
FileHolder resizedFileHolder = _Resize.GetResizedFileHolder(cResultsFullGroupDirectory, item, outputResolutionHasNumber);
ReadOnlyCollection<LocationContainer<MetadataExtractor.Directory>> locationContainers = mapLogic.GetLocationContainers(item);
if (item.Property is null || item.Property.Id is null || item.Any())
if (item.Property is null || item.Property.Id is null || !item.SourceDirectoryFileHolder.Exists || item.SourceDirectoryFileHolder.CreationTime is null || item.SourceDirectoryFileHolder.LastWriteTime is null || item.Any())
{
LogItemPropertyIsNull(item);
int? propertyHashCode = item.Property?.GetHashCode();
@ -458,7 +458,12 @@ public partial class DlibDotNet
else
{
property = item.Property;
if (item.SourceDirectoryFileHolder.LastWriteTime is not null)
if (_Configuration.PropertyConfiguration.ForcePropertyLastWriteTimeToCreationTime && item.SourceDirectoryFileHolder.LastWriteTime.Value != item.SourceDirectoryFileHolder.CreationTime.Value)
{
File.SetLastWriteTime(item.SourceDirectoryFileHolder.FullName, item.SourceDirectoryFileHolder.CreationTime.Value);
subFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), item.SourceDirectoryFileHolder.CreationTime.Value));
}
else if (item.SourceDirectoryFileHolder.LastWriteTime is not null)
subFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), item.SourceDirectoryFileHolder.LastWriteTime.Value));
else
subFileTuples.Add(new Tuple<string, DateTime>(nameof(A_Property), new FileInfo(item.SourceDirectoryFileHolder.FullName).LastWriteTime));
@ -1107,8 +1112,8 @@ public partial class DlibDotNet
bool filesCollectionCountIsOne = false;
List<string[]>? filesCollection = null;
const string directorySearchFilter = "*";
Dictionary<long, List<int>> personKeyToIds;
bool configurationOutputResolutionsHas = false;
ReadOnlyDictionary<long, List<int>> personKeyToIds;
bool runToDoCollectionFirst = GetRunToDoCollectionFirst(ticks);
Dictionary<int, List<MappingFromPhotoPrism>> fileNameToCollection;
(aResultsFullGroupDirectory, bResultsFullGroupDirectory) = GetResultsFullGroupDirectories();

View File

@ -26,7 +26,7 @@ internal class F_Random
return result;
}
private static Dictionary<string, List<string>> Get(Dictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<Shared.Models.Mapping> mappingCollection, string dateFormat)
private static ReadOnlyDictionary<string, List<string>> GetDayToRelativePaths(ReadOnlyCollection<Shared.Models.Mapping> mappingCollection, string dateFormat, ReadOnlyDictionary<int, List<long>> idToPersonKeys)
{
Dictionary<string, List<string>> results = new();
string key;
@ -34,7 +34,6 @@ internal class F_Random
DateTime dateTime;
List<long>? personKeys;
List<string>? relativePaths;
Dictionary<int, List<long>> idToPersonKeys = Map.Models.Stateless.Methods.IMapLogic.GetIdToPersonKeys(personKeyToIds);
foreach (Shared.Models.Mapping mapping in mappingCollection)
{
if (mapping.MappingFromItem.ImageFileHolder.DirectoryName is null || mapping.MappingFromPerson is null)
@ -56,10 +55,10 @@ internal class F_Random
}
relativePaths.Add(mapping.MappingFromItem.RelativePath);
}
return results;
return new(results);
}
internal void Random(Property.Models.Configuration configuration, string[] validKeyWordsToIgnoreInRandom, string outputResolution, Dictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<Shared.Models.Mapping> mappingCollection)
internal void Random(Property.Models.Configuration configuration, string[] validKeyWordsToIgnoreInRandom, string outputResolution, ReadOnlyDictionary<long, List<int>> personKeyToIds, ReadOnlyCollection<Shared.Models.Mapping> mappingCollection)
{
string key;
string json;
@ -70,7 +69,8 @@ internal class F_Random
List<string> relativePaths = new();
List<int> distinctCollection = new();
DateTime dateTime = new(2024, 1, 1); //Leap year
Dictionary<string, List<string>> dayToRelativePaths = Get(personKeyToIds, mappingCollection, dateFormat);
ReadOnlyDictionary<int, List<long>> idToPersonKeys = Map.Models.Stateless.Methods.IMapLogic.GetIdToPersonKeys(personKeyToIds);
ReadOnlyDictionary<string, List<string>> dayToRelativePaths = GetDayToRelativePaths(mappingCollection, dateFormat, idToPersonKeys);
string fRandomCollectionDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(configuration, nameof(F_Random), "[]");
string[] files = Directory.GetFiles(fRandomCollectionDirectory, "*", SearchOption.TopDirectoryOnly);
foreach (string file in files)
@ -90,8 +90,9 @@ internal class F_Random
{
for (int i = 0; i < 366; i++)
{
random = new(i);
key = dateTime.AddDays(i).ToString(dateFormat);
if (dayToRelativePaths.TryGetValue(key, out collection) && collection.Count > 10)
if (dayToRelativePaths.TryGetValue(key, out collection) && collection.Count > 100)
collection = (from l in collection orderby random.NextDouble() select l).ToList();
else
collection = (from l in relativePaths orderby random.NextDouble() select l).ToList();