Skip to content

Instantly share code, notes, and snippets.

@irwins
Last active March 9, 2016 08:41
Show Gist options
  • Save irwins/e5a579325e28d0070a7b to your computer and use it in GitHub Desktop.
Save irwins/e5a579325e28d0070a7b to your computer and use it in GitHub Desktop.
[CmdletBinding()]
Param (
[ValidateScript({ Test-Path $_ } )]
[string]$ChessMatchesPath = 'C:\Users\Irwin\Downloads\ChessData-master\ChessData-master',
[switch]$DisplaySumTotal
)
#region Define regex results. Make search case-insensitive just incase.
[regex]$whiteWin = '(?i)result\s+"1-0"'
[regex]$blackWin = '(?i)Result\s+"0-1"'
[regex]$Tie = '(?i)result\s+"1/2.*'
#endregion
#region Main Process All pgn files
Get-ChildItem -Path $ChessMatchesPath -File *.pgn -Recurse |
ForEach-Object {
$pgnFile = Get-Content $_.FullName -Raw
[PSCustomObject]@{
FileReference = $_.Name
WhiteWin = @($whiteWin.Matches($pgnFile)).Count
BlackWin = @($blackWin.Matches($pgnFile)).Count
Tie = @($Tie.Matches($pgnFile)).Count
}
} -OutVariable ChessResults
If($DisplaySumTotal){
"`n`r"
'Total wins White: {0}' -f ($ChessResults.WhiteWin | Measure-Object -Sum).Sum
'Total wins Black: {0}' -f ($ChessResults.BlackWin | Measure-Object -Sum).Sum
'Total ties: {0}' -f ($ChessResults.Tie | Measure-Object -Sum).Sum
}
#endregion
@irwins
Copy link
Author

irwins commented Mar 4, 2016

C:\scripts> Measure-Command { .\ps1\misc\Get-ChessMatchesResults.ps1 }

Days : 0
Hours : 0
Minutes : 3
Seconds : 53
Milliseconds : 31
Ticks : 2330310183
TotalDays : 0.00269711826736111
TotalHours : 0.0647308384166667
TotalMinutes : 3.883850305
TotalSeconds : 233.0310183
TotalMilliseconds : 233031.0183

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment