From: <jb...@us...> - 2009-09-25 02:17:53
|
Revision: 359 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=359&view=rev Author: jblance Date: 2009-09-25 02:17:43 +0000 (Fri, 25 Sep 2009) Log Message: ----------- Add plugin for testing import from TCXv1 Modified Paths: -------------- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml pytrainer/branches/plugins-v2/plugins/garmingpx/main.py Added Paths: ----------- pytrainer/branches/plugins-v2/plugins/garmin-hr/ pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-hr/gtrnctr2gpx.py pytrainer/branches/plugins-v2/plugins/garmin-hr/main.py pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style pytrainer/branches/plugins-v2/plugins/garmin-hr-file/ Removed Paths: ------------- pytrainer/branches/plugins-v2/plugins/garmin-hr/ Copied: pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml (from rev 358, pytrainer/trunk/plugins/garmin-hr/conf.xml) =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml (rev 0) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml 2009-09-25 02:17:43 UTC (rev 359) @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<pytrainer-plugin + name="Garmin Heart Rate" + description="Import yor records direclty from your garmin gps device with heart rate support" + plugincode="garmin-hr" + pluginbutton="Import from Garmin (HR support)" + executable="main.py" +> +<conf-values variable="device" value="usb:"/> +</pytrainer-plugin> Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml ___________________________________________________________________ Added: svn:mergeinfo + Copied: pytrainer/branches/plugins-v2/plugins/garmin-hr/gtrnctr2gpx.py (from rev 358, pytrainer/trunk/plugins/garmin-hr/gtrnctr2gpx.py) =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/gtrnctr2gpx.py (rev 0) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/gtrnctr2gpx.py 2009-09-25 02:17:43 UTC (rev 359) @@ -0,0 +1,82 @@ +#!/usr/bin/python +# -*- coding: iso-8859-1 -*- + +#Copyright (C) Fiz Vazquez vu...@si... + +#This program is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation; either version 2 +#of the License, or (at your option) any later version. + +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with this program; if not, write to the Free Software +#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +import sys + +import xml.dom.minidom + +#the _variables are the gpx ones. The variables are the xcsv one + + +def gtrnctr2gpx(gtrnctrfile,gpxfile): + dom = xml.dom.minidom.parse(gtrnctrfile) + d = xml.dom.minidom.getDOMImplementation() + _dom = d.createDocument(None,"gpx",None) + _gpx_element = _dom.documentElement + _gpx_element.setAttribute('creator',"pytrainer http://pytrainer.e-oss.net") + _gpx_element.setAttribute('version',"1.1") + _gpx_element.setAttribute('xmlns',"http://www.topografix.com/GPX/1/1") + _gpx_element.setAttribute('xmlns:geocache',"http://www.groundspeak.com/cache/1/0") + _gpx_element.setAttribute('xmlns:gpxdata',"http://www.cluetrust.com/XML/GPXDATA/1/0") + _gpx_element.setAttribute('xmlns:xsi',"http://www.w3.org/2001/XMLSchema-instance") + _gpx_element.setAttribute('xsi:schemaLocation',"http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.cluetrust.com/XML/GPXDATA/1/0 http://www.cluetrust.com/Schemas/gpxdata10.xsd") + + trks = dom.getElementsByTagName("Track") + nametrack = 0 + for trk in trks: + nametrack = nametrack+1 + _trk = _dom.createElement("trk") + _name = _dom.createElement("name") + _name.appendChild(_dom.createTextNode("%s"%str(nametrack))) + _trk.appendChild(_name) + trkpoints = trk.getElementsByTagName("Trackpoint") + for trkpoint in trkpoints: + _trkpt = _dom.createElement("trkpt") + time = trkpoint.getElementsByTagName("Time")[0].firstChild.data + alt = trkpoint.getElementsByTagName("AltitudeMeters")[0].firstChild.data + if len(trkpoint.getElementsByTagName("HeartRateBpm"))>0: + hr = trkpoint.getElementsByTagName("HeartRateBpm")[0].firstChild.data + else: + hr = "0" + lat = trkpoint.getElementsByTagName("LatitudeDegrees")[0].firstChild.data + lon = trkpoint.getElementsByTagName("LongitudeDegrees")[0].firstChild.data + + _time = _dom.createElement("time") + _ele = _dom.createElement("ele") + _hr = _dom.createElement("gpxdata:hr") + _extensions = _dom.createElement("extensions") + _time.appendChild(_dom.createTextNode(time)) + _ele.appendChild(_dom.createTextNode(alt)) + _hr.appendChild(_dom.createTextNode(hr)) + _extensions.appendChild(_hr) + _trkpt.appendChild(_time) + _trkpt.appendChild(_ele) + _trkpt.appendChild(_extensions) + _trkpt.setAttribute('lat', lat) + _trkpt.setAttribute('lon', lon) + _trk.appendChild(_trkpt) + _gpx_element.appendChild(_trk) + + f = open(gpxfile, 'w') + #_dom.writexml(f) + #f.write(_dom.toprettyxml()) + f.write(_dom.toxml()) + f.close() + Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/gtrnctr2gpx.py ___________________________________________________________________ Added: svn:mergeinfo + Copied: pytrainer/branches/plugins-v2/plugins/garmin-hr/main.py (from rev 358, pytrainer/trunk/plugins/garmin-hr/main.py) =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/main.py (rev 0) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/main.py 2009-09-25 02:17:43 UTC (rev 359) @@ -0,0 +1,63 @@ +#!/usr/bin/python +# -*- coding: iso-8859-1 -*- + +#Copyright (C) Fiz Vazquez vu...@si... + +#This program is free software; you can redistribute it and/or +#modify it under the terms of the GNU General Public License +#as published by the Free Software Foundation; either version 2 +#of the License, or (at your option) any later version. + +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. + +#You should have received a copy of the GNU General Public License +#along with this program; if not, write to the Free Software +#Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +from optparse import OptionParser +#from gtrnctr2gpx import gtrnctr2gpx +import os +import commands + +parser = OptionParser() +parser.add_option("-d", "--device", dest="device") +(options,args) = parser.parse_args() +gtrnctrFile="/tmp/file.gtrnctr" +gtrnctrFileMod="/tmp/file_mod.gtrnctr" +input_dev = options.device + +# ToDo (19.05.2008): better exception handling +try: + outmod = commands.getstatusoutput('/sbin/lsmod | grep garmin_gps') + #os.popen("zenity --error --text='Devuelve: %s'" %str(outmod)) + if outmod[0]==256: #there is no garmin_gps module loaded + input_dev = "usb:" + else: + raise Exception + # Can't export to GPX directly because lack of support for heartrate and sports (1.0 version, may change when gpsbabel supports 1.1 with custom fields) + outgps = commands.getstatusoutput("gpsbabel -t -i garmin -f %s -o gtrnctr -F /tmp/file.gtrnctr | zenity --progress --pulsate --text='Loading Data' auto-close" %input_dev) + #os.popen("zenity --error --text='Devuelve: %s'" %str(outgps)) + # XML file from gpsbabel refers to schemas and namespace definitions which are no longer available, removing this info - dgg - 12.05.2008 + if outgps[0]==0: + if outgps[1] == "Found no Garmin USB devices.": # check localizations + raise Exception + else: + if os.path.isfile(gtrnctrFile): + f = open(gtrnctrFile,"r") + lines = f.readlines() + f.close() + f = open(gtrnctrFileMod,'w') + headers = lines[0]+'<TrainingCenterDatabase>\n' + f.write(headers) + f.write(''.join(lines[6:])) + f.close() + print gtrnctrFileMod + else: + raise Exception +except Exception: + os.popen("zenity --error --text='Can not handle Garmin device\nCheck your configuration\nCurrent usb port is set to:\t %s'" %input_dev); + Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/main.py ___________________________________________________________________ Added: svn:executable + * Added: svn:mergeinfo + Copied: pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style (from rev 358, pytrainer/trunk/plugins/garmin-hr/pytrainer.style) =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style (rev 0) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style 2009-09-25 02:17:43 UTC (rev 359) @@ -0,0 +1,39 @@ +# gpsbabel XCSV style file +# +# Format: GPSDrive +# Author: Alex Mottram +# Date: 12/11/2002 +# +# +# + +DESCRIPTION GpsDrive Format +DATATIPE TRACK + +# FILE LAYOUT DEFINITIIONS: +# +FIELD_DELIMITER WHITESPACE +RECORD_DELIMITER CRNEWLINE +BADCHARS WHITESPACE +PROLOGUE OziExplorer Waypoint File Version 1.1 + +SHORTLEN 20 +SHORTWHITE 0 + +# +# INDIVIDUAL DATA FIELDS, IN ORDER OF APPEARANCE: + +IFIELD SHORTNAME, "", "%s" +IFIELD LAT_DECIMAL, "", "%08.5f" +IFIELD LON_DECIMAL, "", "%08.5f" +IFIELD ALT_METERS, "", "%.0f" +IFIELD GMT_TIME,"","%m/%d/%Y %I:%M:%D %p" +IFIELD ICON_DESCR, "", "%s" +IFIELD TRACK_NAME, "", "%s" + +#OFIELD TRACK_NAME, "", "%s" +OFIELD LAT_DECIMAL, "", "%08.5f" +OFIELD LON_DECIMAL, "", "%08.5f" +OFIELD ALT_METERS, "", "%.0f" +OFIELD GMT_TIME,"","%s" +OFIELD HEART_RATE,"","%d" Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style ___________________________________________________________________ Added: svn:mergeinfo + Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr-file ___________________________________________________________________ Added: svn:mergeinfo + /pytrainer/trunk/plugins/garmin-hr:345-347 Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml 2009-09-23 12:18:36 UTC (rev 358) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml 2009-09-25 02:17:43 UTC (rev 359) @@ -1,7 +1,7 @@ <?xml version="1.0" ?> <pytrainer-plugin - name="Garmin Heart Rate" - description="Import records from a garmin gps device with heart rate support (from a file)" + name="Garmin Import with HR (from TCXv1file)" + description="Import records from a garmin gps device with heart rate support (from TCXv1 file)" plugincode="garminhrfile" pluginbutton="Import from Garmin file (HR support)" executable="garminhrfile" Modified: pytrainer/branches/plugins-v2/plugins/garmingpx/main.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmingpx/main.py 2009-09-23 12:18:36 UTC (rev 358) +++ pytrainer/branches/plugins-v2/plugins/garmingpx/main.py 2009-09-25 02:17:43 UTC (rev 359) @@ -17,6 +17,7 @@ #Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import os +import lib.fileSelector class garmingpx(): def __init__(self, parent = None): @@ -25,6 +26,8 @@ def run(self): # Kind of lame to shell out for this.... + f = FileSelectionDialog( ) + return f = os.popen("zenity --file-selection --multiple --title 'Choose a GPX file to import'") inputData = f.read().strip() inputfiles = inputData.split('|') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |