Fix random logic
This commit is contained in:
@ -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();
|
||||
|
Reference in New Issue
Block a user