Posted by skovholm on October 11, 2009 at 8:09pm
| Project: | Trackfield |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | skovholm |
| Status: | active |
Issue Summary
Hi
Can anyone help me to modified the trackfield_tcx module so it can handle the new tcx scheme v2.
There you have lap - track - trackpoint
The code in trackfield_tcx stop when the first "lap" is taken and do only response what is in the first lap ...
http://developer.garmin.com/schemas/tcx/v2/xmlspy/index.html - here you can see the V2 scheme
function _trackfield_tcx_setcsv(&$item) {
$new_value = FALSE;
$doc = new DomDocument;
if ($doc->loadXML($item['value'])) {
$tmp = $doc->getElementsByTagName('TrainingCenterDatabase');
//if ($tmp->length) {
// $tmp = $doc->getElementsByTagName('Activities');
//}
//if ($tmp->length) {
// $tmp = $doc->getElementsByTagName('Activity');
//}
if ($tmp->length) {
$pointname = 'Trackpoint';
$point_list = $tmp->item(0)->getElementsByTagName($pointname);
$point = $point_list->item(0);
$lp = 0;
while ($point) {
$lat = trim($point->getElementsByTagName('LatitudeDegrees')->item(0)->nodeValue);
$lon = trim($point->getElementsByTagName('LongitudeDegrees')->item(0)->nodeValue);
/* Only add point if lat/lon given */
if (is_numeric($lat) && is_numeric($lon)) {
$alt = trim($point->getElementsByTagName('AltitudeMeters')->item(0)->nodeValue);
// $tmp = trim($point->getElementsByTagName('HeartRateBpm'));
if ($tmp->length) {
$val = trim($tmp->item(0)->getElementsByTagName('Value')->item(0)->nodeValue);
/* 255 == invalid value - just use the last good one for now. */
if ($val != 255) {
$hrt = $val;
}
}
/* Convert time into number of seconds since start */
$tim = trim($point->getElementsByTagName('Time')->item(0)->nodeValue);
if ($tim) {
$tim = strtotime($tim);
if (!isset($csv)) { $tim_base = $tim; }
$tim = $tim - $tim_base;
}
if (isset($csv)) { $csv .= ' '; }
$csv .= "$lon,$lat,$alt,$tim,$hrt";
}
/* Move to next point of interest in the list */
do {
$point = $point->nextSibling;
} while ($point && $point->nodeName != $pointname);
}
$new_value = $csv;
$item['valuetype'] = DATASET_LONLATALT;
}
}
// watchdog('trackfield_tcx', sprintf('Done, data is now %d bytes', strlen($new_value)));
// print $new_value; exit;
$item['value'] = &$new_value;
}Thanks for a GREAT module - and please help improving ;o)
Hjalmar
Comments
#1
Hi
You can see a tcx file here attached ... ( renamed txt because could not upload tcx file )
This file Trackfield_tcx do not handle right because of the "laps"
Hjalmar
#2
Hi
Fixed by myself so please close this issue ..
function _trackfield_tcx_setcsv(&$item) {
$new_value = FALSE;
$doc = new DomDocument;
if ($doc->loadXML($item['value'])) {
$point_list = $doc->getElementsByTagName('Trackpoint');
foreach ($point_list as $point)
{
$lat = trim($point->getElementsByTagName('LatitudeDegrees')->item(0)->nodeValue);
$lon = trim($point->getElementsByTagName('LongitudeDegrees')->item(0)->nodeValue);
/* Only add point if lat/lon given */
if (is_numeric($lat) && is_numeric($lon)) {
$alt = trim($point->getElementsByTagName('AltitudeMeters')->item(0)->nodeValue);
$tim = trim($point->getElementsByTagName('Time')->item(0)->nodeValue);
if ($tim) {
$tim = strtotime($tim);
if (!isset($csv)) { $tim_base = $tim; }
$tim = $tim - $tim_base;
}
$hrt = trim($point->getElementsByTagName('HeartRateBpm')->item(0)->nodeValue);
if (isset($csv)) { $csv .= ' '; }
$csv .= "$lon,$lat,$alt,$tim,$hrt";
}
}
$new_value = $csv;
$item['valuetype'] = DATASET_LONLATALT;
}
$item['value'] = &$new_value;
}
#3
Thanks for the snippet.
But sadly I don't think this is a good solution as doubt it will handle both old and new TCX formats seamlessly.
We need to have some code that works for them both, then I'll commit it.