@ -1,6 +1,7 @@
using Microsoft.Extensions.Configuration ;
using Phares.Shared ;
using ShellProgressBar ;
using System.Diagnostics ;
using System.Drawing.Imaging ;
using System.Text.Json ;
using View_by_Distance.Distance.Models ;
@ -686,7 +687,7 @@ public partial class DlibDotNet
nullablePropertyCollection . Clear ( ) ;
propertyFileHolderCollection . Clear ( ) ;
totalSeconds = ( int ) Math . Floor ( new TimeSpan ( DateTime . Now . Ticks - ticks ) . TotalSeconds ) ;
message = $"{i + 1:000}.{container.G} [{filteredItems.Length:000} files ] / {containersLength:000} - {total} / {t} total files - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}" ;
message = $"{i + 1:000}.{container.G} [{filteredItems.Length:000} collection ] / {containersLength:000} - {total} / {t} total collection - {totalSeconds} total second(s) - {outputResolution} - {container.SourceDirectory}" ;
if ( _Configuration . LoadOrCreateThenSaveImageFacesResultsForOutputResolutions . Contains ( outputResolution ) )
_Faces . SetAngleBracketCollection ( dResultsFullGroupDirectory , container . SourceDirectory ) ;
if ( _Configuration . SaveFaceLandmarkForOutputResolutions . Contains ( outputResolution ) )
@ -876,15 +877,12 @@ public partial class DlibDotNet
if ( _Configuration . PersonCharactersToCopyTo . Length = = 1 & & _Configuration . PersonCharacters . ToArray ( ) . Contains ( _Configuration . PersonCharactersToCopyTo [ 0 ] ) )
mapLogic . CopyAtLeastOneMappedFiles ( _Configuration . PersonCharactersToCopyTo [ 0 ] , dFacesContentDirectory , a2PeopleSingletonDirectory , mappingCollection ) ;
mapLogic . CopyManualFiles ( dFacesContentDirectory , idToNormalizedRectangleToMapping ) ;
if ( _Configuration . SaveNotMappedForOutputResolutions . Contains ( outputResolution ) )
mapLogic . CopyNotMappedFaces ( _Configuration . RangeFaceAreaPermilleTolerance , dFacesContentDirectory , idToNormalizedRectangleToMapping ) ;
if ( _Configuration . SaveMappedForOutputResolutions . Contains ( outputResolution ) )
mapLogic . SaveMapped ( dFacesContentDirectory , d2FacePartsContentDirectory , mappingCollection , idToNormalizedRectangleToMapping , personKeyToCount , totalNotMapped ) ;
if ( _Configuration . SaveFilteredOriginalImagesFromJLinksForOutputResolutions . Contains ( outputResolution ) )
mapLogic . SaveFilteredOriginalImagesFromJLinks ( _Configuration . JLinks , _PersonContainers , a2PeopleSingletonDirectory , mappingCollection , personKeyToCount , totalNotMapped ) ;
if ( _Configuration . SaveFaceDistancesForOutputResolutions . Contains ( outputResolution ) )
{
mapLogic . UpdatedPersonKeyToRanges ( _MapConfiguration , ticks , mappingCollection ) ;
MapLogicSupport . SetFaceDistances ( _AppSettings . MaxDegreeOfParallelism , ticks , distinctFilteredFaces ) ;
List < Shared . Models . Face > distinctFurtherFilteredFaces = mapLogic . GetFurtherFilterBySkipCollection ( distinctFilteredFaces ) ;
Dictionary < int , Dictionary < int , PersonContainer [ ] > > missingIdThenNormalizedRectangleToPersonContainers = mapLogic . GetMissing ( idToNormalizedRectangleToMapping ) ;
@ -907,8 +905,6 @@ public partial class DlibDotNet
mapLogic . SaveContainers ( totalNotMapped , updated , saveContainers ) ;
}
}
if ( _Configuration . SaveNotMappedForOutputResolutions . Contains ( outputResolution ) )
mapLogic . SaveNotMappedTicks ( ) ;
}
private static Container ? AreAllSameEndsWith ( string argZero , Container [ ] containers )
@ -979,7 +975,7 @@ public partial class DlibDotNet
return result ;
}
private void ParallelFor ( string eDistanceContentDirectory , List < ( bool , string , int , int , IReadOnlyList < MetadataExtractor . Directory > ) > collection , string file )
private void ParallelFor ( string eDistanceContentDirectory , List < LocationContainer < MetadataExtractor . Directory > > collection , long personKey , string file )
{
const string lnk = ".lnk" ;
int? id , normalizedRectangle ;
@ -996,54 +992,79 @@ public partial class DlibDotNet
else
directories = MetadataExtractor . ImageMetadataReader . ReadMetadata ( file ) ;
lock ( collection )
collection . Add ( new ( fromDistanceContent , file , id . Value , normalizedRectangle . Value , directories ) ) ;
collection . Add ( new ( fromDistanceContent , file , personKey , id . Value , normalizedRectangle . Value , directories , null , null )) ;
}
private List < ( bool , string , int , int , IReadOnlyList < MetadataExtractor . Directory > ) > GetCollection ( long ticks , string? a2PeopleContentDirectory , string eDistanceContentDirectory )
private void Verify ( List < LocationContainer < MetadataExtractor . Directory > > collection )
{
string key ;
int normalizedRectangle ;
string personKeyFormatted ;
Dictionary < string , int > distinct = new ( ) ;
List < ( long , int , string ) > duplicates = new ( ) ;
foreach ( LocationContainer < MetadataExtractor . Directory > locationContainer in collection )
{
key = string . Concat ( locationContainer . PersonKey , locationContainer . Id ) ;
if ( distinct . TryGetValue ( key , out normalizedRectangle ) )
{
if ( normalizedRectangle = = locationContainer . NormalizedRectangle )
continue ;
duplicates . Add ( new ( locationContainer . PersonKey , locationContainer . Id , locationContainer . File ) ) ;
continue ;
}
distinct . Add ( key , locationContainer . NormalizedRectangle ) ;
}
( ) ; //Do they also intersect?
foreach ( ( long personKey , int id , string file ) in duplicates )
{
_ = Process . Start ( "explorer.exe" , string . Concat ( "\"" , Path . GetDirectoryName ( file ) , "\"" ) ) ;
personKeyFormatted = Shared . Models . Stateless . Methods . IPersonBirthday . GetFormatted ( _Configuration . PersonBirthdayFormat , personKey ) ;
}
}
private List < LocationContainer < MetadataExtractor . Directory > > GetCollection ( long ticks , string? a2PeopleContentDirectory , string eDistanceContentDirectory )
{
string file ;
List < string > files = new ( ) ;
List < ( bool , string , int , int , IReadOnlyList < MetadataExtractor . Directory > ) > results = new ( ) ;
files . AddRange ( Map . Models . Stateless . Methods . IMapLogic . GetDisplayDirectoryAllFiles ( _PersonContainers ) ) ;
files . AddRange ( Map . Models . Stateless . Methods . IMapLogic . DeleteEmptyDirectoriesAndGetMappedFaceFiles ( _MapConfiguration , _PersonContainers , ticks , a2PeopleContentDirectory , eDistanceContentDirectory ) ) ;
for ( int i = 0 ; i < files . Count ; i + + )
List < ( long PersonKey , string File ) > collection = new ( ) ;
List < LocationContainer < MetadataExtractor . Directory > > results = new ( ) ;
collection . AddRange ( Map . Models . Stateless . Methods . IMapLogic . GetDisplayDirectoryAllFiles ( _PersonContainers ) ) ;
collection . AddRange ( Map . Models . Stateless . Methods . IMapLogic . DeleteEmptyDirectoriesAndGetMappedFaceFiles ( _MapConfiguration , _PersonContainers , ticks , a2PeopleContentDirectory , eDistanceContentDirectory ) ) ;
for ( int i = 0 ; i < collection . Count ; i + + )
{
file = files [ i ] ;
file = collection [ i ] . File ;
if ( ! file . EndsWith ( ".dup" ) & & ! file . EndsWith ( ".unk" ) )
continue ;
if ( ! File . Exists ( file ) )
continue ;
File . Move ( file , file [ . . ^ 4 ] ) ;
files [ i ] = file [ . . ^ 4 ] ;
collection [ i ] = new ( collection [ i ] . PersonKey , file [ . . ^ 4 ] ) ;
}
string [ ] distictFiles = files . Disti nct ( ) . ToArray ( ) ;
if ( distictFiles . Any ( ) & & ( _Configuration . DistanceMoveUnableToMatch | | _Configuration . DistanceRenameToMatch ) )
if ( collection . Any ( ) & & ( _Configuration . Dista nceMoveUnableToMatch | | _Configuration . DistanceRenameToMatch ) )
{
int totalSeconds = ( int ) Math . Floor ( new TimeSpan ( DateTime . Now . Ticks - ticks ) . TotalSeconds ) ;
string message = $") Building Mapped Face Files Collection - {totalSeconds} total second(s)" ;
ParallelOptions parallelOptions = new ( ) { MaxDegreeOfParallelism = _AppSettings . MaxDegreeOfParallelism } ;
ProgressBarOptions options = new ( ) { ProgressCharacter = '─' , ProgressBarOnBottom = true , DisableBottomPercentage = true } ;
using ProgressBar progressBar = new ( distictFiles . Length , message , options ) ;
_ = Parallel . For ( 0 , distictFiles . Length , parallelOptions , ( i , state ) = >
using ProgressBar progressBar = new ( collection . Count , message , options ) ;
_ = Parallel . For ( 0 , collection . Count , parallelOptions , ( i , state ) = >
{
progressBar . Tick ( ) ;
ParallelFor ( eDistanceContentDirectory , results , distictFiles [ i ] ) ;
ParallelFor ( eDistanceContentDirectory , results , collection [ i ] . PersonKey , collection [ i ] . File ) ;
} ) ;
}
Verify ( results ) ;
return results ;
}
private Dictionary < int , List < LocationContainer < MetadataExtractor . Directory > > > GetDictionary ( long ticks , string? a2PeopleContentDirectory , string eDistanceContentDirectory )
{
Dictionary < int , List < LocationContainer < MetadataExtractor . Directory > > > results = new ( ) ;
LocationContainer < MetadataExtractor . Directory > noob ;
List < ( bool , string , int , int , IReadOnlyList < MetadataExtractor . Directory > ) > collection = GetCollection ( ticks , a2PeopleContentDirectory , eDistanceContentDirectory ) ;
foreach ( ( bool fromDistanceContent , string file , int id , int normalizedRectangle , IReadOnlyList < MetadataExtractor . Directory > directories ) in collection )
List < LocationContainer< MetadataExtractor . Directory > > collection = GetCollection ( ticks , a2PeopleContentDirectory , eDistanceContentDirectory ) ;
foreach ( LocationContainer < MetadataExtractor . Directory > locationContainer in collection )
{
if ( ! results . ContainsKey ( i d) )
results . Add ( i d, new ( ) ) ;
noob = new L ocationContainer< MetadataExtractor . Directory > ( fromDistanceContent , file , normalizedRectangle , directories , null , null ) ;
results [ id ] . Add ( noob ) ;
if ( ! results . ContainsKey ( locationContainer . I d) )
results . Add ( locationContainer . I d, new ( ) ) ;
results [ l ocationContainer. Id ] . Add ( locationContainer ) ;
}
return results ;
}
@ -1125,6 +1146,8 @@ public partial class DlibDotNet
distinctFilteredFaces = GetFilteredDistinctFaces ( argZero , containers ) ;
mappingCollection = MapLogicSupport . GetSelectedMappingCollection ( distinctFilteredFaces ) ;
totalNotMapped = mapLogic . UpdateMappingFromPerson ( mappingCollection ) ;
if ( a2PeopleContentDirectory is not null )
mapLogic . CreateTree ( ticks , a2PeopleContentDirectory ) ;
if ( _ArgZeroIsConfigurationRootDirectory
& & _Configuration . SaveResizedSubfiles
& & outputResolution = = _Configuration . OutputResolutions [ 0 ]