Code:
?#
# Notes: Requires Java
#
# Copy entire folder from google drive
# https://drive.google.com/drive/folders/1fb_MCyteiMZrcL-gj7DJXlCn-Y_LsGkO?usp=drive_link
# Connect Garmin Xero C1 Pro to Computer
# Run the script (right click + run with powershell)
# Navigate to the .FIT files on the device in the pop up and select them, press "Open" button
# Name the sessions when prompted in terminal window. Spaces are OK, dont include .txt
#
#
#
# Created by ZenEffect
cls
Add-Type -AssemblyName System.Windows.Forms
#ripped this part off of a google search. It creates function for the pop up window to select files
function Select-File {
[CmdletBinding()]
param(
[Parameter(ParameterSetName="Single")]
[Parameter(ParameterSetName="Multi")]
[Parameter(ParameterSetName="Save")]
[string]$StartingFolder = [environment]::getfolderpath("mydocuments"),
[Parameter(ParameterSetName="Single")]
[Parameter(ParameterSetName="Multi")]
[Parameter(ParameterSetName="Save")]
[string]$NameFilter = "All Files (*.*)|*.*",
[Parameter(ParameterSetName="Single")]
[Parameter(ParameterSetName="Multi")]
[Parameter(ParameterSetName="Save")]
[switch]$AllowAnyExtension,
[Parameter(Mandatory=$true,ParameterSetName="Save")]
[switch]$Save,
[Parameter(Mandatory=$true,ParameterSetName="Multi")]
[Alias("Multi")]
[switch]$AllowMulti
)
if ($Save) {
$Dialog = New-Object -TypeName System.Windows.Forms.SaveFileDialog
} else {
$Dialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
if ($AllowMulti) {
$Dialog.Multiselect = $true
}
}
if ($AllowAnyExtension) {
$NameFilter = $NameFilter + "|All Files (*.*)|*.*"
}
$Dialog.Filter = $NameFilter
$Dialog.InitialDirectory = $StartingFolder
[void]($Dialog.ShowDialog())
$Dialog.FileNames
}
# .FIT file to .CSV - Copies to a "fit_temp" folder first for processing. Does not interact with device except to copy the files to computer first.
$fit = (Select-File -StartingFolder "C:\" -NameFilter "Garmin FIT Files (*.fit)|*.fit" -AllowMulti)
copy $fit .\fit_Temp
$fit_temp = get-childitem -Path .\fit_temp | select-object fullname
foreach ($fitfile in $fit_temp)
{
$fit3 = $fitfile.fullname
$fit2 = "`"$fit3`""
# sends the selected files to the bat file that came with the Garmin SDK. Only modification to the .BAT was to remove the "Pause" at the end. FIT files
# are processed into CSV by some Garmin SDK Java magic.
start-process -filepath '.\java\fittocsv.bat' -argumentlist $fit2 -wait
}
# gets list of newly created .csv from fit_temp directory for processing
$items = get-childitem -Path .\fit_temp\*.csv | select fullname
foreach ($item in $items)
{
# Gets shot data and calculates standard deviation
$csv1 = $item.fullname | import-csv
$csv_data = $csv1 | where 'type' -eq 'data' | where 'local number' -eq 4
$measured = $csv_data.'value 2' | measure-object -average
$newNumbers = 0
ForEach ($number in $csv_data) {
$newNumbers += [Math]::Pow(($number.'value 2' - $measured.Average), 2)
}
$stdDev = [math]::Sqrt($($newNumbers / ($measured.Count - 1)))
$stdDevp = [math]::Sqrt($($newNumbers / ($measured.Count)))
$stddev_fps=$stddev / 304.79999025
$stddevp_fps=$stddevp / 304.79999025
# Begin CSV to TXT file processing
foreach ($csv in $csv1)
{
$type = $csv.type
$localnumber = $csv."local number"
if ($type -eq "Data" -and $localnumber -eq "3")
{
$min = ($csv."Value 2" / 304.79999025)
$max = ($csv."Value 3" / 304.79999025)
$average = ($csv."Value 4" / 304.79999025)
$shots = $csv."Value 6"
$time_hack=([int]$csv."Value 1" + [int]631065600)
$time = (([System.DateTimeOffset]::FromUnixTimeSeconds($time_hack)).DateTime.ToLocalTime()).ToString("s")
$extreme_spread= ($max - $min)
Write-host "Session Time/Date:" $time
Write-host "# of Shots:", $shots
Write-host " "
Write-host "Min:", $min
Write-host "Max:", $max
Write-host "Average:", $average
Write-host " "
write-host "Standard Deviation:", $stddev_fps
write-host "Population Standard Deviation:", $stddevp_fps
Write-host "Extreme Spread:", $extreme_spread
write-host " "
write-host " "
$Session_name = Read-Host -Prompt "Enter Session Name"
Write-output "Session Time/Date: $time" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Session Name: $session_name" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "# of Shots: $shots" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output " " | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Min: $min" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Max: $max" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Average: $average" | out-file -filepath .\Results\$Session_name.txt -Append
Write-Output "Standard Deviation: $stddev_fps" | out-file -filepath .\Results\$Session_name.txt -Append
Write-Output "Population Standard Deviation: $stddevp_fps" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Extreme Spread: $extreme_spread" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output " " | out-file -filepath .\Results\$Session_name.txt -Append
Write-Output "Session_Time,Session_Name,Count,Min,Max,Average,SD,PSD,ES,Shot_Num,Shot_Time,Velocity" | out-file -filepath .\Results\$Session_name.csx -Append
Write-Output "$time , $session_name , $shots , $min , $max , $average , $stddev_fps , $stddevp_fps , $extreme_spread" | out-file -filepath .\Results\$Session_name.csx -Append
$newNumbers = 0
cls
}
if ($type -eq "Data" -and $localnumber -eq "4")
{
$shot_num = $csv.'Value 3'
$speed = ($csv.'Value 2' / 304.79999025)
$time_hack1=([int]$csv."value 1" + [int]631065600)
$time1 = (([System.DateTimeOffset]::FromUnixTimeSeconds($time_hack1)).DateTime.ToLocalTime()).ToString("s")
Write-output " " | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Shot #: $shot_num" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Speed: $speed" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output "Time of Shot: $time1" | out-file -filepath .\Results\$Session_name.txt -Append
Write-output " " | out-file -filepath .\Results\$Session_name.txt -Append
Write-Output ",,,,,,,,,$shot_num,$time1,$speed" | out-file -filepath .\Results\$Session_name.csx -Append
}
}
$csvprocessing = import-csv .\results\$session_name.csx
$csvprocessing | export-csv .\results\$session_name.csv -NoTypeInformation
remove-item .\results\$session_name.csx
}
# cleanup actions
move-item -path .\fit_temp\*.csv -destination .\results\
move-item .\fit_temp\*.fit -destination .\fit_backupcleaned up CSV output is added, with actual CSV headers! It will be the same as your session name. what a cheap ass hack i thought of before goign to sleep. google drive repository is updated, updating github now.
I need to add a couple of safety features incase of bad or empty input but this is pretty much complete now.

