1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
Function ParseData
{
param
(
[string][Parameter(Mandatory=$True)] [string]$path
)
$results = @()
$refresh = [system.diagnostics.stopwatch]::StartNew()
$clock = [system.diagnostics.stopwatch]::StartNew()
$data = Import-Csv -Path $path -Encoding 'UTF8' -Delimiter ';'
$data_raw = $data.NOM | Sort
$data_uni = $data_raw | Sort -Unique
$index_max = $data_uni.Count ; Write-Host "Nombre d'entrées : $index_max"
$t = Measure-Command {
$current_index = 0;
foreach ( $item_1 in $data_uni )
{
$occurrences = 0
$results_item = @()
$t_loop = Measure-Command {
foreach ( $item_2 in $data_raw )
{
if ( $item_2 -match $item_1 )
{
$occurrences++
$results_item += $item_2
}
}
}
$t_end = New-TimeSpan -Seconds $($index_max*$t_loop.TotalSeconds-$Clock.Elapsed.TotalSeconds)
if ( $($refresh.Elapsed.TotalSeconds) -gt 10)
{
$refresh.Reset() ; $refresh.Start()
$progress = [Math]::Round(100*($current_index)/$index_max,1) ;
Write-Host " + Progress : $progress `% - $current_index/$index_max"
Write-Host " | Temps sous boucle : $($t_loop.TotalSeconds) sec"
Write-Host " | Temps restant estimé : $([Int32]$t_end.TotalMinutes) min"
Write-Host " +----------------------------------------+"
$refresh++
}
if ( $occurrences -eq 17 ) { $results += @{ Commune = $item_1 ; Occurence = $occurrences ; Liste = $results_item } }
$current_index++
}
$results = $results | % { new-object PSObject -Property $_ } | Select Commune, Occurence, Liste | sort -Descending -Property Occurence
}
$clock.Stop()
$refresh.Stop()
Write-Host "+ Temps d''execution : $($t.TotalMinutes) minutes"
return $results
} |
Partager