Skip to content

Instantly share code, notes, and snippets.

@juzam
Created January 3, 2020 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juzam/e078b7b46620cc3bea5007df5222c8a5 to your computer and use it in GitHub Desktop.
Save juzam/e078b7b46620cc3bea5007df5222c8a5 to your computer and use it in GitHub Desktop.
Parse Training Peaks Metrics zipped export file and converts it to Golden Cheetah metrics import CSV format
#!/bin/bash
UNZIP=$( which unzip )
INPUT_FILE=$1
if [ -$INPUT_FILE- == -- ]; then
echo "usage: $0 trainingpeaksexportfile.zip"
exit 1
fi
CURRENT_DATE=""
DATE=""
OUTPUT=0
WEIGHTKG=0
PERCENTFAT=.00
echo "date,weightkg,fatkg,boneskg,musclekg,leankg,fatpercent,comment"
while read LINE; do
DATE=$( echo $LINE | cut -d, -f1 | sed 's/"//g' )
if [ "-$DATE-" != "-$CURRENT_DATE-" ]; then
if [ "$WEIGHTKG" != "0" ]; then
if [ $OUTPUT -eq 0 ]; then
echo "$( echo $CURRENT_DATE | sed 's/ /T/' )Z,$WEIGHTKG,0,0,0,0,$PERCENTFAT,tp2gc"
OUTPUT=1
else
OUTPUT=0
fi
fi
CURRENT_DATE=$DATE
fi
FIELD=$( echo $LINE | cut -d, -f2 )
VALUE=$( echo $LINE | cut -d, -f3 | sed 's/"//g' )
if [ "$FIELD" == '"Weight Kilograms"' ]; then
WEIGHTKG=$VALUE
fi
if [ "$FIELD" == '"Percent Fat"' ]; then
if [ "$VALUE" = ".00" ]; then
PERCENTFAT=0
else
PERCENTFAT=$VALUE
fi
fi
done < <( unzip -c $INPUT_FILE metrics.csv | sed 's/\r$//g' | tail -n +4 | head -n -1)
if [ "$WEIGHTKG" != "0" ]; then
echo "$( echo $DATE | sed 's/ /T/' )Z,$WEIGHTKG,0,0,0,0,$PERCENTFAT,tp2gc"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment