<!-- --><!-- --><style type="text/css">@import url(https://www.blogger.com/static/v1/v-css/navbar/3334278262-classic.css); div.b-mobile {display:none;} </style> </head><body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\0757256432\46blogName\75The+Frustrated+Programmer\46publishMode\75PUBLISH_MODE_BLOGSPOT\46navbarType\75BLACK\46layoutType\75CLASSIC\46searchRoot\75http://frustratedprogrammer.blogspot.com/search\46blogLocale\75en_US\46v\0752\46homepageUrl\75http://frustratedprogrammer.blogspot.com/\46vt\0755012862196962223429', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>
| Sunday, January 29, 2012

I like to keep the data around from my Swimmovate PoolMate and entering the details into TrainingPeaks is very cumbersome. So I wrote a quick script to generate TCX files that can be uploaded. Its very simple:





#!/bin/bash

function do_lap() {
LAP_TIME=`expr $LAP_MINUTES \* 60`
LAP_TIME=`expr $LAP_TIME + $LAP_SECONDS`
echo " <Lap StartTime=\"$LAP_START\">" >> $START_DATE.tcx
echo " <TotalTimeSeconds>$LAP_TIME</TotalTimeSeconds>" >> $START_DATE.tcx
echo " <DistanceMeters>$LAP_DISTANCE</DistanceMeters>" >> $START_DATE.tcx
echo " <Intensity>$1</Intensity>" >> $START_DATE.tcx
echo " <TriggerMethod>Manual</TriggerMethod>" >> $START_DATE.tcx
echo " </Lap>" >> $START_DATE.tcx
MINUTE_OFFSET=`expr $MINUTE_OFFSET + $LAP_MINUTES`
SECOND_OFFSET=`expr $SECOND_OFFSET + $LAP_SECONDS`
}

START_DATE=`date +%Y-%m-%dT%H:%M:%S.000Z`
cat header.tcx > $START_DATE.tcx
echo " <Id>"$START_DATE"</Id>" >> $START_DATE.tcx
echo -n "Yards or Meters (y/m): "
read YARDS
echo -n "Number of sets: "
read SETS
CURRENT_SET=0
MINUTE_OFFSET=0
SECOND_OFFSET=0
while [ $CURRENT_SET -ne $SETS ]; do
echo -n "Set $CURRENT_SET Distance: "
read LAP_DISTANCE
if [ "$YARDS" = "y" ]; then
LAP_DISTANCE=`echo $LAP_DISTANCE \* 0.9144 | bc`
fi
echo -n "Set $CURRENT_SET Time (Min Sec): "
read LAP_MINUTES LAP_SECONDS
LAP_START=`date -v +${MINUTE_OFFSET}M -v +${SECOND_OFFSET}S +%Y-%m-%dT%H:%M:%S.000Z`
do_lap "Active"

#Default to 60 second reset between sets
LAP_MINUTES=0
LAP_SECONDS=60
LAP_DISTANCE=0
do_lap "Resting"

CURRENT_SET=`expr $CURRENT_SET + 1`
done
cat trailer.tcx >> $START_DATE.tcx



Here is header.tcx

<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase
xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd"
xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1"
xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2"
xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2"
xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1">
<Activities>
<Activity Sport="Other">


And trailer.tcx

</Activity>
</Activities>
</TrainingCenterDatabase>