You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
|
Feb
(1) |
Mar
(15) |
Apr
(20) |
May
(2) |
Jun
(9) |
Jul
(3) |
Aug
(2) |
Sep
(17) |
Oct
(16) |
Nov
(38) |
Dec
(40) |
2010 |
Jan
(51) |
Feb
(11) |
Mar
(24) |
Apr
(31) |
May
(24) |
Jun
(3) |
Jul
(9) |
Aug
(1) |
Sep
(29) |
Oct
(33) |
Nov
(81) |
Dec
(6) |
2011 |
Jan
(2) |
Feb
(4) |
Mar
(13) |
Apr
(4) |
May
(24) |
Jun
(4) |
Jul
(19) |
Aug
(46) |
Sep
(10) |
Oct
(28) |
Nov
(31) |
Dec
|
From: <jb...@us...> - 2009-11-20 06:44:09
|
Revision: 393 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=393&view=rev Author: jblance Date: 2009-11-20 06:44:01 +0000 (Fri, 20 Nov 2009) Log Message: ----------- Fix for weekview, start of week and localised days Modified Paths: -------------- pytrainer/trunk/pytrainer/gui/windowmain.py pytrainer/trunk/pytrainer/lib/date.py pytrainer/trunk/pytrainer/main.py pytrainer/trunk/pytrainer/weekgraph.py Modified: pytrainer/trunk/pytrainer/gui/windowmain.py =================================================================== --- pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-19 21:10:35 UTC (rev 392) +++ pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-20 06:44:01 UTC (rev 393) @@ -339,7 +339,7 @@ def actualize_weekview(self, record_list, date_ini, date_end): logging.debug(">>") - self.drawareaweek.drawgraph(record_list) + self.drawareaweek.drawgraph(record_list, date_ini, date_end) logging.debug("<<") def actualize_monthview(self,record_list, nameMonth): Modified: pytrainer/trunk/pytrainer/lib/date.py =================================================================== --- pytrainer/trunk/pytrainer/lib/date.py 2009-11-19 21:10:35 UTC (rev 392) +++ pytrainer/trunk/pytrainer/lib/date.py 2009-11-20 06:44:01 UTC (rev 393) @@ -20,6 +20,7 @@ import time import datetime +import calendar class Date: def __init__(self, calendar=None): @@ -50,11 +51,19 @@ def time2string(self,date): return "%0.4d-%0.2d-%0.2d" %(int(date[0]),int(date[1]),int(date[2])) - def getWeekInterval(self,date): - weekDate = datetime.datetime.strptime(date, "%Y-%m-%d") - dayOfWeek = int(weekDate.strftime("%w")) - date_ini = weekDate + datetime.timedelta(days=0-dayOfWeek) - date_end = weekDate + datetime.timedelta(days=6-dayOfWeek) + def getWeekInterval(self,date, prf_us_system): + if prf_us_system == "True": + #Sunday is first day of week + weekDate = datetime.datetime.strptime(date, "%Y-%m-%d") + dayOfWeek = int(weekDate.strftime("%w")) + date_ini = weekDate + datetime.timedelta(days=0-dayOfWeek) + date_end = weekDate + datetime.timedelta(days=6-dayOfWeek) + else: + #Monday is first day of week + weekDate = datetime.datetime.strptime(date, "%Y-%m-%d") + dayOfWeek = int(weekDate.strftime("%w")) + date_ini = weekDate + datetime.timedelta(days=1-dayOfWeek) + date_end = weekDate + datetime.timedelta(days=7-dayOfWeek) return date_ini.strftime("%Y-%m-%d"), date_end.strftime("%Y-%m-%d") def getMonthInterval(self,date): Modified: pytrainer/trunk/pytrainer/main.py =================================================================== --- pytrainer/trunk/pytrainer/main.py 2009-11-19 21:10:35 UTC (rev 392) +++ pytrainer/trunk/pytrainer/main.py 2009-11-20 06:44:01 UTC (rev 393) @@ -93,7 +93,7 @@ def __init__(self,filename = None, data_path = None): logging.debug('>>') self.data_path = data_path - self.version ="1.6.0.9" # 22.10.2009 + self.version ="1.6.0.9 svn" # 22.10.2009 self.date = Date() main_dir = os.path.realpath(os.path.dirname(__file__)) #why? sys.path.insert(0, main_dir) #why? @@ -111,6 +111,7 @@ self.filename = self.conf.getValue("conffile") logging.debug('retrieving data from '+ self.filename) self.configuration = XMLParser(self.filename) + self.prf_us_system = self.configuration.getValue("pytraining","prf_us_system") self.ddbb = DDBB(self.configuration) logging.debug('connecting to DDBB') self.ddbb.connect() @@ -222,7 +223,7 @@ selected,iter = self.windowmain.recordTreeView.get_selection().get_selected() elif view=="week": logging.debug('week view') - date_ini, date_end = self.date.getWeekInterval(date_selected) + date_ini, date_end = self.date.getWeekInterval(date_selected, self.prf_us_system) record_list = self.record.getrecordPeriod(date_ini, date_end) self.windowmain.actualize_weekview(record_list, date_ini, date_end) elif view=="month": Modified: pytrainer/trunk/pytrainer/weekgraph.py =================================================================== --- pytrainer/trunk/pytrainer/weekgraph.py 2009-11-19 21:10:35 UTC (rev 392) +++ pytrainer/trunk/pytrainer/weekgraph.py 2009-11-20 06:44:01 UTC (rev 393) @@ -24,11 +24,17 @@ def __init__(self, vbox = None, window = None): self.drawarea = DrawArea(vbox, window) - def drawgraph(self,values): + def drawgraph(self,values, date_ini, date_end): logging.debug(">>") #print "Found %d records" % len(values) logging.debug(str(values)) - days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + #build days list to ensure localised values are used. + days = [] + for day in range(0, 7): + dateTemp = datetime.datetime.strptime(date_ini, "%Y-%m-%d") + incrementDay = datetime.timedelta(days=day) + dateToUse = dateTemp + incrementDay + days.append( dateToUse.strftime("%a") ) valueDict = {} for record in values: day = datetime.datetime.strptime(record[1], "%Y-%m-%d").strftime("%a") # Gives Sun, Mon etc for this record This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dg...@us...> - 2009-11-19 21:10:42
|
Revision: 392 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=392&view=rev Author: dgranda Date: 2009-11-19 21:10:35 +0000 (Thu, 19 Nov 2009) Log Message: ----------- Moving logic to dictionaries. Adding logic for checkTable. Warning to mysql users Modified Paths: -------------- pytrainer/trunk/pytrainer/lib/ddbb.py pytrainer/trunk/pytrainer/lib/sqliteUtils.py Modified: pytrainer/trunk/pytrainer/lib/ddbb.py =================================================================== --- pytrainer/trunk/pytrainer/lib/ddbb.py 2009-11-19 06:04:01 UTC (rev 391) +++ pytrainer/trunk/pytrainer/lib/ddbb.py 2009-11-19 21:10:35 UTC (rev 392) @@ -24,10 +24,10 @@ class DDBB: def __init__(self, configuration): - ddbb_type = configuration.getValue("pytraining","prf_ddbb") - if ddbb_type == "mysql": + self.ddbb_type = configuration.getValue("pytraining","prf_ddbb") + if self.ddbb_type == "mysql": from mysqlUtils import Sql - if ddbb_type == "sqlite": + else: from sqliteUtils import Sql ddbb_host = configuration.getValue("pytraining","prf_ddbbhost") @@ -39,7 +39,7 @@ def connect(self): #si devolvemos 1 ha ido todo con exito #con 0 es que no estaba la bbdd creada - #con 1 imposible conectar a la maquina. + #con -1 imposible conectar a la maquina. var = self.ddbbObject.connect() if var == 0: self.ddbbObject.createDDBB() @@ -206,6 +206,9 @@ args: none returns: none""" logging.debug('>>') + if self.ddbb_type != "sqlite": + logging.error('Support for MySQL database is decommissioned, please migrate to SQLite. Exiting check') + exit(-2) columnsSports = {"id_sports":"integer primary key autoincrement", "name":"varchar(100)", "weight":"float", @@ -236,8 +239,8 @@ "time":"date", "name":"varchar(200)", "sym":"varchar(200)"} - tablesList = ["records","sports","waypoints"] columns = [columnsRecords,columnsSports,columnsWaypoints] + tablesList = {"records":columnsRecords,"sports":columnsSports,"waypoints":columnsWaypoints} try: tablesDB = self.ddbbObject.select("sqlite_master","name", "type IN ('table','view') AND name NOT LIKE 'sqlite_%' ORDER BY name") logging.debug('Found '+ str(len(tablesDB))+' tables in db: '+ str(tablesDB)) @@ -248,15 +251,15 @@ if len(tablesDB) > len(tablesList): logging.info('Database has more tables than expected, please check duplicity!') for entry in tablesDB: - if tablesList.count(entry[0]) > 0: + if entry[0] in tablesList: logging.debug('Inspecting '+str(entry[0])+' table') - #self.checkTable(table,columns[tablesList.pos(table)]) # ToDo - tablesList.remove(entry[0]) + self.ddbbObject.checkTable(entry[0],tablesList[entry[0]]) # ToDo + del tablesList[entry[0]] if len(tablesList) > 0: logging.info('Missing '+str(len(tablesList))+' tables in database, adding them') for table in tablesList: logging.info('Adding table '+str(table)) - #self.createTableDefault(table,columns[tablesList.pos(table)]) # ToDo -> review sqliteUtils.createTables + #self.ddbbObject.createTableDefault(table,columns[tablesList.pos(table)]) # ToDo -> review sqliteUtils.createTables else: logging.info('Database has all needed tables') logging.debug('<<') Modified: pytrainer/trunk/pytrainer/lib/sqliteUtils.py =================================================================== --- pytrainer/trunk/pytrainer/lib/sqliteUtils.py 2009-11-19 06:04:01 UTC (rev 391) +++ pytrainer/trunk/pytrainer/lib/sqliteUtils.py 2009-11-19 21:10:35 UTC (rev 392) @@ -179,3 +179,29 @@ retorno.append(row) return retorno + def checkTable(self,tableName,columns): + """19.11.2009 - dgranda + Checks column names and values from table and adds something if missed. New in version 1.7.0 + args: + tableName - string with name of the table + columns - dictionary containing column names and data types coming from definition + returns: none""" + logging.debug('>>') + cur = self.db.cursor() + sql = "PRAGMA table_info(%s);" %tableName + cur.execute(sql) + tableInfo = [] + for row in cur: + tableInfo.append(row) + logging.debug('Raw data retrieved from table '+str(tableName)+': '+str(tableInfo)) + logging.debug('Table '+str(tableName)+' definition: '+str(columns)) + # Comparing data retrieved from DB and what comes from definition + # Extracting data needed (column names and types) + tableInfoComp = {} + for field in tableInfo: + newField = {field[1]:field[2]} + tableInfoComp.update(newField) + logging.debug('Useful data retrieved from table '+str(tableName)+': '+str(tableInfoComp)) + # Finding out if they differ and what exactly if yes - ToDo + logging.debug('<<') + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-19 06:04:09
|
Revision: 391 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=391&view=rev Author: jblance Date: 2009-11-19 06:04:01 +0000 (Thu, 19 Nov 2009) Log Message: ----------- Fix for bug 2811470 - clickable link for further details on MET (links to wikipedia) Modified Paths: -------------- pytrainer/trunk/glade/pytrainer.glade pytrainer/trunk/pytrainer/gui/windowmain.py Modified: pytrainer/trunk/glade/pytrainer.glade =================================================================== --- pytrainer/trunk/glade/pytrainer.glade 2009-11-19 05:32:10 UTC (rev 390) +++ pytrainer/trunk/glade/pytrainer.glade 2009-11-19 06:04:01 UTC (rev 391) @@ -10527,25 +10527,16 @@ <property name="y_options"></property> </packing> </child> - - <child> - <widget class="GtkLabel" id="label157"> - <property name="visible">True</property> - <property name="label" translatable="yes"><small><b>Note:</b> You can get your M.E.T. sport Coefficient here: http://pytrainer.e-oss.net/met.pdf</small></property> - <property name="use_underline">False</property> - <property name="use_markup">True</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> - </widget> + <child> + <widget class="GtkLinkButton" id="metlinkbutton"> + <property name="label" translatable="yes">More information on determining yor M.E.T sport coefficient on Wikipedia</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="has_tooltip">True</property> + <property name="relief">none</property> + <property name="uri">http://en.wikipedia.org/wiki/Metabolic_equivalent</property> + </widget> <packing> <property name="left_attach">0</property> <property name="right_attach">3</property> @@ -11135,31 +11126,23 @@ </child> <child> - <widget class="GtkLabel" id="label-2147483647"> - <property name="visible">True</property> - <property name="label" translatable="yes"><small><b>Note:</b> You can get your M.E.T. sport Coefficient here: http://pytrainer.e-oss.net/met.pdf</small></property> - <property name="use_underline">False</property> - <property name="use_markup">True</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> - <property name="width_chars">-1</property> - <property name="single_line_mode">False</property> - <property name="angle">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> + <widget class="GtkLinkButton" id="linkbutton1"> + <property name="label" translatable="yes">More information on determining yor M.E.T sport coefficient on Wikipedia</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="has_tooltip">True</property> + <property name="relief">none</property> + <property name="uri">http://en.wikipedia.org/wiki/Metabolic_equivalent</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">2</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> </child> </widget> <packing> Modified: pytrainer/trunk/pytrainer/gui/windowmain.py =================================================================== --- pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-19 05:32:10 UTC (rev 390) +++ pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-19 06:04:01 UTC (rev 391) @@ -31,6 +31,10 @@ class Main(SimpleGladeApp): def __init__(self, data_path = None, parent = None, version = None): + def url_hook(dialog, url): + pytrainer.lib.webUtils.open_url_in_browser(url) + # Available in PyGTK 2.6 and above + gtk.about_dialog_set_url_hook(url_hook) self.version = version self.parent = parent self.data_path = data_path This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-19 05:32:18
|
Revision: 390 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=390&view=rev Author: jblance Date: 2009-11-19 05:32:10 +0000 (Thu, 19 Nov 2009) Log Message: ----------- Fix for bug 2089342 auto refresh after import, edit and delete of records Modified Paths: -------------- pytrainer/trunk/pytrainer/gui/windowmain.py pytrainer/trunk/pytrainer/main.py Modified: pytrainer/trunk/pytrainer/gui/windowmain.py =================================================================== --- pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-18 19:19:47 UTC (rev 389) +++ pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-19 05:32:10 UTC (rev 390) @@ -664,12 +664,12 @@ ###################### def on_edit_clicked(self,widget): - selected,iter = self.recordTreeView.get_selection().get_selected() + selected,iter = self.recordTreeView.get_selection().get_selected() id_record = selected.get_value(iter,0) self.parent.editRecord(id_record) def on_remove_clicked(self,widget): - selected,iter = self.recordTreeView.get_selection().get_selected() + selected,iter = self.recordTreeView.get_selection().get_selected() id_record = selected.get_value(iter,0) self.parent.removeRecord(id_record) Modified: pytrainer/trunk/pytrainer/main.py =================================================================== --- pytrainer/trunk/pytrainer/main.py 2009-11-18 19:19:47 UTC (rev 389) +++ pytrainer/trunk/pytrainer/main.py 2009-11-19 05:32:10 UTC (rev 390) @@ -185,6 +185,7 @@ logging.error('File '+pluginFile+' not valid') else: logging.debug("No files returned from Plugin") + self.refreshListRecords() logging.debug('<<') def runExtension(self,extension,id): @@ -354,6 +355,7 @@ if date == None: date = self.date.getDate() self.record.newRecord(list_sport, date, title, distance, time, upositive, unegative, bpm, calories, comment) + self.refreshListRecords() logging.debug('<<') def editRecord(self, id_record): @@ -361,6 +363,7 @@ list_sport = self.profile.getSportList() logging.debug('id_record: '+str(id_record)+' | list_sport: '+str(list_sport)) self.record.editRecord(id_record,list_sport) + self.refreshListRecords() logging.debug('<<') def removeRecord(self, id_record, confirm = False): @@ -373,6 +376,7 @@ warning = Warning(self.data_path,self.removeRecord,params) warning.set_text(msg) warning.run() + self.refreshListRecords() logging.debug('<<') def removeWaypoint(self,id_waypoint, confirm = False): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dg...@us...> - 2009-11-18 19:19:55
|
Revision: 389 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=389&view=rev Author: dgranda Date: 2009-11-18 19:19:47 +0000 (Wed, 18 Nov 2009) Log Message: ----------- Created main function to steer database check Modified Paths: -------------- pytrainer/trunk/pytrainer/lib/ddbb.py Modified: pytrainer/trunk/pytrainer/lib/ddbb.py =================================================================== --- pytrainer/trunk/pytrainer/lib/ddbb.py 2009-11-18 10:32:51 UTC (rev 388) +++ pytrainer/trunk/pytrainer/lib/ddbb.py 2009-11-18 19:19:47 UTC (rev 389) @@ -80,7 +80,6 @@ ret_val = self.ddbbObject.freeExec(sql) return ret_val[0][0] - def addTitle2ddbb(self): #this function add a title column in #the record ddbb. New in 0.9.9 version @@ -194,10 +193,71 @@ logging.error('Column date_time_utc already exists in DB. Printing traceback and continuing') traceback.print_exc() - def shortFromLocal(self, getSport=True): # Check LEFT and RIGHT JOINS with people with multiple sports + def shortFromLocal(self, getSport=True): # Check LEFT and RIGHT JOINS for people with multiple sports if getSport is True: sql = "select sports.name,records.date_time_utc from sports INNER JOIN records ON sports.id_sports = records.sport" else: sql = "select records.date_time_utc from sports INNER JOIN records ON sports.id_sports = records.sport" return self.ddbbObject.freeExec(sql) + def checkDBIntegrity(self): + """17.11.2009 - dgranda + Retrieves tables and columns from database and adds something if missed. New in version 1.7.0 + args: none + returns: none""" + logging.debug('>>') + columnsSports = {"id_sports":"integer primary key autoincrement", + "name":"varchar(100)", + "weight":"float", + "met":"float"} + columnsRecords = {"id_record":"integer primary key autoincrement", + "date":"date", + "sport":"integer", + "distance":"float", + "time":"varchar(200)", + "beats":"float", + "average":"float", + "calories":"int", + "comments":"text", + "gpslog":"varchar(200)", + "title":"varchar(200)", + "upositive":"float", + "unegative":"float", + "maxspeed":"float", + "maxpace":"float", + "pace":"float", + "maxbeats":"float", + "date_time_utc":"varchar2(20)"} + columnsWaypoints = {"id_waypoint":"integer primary key autoincrement", + "lat":"float", + "lon":"float", + "ele":"float", + "comment":"varchar(240)", + "time":"date", + "name":"varchar(200)", + "sym":"varchar(200)"} + tablesList = ["records","sports","waypoints"] + columns = [columnsRecords,columnsSports,columnsWaypoints] + try: + tablesDB = self.ddbbObject.select("sqlite_master","name", "type IN ('table','view') AND name NOT LIKE 'sqlite_%' ORDER BY name") + logging.debug('Found '+ str(len(tablesDB))+' tables in db: '+ str(tablesDB)) + except: + logging.error('Not able to retrieve which tables are in DB. Printing traceback') + traceback.print_exc() + exit(-1) + if len(tablesDB) > len(tablesList): + logging.info('Database has more tables than expected, please check duplicity!') + for entry in tablesDB: + if tablesList.count(entry[0]) > 0: + logging.debug('Inspecting '+str(entry[0])+' table') + #self.checkTable(table,columns[tablesList.pos(table)]) # ToDo + tablesList.remove(entry[0]) + if len(tablesList) > 0: + logging.info('Missing '+str(len(tablesList))+' tables in database, adding them') + for table in tablesList: + logging.info('Adding table '+str(table)) + #self.createTableDefault(table,columns[tablesList.pos(table)]) # ToDo -> review sqliteUtils.createTables + else: + logging.info('Database has all needed tables') + logging.debug('<<') + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-18 10:33:00
|
Revision: 388 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=388&view=rev Author: jblance Date: 2009-11-18 10:32:51 +0000 (Wed, 18 Nov 2009) Log Message: ----------- Initial week view code Modified Paths: -------------- pytrainer/trunk/glade/pytrainer.glade pytrainer/trunk/pytrainer/gui/drawArea.py pytrainer/trunk/pytrainer/gui/windowmain.py pytrainer/trunk/pytrainer/lib/date.py pytrainer/trunk/pytrainer/main.py pytrainer/trunk/pytrainer/record.py Added Paths: ----------- pytrainer/trunk/pytrainer/weekgraph.py Modified: pytrainer/trunk/glade/pytrainer.glade =================================================================== --- pytrainer/trunk/glade/pytrainer.glade 2009-11-16 10:01:05 UTC (rev 387) +++ pytrainer/trunk/glade/pytrainer.glade 2009-11-18 10:32:51 UTC (rev 388) @@ -3995,6 +3995,29 @@ <property name="type">tab</property> </packing> </child> + <child> + <widget class="GtkVBox" id="weekview"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + <child> + <widget class="GtkLabel" id="weekviewlabel"> + <property name="visible">True</property> + <property name="label" translatable="yes">Week</property> + </widget> + <packing> + <property name="position">2</property> + <property name="tab_fill">False</property> + <property name="type">tab</property> + </packing> + </child> <child> <widget class="GtkVBox" id="monthview"> Modified: pytrainer/trunk/pytrainer/gui/drawArea.py =================================================================== --- pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-16 10:01:05 UTC (rev 387) +++ pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-18 10:32:51 UTC (rev 388) @@ -21,9 +21,8 @@ from matplotlib.figure import Figure from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvasGTK from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar -#from matplotlib.numerix import * import matplotlib.pyplot as plt -#from pylab import * +import pylab import logging class DrawArea: @@ -37,7 +36,7 @@ #self.drawDefault() logging.debug('<<') - def stadistics(self,type,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): + def stadistics(self,type,xvalues,yvalues,xlabel,ylabel,title,color=None,zones=None): logging.debug('>>') if len(xvalues[0]) < 1: #self.drawDefault() @@ -47,6 +46,8 @@ logging.debug("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) if type == "bars": self.drawBars(xvalues,yvalues,xlabel,ylabel,title,color) + elif type == "stackedbars": + self.drawStackedBars(xvalues,yvalues,xlabel,ylabel,title) elif type == "plot": self.drawPlot(xvalues,yvalues,xlabel,ylabel,title,color,zones) elif type == "pie": @@ -54,14 +55,8 @@ logging.debug('<<') def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color): - logging.debug('>>') - - # ToDo: check why vertical container is shared - for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: - logging.debug('Removing child: '+str(child)) - self.vbox.remove(child) - + logging.debug('>>') + self.removeVboxChildren() figure = Figure(figsize=(6,4), dpi=72) #canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea @@ -113,19 +108,81 @@ logging.debug('<<') + def getColor(self, x): + colors=["b","g","r","c","m","y","k", "w"] + if x > len(colors): + x = x % len(colors) + return colors[x] + + def fmt(self, x): + if x <= 0.0001: + return ' ' + else: + return '%1.1f' % x + + def drawStackedBars(self,xbars,yvalues,xlabel,ylabel,title): + '''function to draw stacked bars + xbars needs to be a list of strings, e.g. ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + yvalues needs to be a dict e.g. {'Kayak': {'Tue': 10.08, 'Fri': 17.579999999999998, 'Thu': 15.66, 'Sat': 30.619999999999997}, {'Run': {'Mon': 9.65, 'Sun': 15.59}} + ''' + #TODO tidy + #Add totals to table? + logging.debug('>>') + self.removeVboxChildren() + keys = yvalues.keys() + numRows = len(keys) + numCols = len(xbars) + if numRows == 0: + return + width = .8 + figure = plt.figure(figsize=(6,4), dpi=72) + axis = plt.subplot(111) + + ybottoms = [0] * numCols + yheights = [0] * numCols + inds = xrange(0, numCols) + xvals = [x+(1-width)/2 for x in xrange(0, numCols)] + cellText = [] + for key in keys: + for ind in inds: + ybottoms[ind] += yheights[ind] + yheights[ind] = 0 #Zero heights + color = self.getColor(keys.index(key)) + for xvalue in xbars: + index = xbars.index(xvalue) + if xvalue in yvalues[key]: + height = yvalues[key][xvalue] + else: + height = 0.000000000001 + yheights[index] = height + cellText.append([self.fmt(x) for x in yheights]) + axis.bar(xvals, yheights, bottom=ybottoms, width=width, color=color, align='edge', label=key) + axis.set_xticklabels('' * len(xbars)) + axis.set_ylabel(ylabel) + plt.title(title) + axis.legend(loc=0) + + ## try to do some table stuff + colLabels = xbars + rowLabels = keys + axis.table(cellText=cellText, cellLoc='center', rowLabels=rowLabels, colLabels=colLabels, loc='bottom') + plt.subplots_adjust(left=0.15,bottom=0.08+(0.03*numRows)) + axis.grid(True) + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + canvas.show() + self.vbox.pack_start(canvas, True, True) + toolbar = NavigationToolbar(canvas, self.window) + self.vbox.pack_start(toolbar, False, False) + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + + logging.debug('<<') + def drawPlot(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') - logging.debug('xlabel: '+str(xlabel)+' | ylabel: '+str(ylabel)+' | title: '+str(title)) - vboxChildren = self.vbox.get_children() - logging.debug('Vbox has %d children %s' % (len(vboxChildren), str(vboxChildren) )) - # ToDo: check why vertical container is shared - for child in vboxChildren: - #Remove all FigureCanvasGTK and NavigationToolbar2GTKAgg to stop double ups of graphs - if isinstance(child, matplotlib.backends.backend_gtkagg.FigureCanvasGTK) or isinstance(child, matplotlib.backends.backend_gtkagg.NavigationToolbar2GTKAgg): - logging.debug('Removing child: '+str(child)) - self.vbox.remove(child) - + self.removeVboxChildren() figure = Figure() figure.clf() i = 0 @@ -167,16 +224,7 @@ def drawPie(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') - - vboxChildren = self.vbox.get_children() - logging.debug('Vbox has %d children %s' % (len(vboxChildren), str(vboxChildren) )) - # ToDo: check why vertical container is shared - for child in vboxChildren: - #Remove all FigureCanvasGTK and NavigationToolbar2GTKAgg to stop double ups of graphs - if isinstance(child, matplotlib.backends.backend_gtkagg.FigureCanvasGTK) or isinstance(child, matplotlib.backends.backend_gtkagg.NavigationToolbar2GTKAgg): - logging.debug('Removing child: '+str(child)) - self.vbox.remove(child) - + self.removeVboxChildren() figure = Figure(figsize=(6,4), dpi=72) axis = figure.add_subplot(111) @@ -257,3 +305,18 @@ indLast = ind logging.debug('<<') + def removeVboxChildren(self): + ''' function to delete vbox children so that multiple graphs do not appear + there must a better way to do this - pyplot? + ''' + logging.debug('>>') + #Tidy up draw areas + vboxChildren = self.vbox.get_children() + logging.debug('Vbox has %d children %s' % (len(vboxChildren), str(vboxChildren) )) + # ToDo: check why vertical container is shared + for child in vboxChildren: + #Remove all FigureCanvasGTK and NavigationToolbar2GTKAgg to stop double ups of graphs + if isinstance(child, matplotlib.backends.backend_gtkagg.FigureCanvasGTK) or isinstance(child, matplotlib.backends.backend_gtkagg.NavigationToolbar2GTKAgg): + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) + logging.debug('<<') Modified: pytrainer/trunk/pytrainer/gui/windowmain.py =================================================================== --- pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-16 10:01:05 UTC (rev 387) +++ pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-18 10:32:51 UTC (rev 388) @@ -1,5 +1,3 @@ -# -*- coding: iso-8859-1 -*- - #Copyright (C) Fiz Vazquez vu...@si... # Modified by dgranda @@ -106,11 +104,12 @@ id = selected.get_value(iter,0) self.parent.runExtension(extension,id) - def createGraphs(self,RecordGraph,DayGraph,MonthGraph,YearGraph,HeartRateGraph): + def createGraphs(self,RecordGraph,DayGraph,WeekGraph, MonthGraph,YearGraph,HeartRateGraph): self.drawarearecord = RecordGraph(self.record_vbox, self.window1, self.record_combovalue, self.record_combovalue2) self.drawareaheartrate = HeartRateGraph(self.heartrate_vbox, self.window1, self.heartrate_vbox2) #self.drawareaday = DayGraph(self.day_vbox, self.day_combovalue) self.day_vbox.hide() + self.drawareaweek = WeekGraph(self.weekview, self.window1) self.drawareamonth = MonthGraph(self.month_vbox, self.window1, self.month_combovalue,self.month_combovalue2) self.drawareayear = YearGraph(self.year_vbox, self.window1, self.year_combovalue,self.year_combovalue2) @@ -334,6 +333,11 @@ self.googlemaps.drawMap(id_record) logging.debug("<<") + def actualize_weekview(self, record_list, date_ini, date_end): + logging.debug(">>") + self.drawareaweek.drawgraph(record_list) + logging.debug("<<") + def actualize_monthview(self,record_list, nameMonth): logging.debug(">>") self.month_date.set_text(nameMonth) @@ -692,8 +696,10 @@ elif page == 1: self.selected_view="day" elif page == 2: + self.selected_view="week" + elif page == 3: self.selected_view="month" - elif page == 3: + elif page == 4: self.selected_view="year" self.parent.refreshGraphView(self.selected_view) @@ -742,7 +748,7 @@ def on_calendar_changemonth(self,widget): logging.debug("--") self.block = True - self.notebook.set_current_page(2) + self.notebook.set_current_page(3) self.selected_view="month" self.parent.refreshListRecords() self.parent.refreshGraphView(self.selected_view) @@ -750,7 +756,7 @@ def on_calendar_next_year(self,widget): logging.debug("--") self.block = True - self.notebook.set_current_page(3) + self.notebook.set_current_page(4) self.selected_view="year" self.parent.refreshListRecords() self.parent.refreshGraphView(self.selected_view) Modified: pytrainer/trunk/pytrainer/lib/date.py =================================================================== --- pytrainer/trunk/pytrainer/lib/date.py 2009-11-16 10:01:05 UTC (rev 387) +++ pytrainer/trunk/pytrainer/lib/date.py 2009-11-18 10:32:51 UTC (rev 388) @@ -49,6 +49,13 @@ def time2string(self,date): return "%0.4d-%0.2d-%0.2d" %(int(date[0]),int(date[1]),int(date[2])) + + def getWeekInterval(self,date): + weekDate = datetime.datetime.strptime(date, "%Y-%m-%d") + dayOfWeek = int(weekDate.strftime("%w")) + date_ini = weekDate + datetime.timedelta(days=0-dayOfWeek) + date_end = weekDate + datetime.timedelta(days=6-dayOfWeek) + return date_ini.strftime("%Y-%m-%d"), date_end.strftime("%Y-%m-%d") def getMonthInterval(self,date): year,month,day = date.split("-") Modified: pytrainer/trunk/pytrainer/main.py =================================================================== --- pytrainer/trunk/pytrainer/main.py 2009-11-16 10:01:05 UTC (rev 387) +++ pytrainer/trunk/pytrainer/main.py 2009-11-18 10:32:51 UTC (rev 388) @@ -39,6 +39,7 @@ from profile import Profile from recordgraph import RecordGraph from daygraph import DayGraph +from weekgraph import WeekGraph from monthgraph import MonthGraph from yeargraph import YearGraph from heartrategraph import HeartRateGraph @@ -131,7 +132,7 @@ self.plugins = Plugins(data_path, self) self.loadPlugins() self.loadExtensions() - self.windowmain.createGraphs(RecordGraph,DayGraph,MonthGraph,YearGraph,HeartRateGraph) + self.windowmain.createGraphs(RecordGraph,DayGraph,WeekGraph, MonthGraph,YearGraph,HeartRateGraph) self.windowmain.createMap(Googlemaps,self.waypoint) self.windowmain.createWaypointEditor(WaypointEditor,self.waypoint) self.windowmain.on_calendar_selected(None) @@ -218,6 +219,11 @@ record_list = self.record.getrecordList(date_selected) self.windowmain.actualize_dayview(record_list) selected,iter = self.windowmain.recordTreeView.get_selection().get_selected() + elif view=="week": + logging.debug('week view') + date_ini, date_end = self.date.getWeekInterval(date_selected) + record_list = self.record.getrecordPeriod(date_ini, date_end) + self.windowmain.actualize_weekview(record_list, date_ini, date_end) elif view=="month": logging.debug('month view') date_ini, date_end = self.date.getMonthInterval(date_selected) @@ -235,6 +241,8 @@ record_list = self.record.getrecordPeriodSport(date_ini, date_end,sport) self.windowmain.actualize_yearview(record_list, year) self.windowmain.actualize_yeargraph(record_list) + else: + print "Unknown view %s" % view logging.debug('<<') def refreshRecordGraphView(self, view): Modified: pytrainer/trunk/pytrainer/record.py =================================================================== --- pytrainer/trunk/pytrainer/record.py 2009-11-16 10:01:05 UTC (rev 387) +++ pytrainer/trunk/pytrainer/record.py 2009-11-18 10:32:51 UTC (rev 388) @@ -252,7 +252,13 @@ return self.ddbb.select("records,sports", "sports.name,date,distance,time,beats,comments,average,calories,id_record,maxspeed,maxbeats", "date=\"%s\" and records.sport=sports.id_sports" %date) + + def getrecordPeriod(self,date_ini, date_end): + tables = "records,sports" + condition = "date>=\"%s\" and date<=\"%s\" and records.sport=sports.id_sports" %(date_ini,date_end) + return self.ddbb.select(tables,"sports.name, date,distance,time,beats,comments,average,calories,maxspeed,maxbeats", condition) + def getrecordPeriodSport(self,date_ini, date_end,sport): if sport<1 : tables = "records" Added: pytrainer/trunk/pytrainer/weekgraph.py =================================================================== --- pytrainer/trunk/pytrainer/weekgraph.py (rev 0) +++ pytrainer/trunk/pytrainer/weekgraph.py 2009-11-18 10:32:51 UTC (rev 388) @@ -0,0 +1,55 @@ +# -*- 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 gui.drawArea import DrawArea +import logging +import datetime + +class WeekGraph: + def __init__(self, vbox = None, window = None): + self.drawarea = DrawArea(vbox, window) + + def drawgraph(self,values): + logging.debug(">>") + #print "Found %d records" % len(values) + logging.debug(str(values)) + days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] + valueDict = {} + for record in values: + day = datetime.datetime.strptime(record[1], "%Y-%m-%d").strftime("%a") # Gives Sun, Mon etc for this record + sport = record[0] + distance = record[2] + if sport in valueDict: #Already got this sport + if day in valueDict[sport]: #Already got this sport on this day + valueDict[sport][day] += distance + else: #New day for this sport + valueDict[sport][day] = distance + else: #New sport + valueDict[sport] = {day: distance} + + xlab = "Day" + ylab = "kilometers" + tit = "Week View" + self.drawarea.stadistics("stackedbars",days,valueDict,xlab,ylab,tit) + logging.debug("<<") + + + + + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-16 10:01:13
|
Revision: 387 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=387&view=rev Author: jblance Date: 2009-11-16 10:01:05 +0000 (Mon, 16 Nov 2009) Log Message: ----------- Fix for multiple graphs bug v2 including heartrate pie graph fix Modified Paths: -------------- pytrainer/trunk/pytrainer/gui/drawArea.py Modified: pytrainer/trunk/pytrainer/gui/drawArea.py =================================================================== --- pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-16 09:58:59 UTC (rev 386) +++ pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-16 10:01:05 UTC (rev 387) @@ -168,9 +168,12 @@ def drawPie(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') + vboxChildren = self.vbox.get_children() + logging.debug('Vbox has %d children %s' % (len(vboxChildren), str(vboxChildren) )) # ToDo: check why vertical container is shared - for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: + for child in vboxChildren: + #Remove all FigureCanvasGTK and NavigationToolbar2GTKAgg to stop double ups of graphs + if isinstance(child, matplotlib.backends.backend_gtkagg.FigureCanvasGTK) or isinstance(child, matplotlib.backends.backend_gtkagg.NavigationToolbar2GTKAgg): logging.debug('Removing child: '+str(child)) self.vbox.remove(child) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-16 09:59:08
|
Revision: 386 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=386&view=rev Author: jblance Date: 2009-11-16 09:58:59 +0000 (Mon, 16 Nov 2009) Log Message: ----------- Fix for multiple graphs bug (inc reinstating the drop down for the record graph) Modified Paths: -------------- pytrainer/trunk/pytrainer/gui/drawArea.py pytrainer/trunk/pytrainer/gui/windowmain.py Modified: pytrainer/trunk/pytrainer/gui/drawArea.py =================================================================== --- pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-12 19:33:28 UTC (rev 385) +++ pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-16 09:58:59 UTC (rev 386) @@ -21,7 +21,6 @@ from matplotlib.figure import Figure from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvasGTK from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar -#from matplotlib.backends.backend_gtk import FigureCanvasGTK #from matplotlib.numerix import * import matplotlib.pyplot as plt #from pylab import * @@ -55,15 +54,16 @@ logging.debug('<<') def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color): - logging.debug('>>') - + logging.debug('>>') + # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - logging.debug('Removing child: '+str(child)) - self.vbox.remove(child) + if self.vbox.get_children()[0] != child: + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure(figsize=(6,4), dpi=72) - #canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + #canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea xmod = 0.4 if len(xvalues) > 1: @@ -101,6 +101,7 @@ else: axis.set_title("%s" %(ylabel[0])) + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() self.vbox.pack_start(canvas, True, True) @@ -114,12 +115,16 @@ def drawPlot(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') - + logging.debug('xlabel: '+str(xlabel)+' | ylabel: '+str(ylabel)+' | title: '+str(title)) + vboxChildren = self.vbox.get_children() + logging.debug('Vbox has %d children %s' % (len(vboxChildren), str(vboxChildren) )) # ToDo: check why vertical container is shared - for child in self.vbox.get_children(): - logging.debug('Removing child: '+str(child)) - self.vbox.remove(child) + for child in vboxChildren: + #Remove all FigureCanvasGTK and NavigationToolbar2GTKAgg to stop double ups of graphs + if isinstance(child, matplotlib.backends.backend_gtkagg.FigureCanvasGTK) or isinstance(child, matplotlib.backends.backend_gtkagg.NavigationToolbar2GTKAgg): + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure() figure.clf() @@ -128,6 +133,7 @@ if i<1: axis = figure.add_subplot(111) axis.plot(xvalues[i],yvalues[i], color=color[i]) + axis.grid(True) for tl in axis.get_yticklabels(): tl.set_color('%s' %color[i]) @@ -135,7 +141,7 @@ ax2 = axis.twinx() ax2.plot(xvalues[i], yvalues[i], color=color[i]) for tl in ax2.get_yticklabels(): - tl.set_color('%s' %color[i]) + tl.set_color('%s' %color[i]) axis.set_xlabel(xlabel[i]) i+=1 @@ -143,10 +149,9 @@ axis.set_title("%s vs %s" %(ylabel[0],ylabel[1])) else: axis.set_title("%s" %(ylabel[0])) - + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() - self.vbox.pack_start(canvas, True, True) toolbar = NavigationToolbar(canvas, self.window) self.vbox.pack_start(toolbar, False, False) @@ -165,11 +170,11 @@ # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - logging.debug('Removing child: '+str(child)) - self.vbox.remove(child) + if self.vbox.get_children()[0] != child: + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure(figsize=(6,4), dpi=72) - figure.clf() axis = figure.add_subplot(111) labels = ["rest"] @@ -201,7 +206,7 @@ fracs = [frac0,frac1,frac2,frac3,frac4, frac5] explode=(0, 0, 0, 0,0,0) axis.pie(fracs, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True) - + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() Modified: pytrainer/trunk/pytrainer/gui/windowmain.py =================================================================== --- pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-12 19:33:28 UTC (rev 385) +++ pytrainer/trunk/pytrainer/gui/windowmain.py 2009-11-16 09:58:59 UTC (rev 386) @@ -225,7 +225,7 @@ def actualize_heartrategraph(self,record_list): logging.debug(">>") self.drawareaheartrate.drawgraph(record_list) - logging.debug(">>") + logging.debug("<<") def actualize_hrview(self,record_list,zones,is_karvonen_method): logging.debug(">>") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dg...@us...> - 2009-11-12 19:33:38
|
Revision: 385 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=385&view=rev Author: dgranda Date: 2009-11-12 19:33:28 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Removed widgets from vertical containers to avoid graphs multiplicity. Improved logging Modified Paths: -------------- pytrainer/trunk/pytrainer/gui/drawArea.py Modified: pytrainer/trunk/pytrainer/gui/drawArea.py =================================================================== --- pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-12 19:31:14 UTC (rev 384) +++ pytrainer/trunk/pytrainer/gui/drawArea.py 2009-11-12 19:33:28 UTC (rev 385) @@ -19,14 +19,14 @@ import matplotlib matplotlib.use('GTK') from matplotlib.figure import Figure -from matplotlib.backends.backend_gtk import FigureCanvasGTK +from matplotlib.backends.backend_gtkagg import FigureCanvasGTKAgg as FigureCanvasGTK +from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar +#from matplotlib.backends.backend_gtk import FigureCanvasGTK #from matplotlib.numerix import * import matplotlib.pyplot as plt #from pylab import * import logging -from matplotlib.backends.backend_gtkagg import NavigationToolbar2GTKAgg as NavigationToolbar - class DrawArea: def __init__(self, vbox = None, window = None): logging.debug('>>') @@ -45,7 +45,7 @@ return False #logging.debug('xvalues: '+str(xvalues)) #logging.debug('yvalues: '+str(yvalues)) - logging.info("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) + logging.debug("Type: "+type+" | title: "+str(title)+" | col: "+str(color)+" | xlabel: "+str(xlabel)+" | ylabel: "+str(ylabel)) if type == "bars": self.drawBars(xvalues,yvalues,xlabel,ylabel,title,color) elif type == "plot": @@ -55,14 +55,15 @@ logging.debug('<<') def drawBars(self,xvalues,yvalues,xlabel,ylabel,title,color): - logging.debug('>>') - + logging.debug('>>') + + # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: - self.vbox.remove(child) + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure(figsize=(6,4), dpi=72) - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea + #canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea xmod = 0.4 if len(xvalues) > 1: @@ -100,28 +101,33 @@ else: axis.set_title("%s" %(ylabel[0])) - canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() self.vbox.pack_start(canvas, True, True) toolbar = NavigationToolbar(canvas, self.window) self.vbox.pack_start(toolbar, False, False) + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + logging.debug('<<') def drawPlot(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') + logging.debug('xlabel: '+str(xlabel)+' | ylabel: '+str(ylabel)+' | title: '+str(title)) + # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: - self.vbox.remove(child) + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure() + figure.clf() i = 0 for value in xvalues: if i<1: axis = figure.add_subplot(111) axis.plot(xvalues[i],yvalues[i], color=color[i]) - axis.grid(True) for tl in axis.get_yticklabels(): tl.set_color('%s' %color[i]) @@ -129,7 +135,7 @@ ax2 = axis.twinx() ax2.plot(xvalues[i], yvalues[i], color=color[i]) for tl in ax2.get_yticklabels(): - tl.set_color('%s' %color[i]) + tl.set_color('%s' %color[i]) axis.set_xlabel(xlabel[i]) i+=1 @@ -137,12 +143,17 @@ axis.set_title("%s vs %s" %(ylabel[0],ylabel[1])) else: axis.set_title("%s" %(ylabel[0])) - + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() + self.vbox.pack_start(canvas, True, True) toolbar = NavigationToolbar(canvas, self.window) self.vbox.pack_start(toolbar, False, False) + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + if title[0] == 'Stage Profile': figure.savefig('/tmp/stage.png', dpi=75) if title[0] == 'Heart Rate': @@ -151,12 +162,14 @@ def drawPie(self,xvalues,yvalues,xlabel,ylabel,title,color,zones=None): logging.debug('>>') - + + # ToDo: check why vertical container is shared for child in self.vbox.get_children(): - if self.vbox.get_children()[0] != child: - self.vbox.remove(child) + logging.debug('Removing child: '+str(child)) + self.vbox.remove(child) figure = Figure(figsize=(6,4), dpi=72) + figure.clf() axis = figure.add_subplot(111) labels = ["rest"] @@ -188,9 +201,13 @@ fracs = [frac0,frac1,frac2,frac3,frac4, frac5] explode=(0, 0, 0, 0,0,0) axis.pie(fracs, explode=explode, labels=labels, colors=colors, autopct='%1.1f%%', shadow=True) - + canvas = FigureCanvasGTK(figure) # a gtk.DrawingArea canvas.show() + + for child in self.vbox.get_children(): + logging.debug('Child available: '+str(child)) + self.vbox.pack_start(canvas, True, True) logging.debug('<<') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dg...@us...> - 2009-11-12 19:31:25
|
Revision: 384 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=384&view=rev Author: dgranda Date: 2009-11-12 19:31:14 +0000 (Thu, 12 Nov 2009) Log Message: ----------- Improved logging Modified Paths: -------------- pytrainer/trunk/pytrainer/extensions/waypointeditor.py pytrainer/trunk/pytrainer/heartrategraph.py pytrainer/trunk/pytrainer/waypoint.py Modified: pytrainer/trunk/pytrainer/extensions/waypointeditor.py =================================================================== --- pytrainer/trunk/pytrainer/extensions/waypointeditor.py 2009-11-09 11:07:55 UTC (rev 383) +++ pytrainer/trunk/pytrainer/extensions/waypointeditor.py 2009-11-12 19:31:14 UTC (rev 384) @@ -27,25 +27,32 @@ import string,cgi,time import time +import logging class WaypointEditor: - def __init__(self, data_path = None, vbox = None, waypoint=None): + def __init__(self, data_path = None, vbox = None, waypoint=None): + logging.debug(">>") self.data_path = data_path self.conf = checkConf() self.extension = Extension() self.moz = gtkmozembed.MozEmbed() - vbox.pack_start(self.moz, True, True) + vbox.pack_start(self.moz, True, True) vbox.show_all() self.htmlfile = "" self.waypoint=waypoint + logging.debug("<<") def drawMap(self): + logging.debug(">>") #self.createHtml() tmpdir = self.conf.getValue("tmpdir") htmlfile = tmpdir+"/waypointeditor.html" - self.moz.load_url("file://"+htmlfile) + logging.debug("HTML file: "+str(htmlfile)) + self.moz.load_url("file://"+htmlfile) + logging.debug("<<") def createHtml(self,default_waypoint=None): + logging.debug(">>") tmpdir = self.conf.getValue("tmpdir") filename = tmpdir+"/waypointeditor.html" @@ -268,6 +275,6 @@ """ file = fileUtils(filename,content) file.run() + logging.debug("<<") - Modified: pytrainer/trunk/pytrainer/heartrategraph.py =================================================================== --- pytrainer/trunk/pytrainer/heartrategraph.py 2009-11-09 11:07:55 UTC (rev 383) +++ pytrainer/trunk/pytrainer/heartrategraph.py 2009-11-12 19:31:14 UTC (rev 384) @@ -20,26 +20,34 @@ from lib.system import checkConf from lib.xmlUtils import XMLParser from lib.heartrate import * +import logging class HeartRateGraph: def __init__(self, vbox = None, window = None, vbox2 = None): + logging.debug('>>') self.drawarea = DrawArea(vbox, window) self.drawarea2 = DrawArea(vbox2, window) + logging.debug('<<') def drawgraph(self,values): - zones = getZones() - + logging.debug('>>') + zones = getZones() xvalues, yvalues = self.get_values(values) + #logging.debug('xvalues: '+str(xvalues)) + #logging.debug('yvalues: '+str(yvalues)) xlabel,ylabel,title,color = _("Distance (km)"),_("Beats (bpm)"),_("Heart Rate"),"#740074" self.drawarea.stadistics("plot",[xvalues],[yvalues],[xlabel],[ylabel],[title],[color],zones) self.drawarea2.stadistics("pie",[xvalues],[yvalues],[xlabel],[ylabel],[title],[color],zones) + logging.debug('<<') def get_values(self,values): + logging.debug('>>') xvalue = [] yvalue = [] for value in values: xvalue.append(value[0]) - yvalue.append(value[6]) + yvalue.append(value[6]) + logging.debug('<<') return xvalue,yvalue def getFloatValue(self, value): Modified: pytrainer/trunk/pytrainer/waypoint.py =================================================================== --- pytrainer/trunk/pytrainer/waypoint.py 2009-11-09 11:07:55 UTC (rev 383) +++ pytrainer/trunk/pytrainer/waypoint.py 2009-11-12 19:31:14 UTC (rev 384) @@ -20,40 +20,53 @@ from lib.system import checkConf from lib.xmlUtils import XMLParser +import logging + class Waypoint: def __init__(self, data_path = None, parent = None): + logging.debug(">>") self.parent = parent self.data_path = data_path self.conf = checkConf() self.filename = self.conf.getValue("conffile") self.configuration = XMLParser(self.filename) self.ddbb = DDBB(self.configuration) + logging.debug("<<") def removeWaypoint(self,id_waypoint): + logging.debug(">>") self.ddbb.connect() self.ddbb.delete("waypoints", "id_waypoint=\"%s\"" %id_waypoint) self.ddbb.disconnect() + logging.debug("<<") def updateWaypoint(self,id_waypoint,lat,lon,name,desc,sym): + logging.debug(">>") self.ddbb.connect() self.ddbb.update("waypoints","lat,lon,comment,name,sym",[lat,lon,desc,name,sym]," id_waypoint=%d" %id_waypoint) self.ddbb.disconnect() + logging.debug("<<") def getwaypointInfo(self,id_waypoint): + logging.debug(">>") self.ddbb.connect() retorno = self.ddbb.select("waypoint", "lat,lon,ele,comment,time,name,sym" "id_waypoint=\"%s\"" %id_waypoint) self.ddbb.disconnect() + logging.debug("<<") return retorno def getAllWaypoints(self): + logging.debug(">>") self.ddbb.connect() retorno = self.ddbb.select("waypoints","id_waypoint,lat,lon,ele,comment,time,name,sym","1=1 order by name") self.ddbb.disconnect() + logging.debug("<<") return retorno def actualize_fromgpx(self,gpxfile): + logging.debug(">>") self.ddbb.connect() from lib.gpx import Gpx gpx = Gpx(self.data_path,gpxfile) @@ -70,8 +83,10 @@ warning.set_text(msg) warning.run() self.ddbb.disconnect() + logging.debug("<<") def _actualize_fromgpx(self, gpx): + logging.debug(">>") distance, time = gpx.getMaxValues() upositive,unegative = gpx.getUnevenness() self.recordwindow.rcd_upositive.set_text(str(upositive)) @@ -79,4 +94,5 @@ self.recordwindow.set_distance(distance) self.recordwindow.set_recordtime(time/60.0/60.0) self.recordwindow.on_calcaverage_clicked(None) + logging.debug("<<") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-09 11:08:08
|
Revision: 383 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=383&view=rev Author: jblance Date: 2009-11-09 11:07:55 +0000 (Mon, 09 Nov 2009) Log Message: ----------- Plugins-v2 branch merge to trunk Modified Paths: -------------- pytrainer/trunk/plugins/googleearth/conf.xml pytrainer/trunk/pytrainer/gui/windowrecord.py pytrainer/trunk/pytrainer/lib/system.py pytrainer/trunk/pytrainer/lib/xmlUtils.py pytrainer/trunk/pytrainer/main.py pytrainer/trunk/pytrainer/plugins.py pytrainer/trunk/pytrainer/profile.py pytrainer/trunk/pytrainer/record.py pytrainer/trunk/pytrainer.sh pytrainer/trunk/setup.py Added Paths: ----------- pytrainer/trunk/PLUGINS.README pytrainer/trunk/plugins/garmin-gpx/ pytrainer/trunk/plugins/garmin-gpx/conf.xml pytrainer/trunk/plugins/garmin-gpx/garmingpx.py pytrainer/trunk/plugins/garmin-hr/ pytrainer/trunk/plugins/garmin-hr/conf.xml pytrainer/trunk/plugins/garmin-hr/garminhr.py pytrainer/trunk/plugins/garmin-hr/pytrainer.style pytrainer/trunk/plugins/garmin-hr/translate.xsl pytrainer/trunk/plugins/garmin-hr-file/ pytrainer/trunk/plugins/garmin-hr-file/conf.xml pytrainer/trunk/plugins/garmin-hr-file/garminhrfile.py pytrainer/trunk/plugins/garmin-hr-file/pytrainer.style pytrainer/trunk/plugins/garmin-hr-file/translate.xsl pytrainer/trunk/plugins/garmin-tcxv2/ pytrainer/trunk/plugins/garmin-tcxv2/conf.xml pytrainer/trunk/plugins/garmin-tcxv2/garmin-tcxv2.py pytrainer/trunk/plugins/garmin-tcxv2/translate.xsl pytrainer/trunk/plugins/googleearth/main.py pytrainer/trunk/pytrainer/gui/dialogs.py pytrainer/trunk/pytrainer/lib/xmlValidation.py pytrainer/trunk/schemas/ pytrainer/trunk/schemas/Cluetrust_gpxdata10.xsd pytrainer/trunk/schemas/GarminTrainingCenterDatabase_v1-gpsbabel.xsd pytrainer/trunk/schemas/GarminTrainingCenterDatabase_v1.xsd pytrainer/trunk/schemas/GarminTrainingCenterDatabase_v2.xsd pytrainer/trunk/schemas/README pytrainer/trunk/schemas/Topografix_gpx11.xsd pytrainer/trunk/schemas/validate_gpsfile.py Removed Paths: ------------- pytrainer/trunk/plugins/garmin-gpx/conf.xml pytrainer/trunk/plugins/garmin-gpx/garmingpx.py pytrainer/trunk/plugins/garmin-hr/conf.xml pytrainer/trunk/plugins/garmin-hr/garminhr.py pytrainer/trunk/plugins/garmin-hr/pytrainer.style pytrainer/trunk/plugins/garmin-hr/translate.xsl pytrainer/trunk/plugins/garmin-hr-file/conf.xml pytrainer/trunk/plugins/garmin-hr-file/garminhrfile.py pytrainer/trunk/plugins/garmin-hr-file/pytrainer.style pytrainer/trunk/plugins/garmin-hr-file/translate.xsl pytrainer/trunk/plugins/garmin-tcxv2/conf.xml pytrainer/trunk/plugins/garmin-tcxv2/garmin-tcxv2.py pytrainer/trunk/plugins/garmin-tcxv2/translate.xsl pytrainer/trunk/plugins/garmingpx/ pytrainer/trunk/plugins/ipod/ pytrainer/trunk/schemas/Cluetrust_gpxdata10.xsd pytrainer/trunk/schemas/GarminTrainingCenterDatabase_v1-gpsbabel.xsd pytrainer/trunk/schemas/GarminTrainingCenterDatabase_v1.xsd pytrainer/trunk/schemas/GarminTrainingCenterDatabase_v2.xsd pytrainer/trunk/schemas/README pytrainer/trunk/schemas/Topografix_gpx11.xsd pytrainer/trunk/schemas/validate_gpsfile.py Property Changed: ---------------- pytrainer/trunk/ Property changes on: pytrainer/trunk ___________________________________________________________________ Added: svn:mergeinfo + /pytrainer/branches/plugins-v2:345-382 Copied: pytrainer/trunk/PLUGINS.README (from rev 382, pytrainer/branches/plugins-v2/PLUGINS.README) =================================================================== --- pytrainer/trunk/PLUGINS.README (rev 0) +++ pytrainer/trunk/PLUGINS.README 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,31 @@ +Information on creating Plugins +=========================================== + +Plugins are created by: +1) Making a directory in <pytrainer>/plugins/ +2) Creating a python class in a file in your directory + - class must have run(self) function + - run(self) returns tuple of GPX files to import +3) Creating a conf.xml configuration file in your directory with at least the following information: + <?xml version="1.0" ?> + <pytrainer-plugin + name="Garmin v2 TCX" + description="Import your records from a version 2 TCX file from a Garmin gps device (i.e. Forerunner 405)" + plugincode="garminTCXv2" + pluginbutton="Import from Garmin TCX (version 2)" + executable="garmintcxv2" + > + </pytrainer-plugin> + +Where + name: is the name of your plugin + description: is the description + plugincode: is the name of the class in your plugin file + pluginbutton: is the label that the menu option will have once your plugin is enabled + executable: is the file that the python class in in (without the .py extension) + + + + + + Deleted: pytrainer/trunk/plugins/garmin-gpx/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-gpx/conf.xml 2009-11-09 11:07:55 UTC (rev 383) @@ -1,10 +0,0 @@ -<?xml version="1.0" ?> -<pytrainer-plugin - name="Garmin GPX file" - description="Import your records directly from a garmin gpx file." - plugincode="garmingpx" - pluginbutton="Import from file: Garmin GPX" - executable="garmingpx" -> -<conf-values variable="Force_sport_to" value=""/> -</pytrainer-plugin> Copied: pytrainer/trunk/plugins/garmin-gpx/conf.xml (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml) =================================================================== --- pytrainer/trunk/plugins/garmin-gpx/conf.xml (rev 0) +++ pytrainer/trunk/plugins/garmin-gpx/conf.xml 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<pytrainer-plugin + name="Garmin GPX file" + description="Import your records directly from a garmin gpx file." + plugincode="garmingpx" + pluginbutton="Import from file: Garmin GPX" + executable="garmingpx" +> +<conf-values variable="Force_sport_to" value=""/> +</pytrainer-plugin> Deleted: pytrainer/trunk/plugins/garmin-gpx/garmingpx.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-gpx/garmingpx.py 2009-11-09 11:07:55 UTC (rev 383) @@ -1,114 +0,0 @@ -#!/usr/bin/env python - -#Copyright (C) - -#Based on plugin by Kevin Dwyer ke...@ph... - -#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 logging -import os -import shutil -from gui.dialogs import fileChooserDialog, guiFlush -import xml.etree.cElementTree -from lib.xmlUtils import XMLParser - -class garmingpx(): - """ Plugin to import from a GPX file or files - Expects only one activity in each file - Checks to see if any entries are in the database with the same start time - """ - def __init__(self, parent = None, validate=False): - self.parent = parent - self.tmpdir = self.parent.conf.getValue("tmpdir") - self.validate = validate - self.data_path = os.path.dirname(__file__) - self.sport = self.getConfValue("Force_sport_to") - - def getConfValue(self, confVar): - info = XMLParser(self.data_path+"/conf.xml") - code = info.getValue("pytrainer-plugin","plugincode") - plugindir = self.parent.conf.getValue("plugindir") - if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): - value = None - else: - info = XMLParser(plugindir+"/"+code+"/conf.xml") - value = info.getValue("pytrainer-plugin",confVar) - return value - - def run(self): - logging.debug(">>") - selectedFiles = fileChooserDialog(title="Choose a GPX file (or files) to import", multiple=True).getFiles() - guiFlush() - importfiles = [] - if not selectedFiles: - return importfiles - for filename in selectedFiles: - if self.valid_input_file(filename): - if not self.inDatabase(filename): - sport = self.getSport(filename) - gpxfile = "%s/garmin-gpx-%d.gpx" % (self.tmpdir, len(importfiles)) - shutil - shutil.copy(filename, gpxfile) - importfiles.append((gpxfile, sport)) - else: - logging.debug("%s already in database. Skipping import." % (filename) ) - else: - logging.info("File %s failed validation" % (filename)) - logging.debug("<<") - return importfiles - - def valid_input_file(self, filename): - """ Function to validate input file if requested""" - if not self.validate: #not asked to validate - logging.debug("Not validating %s" % (filename) ) - return True - else: - #To validate GPX as used for pytrainer must test against both Topograpfix and Cluetrust - topografixXSLfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/Topografix_gpx11.xsd" - cluetrustXSLfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/Cluetrust_gpxdata10.xsd" - from lib.xmlValidation import xmlValidator - validator = xmlValidator() - return validator.validateXSL(filename, topografixXSLfile) and validator.validateXSL(filename, cluetrustXSLfile) - - def inDatabase(self, filename): - """ Function to determine if a given file has already been imported into the database - only compares date and start time (sport may have been changed in DB after import) - only valid for GPX files with a single activity - """ - time = self.detailsFromGPX(filename) - if self.parent.parent.ddbb.select("records","*","date_time_utc=\"%s\"" % (time)): - return True - else: - return False - - def getSport(self, filename): - #return sport from overide if present or default to "import" - if self.sport: - return self.sport - sport = "import" - return sport - - def detailsFromGPX(self, filename): - """ Function to return the first time element from a GPX 1.1 file """ - tree = xml.etree.cElementTree.ElementTree(file=filename) - root = tree.getroot() - timeElement = root.find(".//{http://www.topografix.com/GPX/1/1}time") - if timeElement is None: - return None - else: - return timeElement.text - - Copied: pytrainer/trunk/plugins/garmin-gpx/garmingpx.py (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py) =================================================================== --- pytrainer/trunk/plugins/garmin-gpx/garmingpx.py (rev 0) +++ pytrainer/trunk/plugins/garmin-gpx/garmingpx.py 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,114 @@ +#!/usr/bin/env python + +#Copyright (C) + +#Based on plugin by Kevin Dwyer ke...@ph... + +#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 logging +import os +import shutil +from gui.dialogs import fileChooserDialog, guiFlush +import xml.etree.cElementTree +from lib.xmlUtils import XMLParser + +class garmingpx(): + """ Plugin to import from a GPX file or files + Expects only one activity in each file + Checks to see if any entries are in the database with the same start time + """ + def __init__(self, parent = None, validate=False): + self.parent = parent + self.tmpdir = self.parent.conf.getValue("tmpdir") + self.validate = validate + self.data_path = os.path.dirname(__file__) + self.sport = self.getConfValue("Force_sport_to") + + def getConfValue(self, confVar): + info = XMLParser(self.data_path+"/conf.xml") + code = info.getValue("pytrainer-plugin","plugincode") + plugindir = self.parent.conf.getValue("plugindir") + if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): + value = None + else: + info = XMLParser(plugindir+"/"+code+"/conf.xml") + value = info.getValue("pytrainer-plugin",confVar) + return value + + def run(self): + logging.debug(">>") + selectedFiles = fileChooserDialog(title="Choose a GPX file (or files) to import", multiple=True).getFiles() + guiFlush() + importfiles = [] + if not selectedFiles: + return importfiles + for filename in selectedFiles: + if self.valid_input_file(filename): + if not self.inDatabase(filename): + sport = self.getSport(filename) + gpxfile = "%s/garmin-gpx-%d.gpx" % (self.tmpdir, len(importfiles)) + shutil + shutil.copy(filename, gpxfile) + importfiles.append((gpxfile, sport)) + else: + logging.debug("%s already in database. Skipping import." % (filename) ) + else: + logging.info("File %s failed validation" % (filename)) + logging.debug("<<") + return importfiles + + def valid_input_file(self, filename): + """ Function to validate input file if requested""" + if not self.validate: #not asked to validate + logging.debug("Not validating %s" % (filename) ) + return True + else: + #To validate GPX as used for pytrainer must test against both Topograpfix and Cluetrust + topografixXSLfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/Topografix_gpx11.xsd" + cluetrustXSLfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/Cluetrust_gpxdata10.xsd" + from lib.xmlValidation import xmlValidator + validator = xmlValidator() + return validator.validateXSL(filename, topografixXSLfile) and validator.validateXSL(filename, cluetrustXSLfile) + + def inDatabase(self, filename): + """ Function to determine if a given file has already been imported into the database + only compares date and start time (sport may have been changed in DB after import) + only valid for GPX files with a single activity + """ + time = self.detailsFromGPX(filename) + if self.parent.parent.ddbb.select("records","*","date_time_utc=\"%s\"" % (time)): + return True + else: + return False + + def getSport(self, filename): + #return sport from overide if present or default to "import" + if self.sport: + return self.sport + sport = "import" + return sport + + def detailsFromGPX(self, filename): + """ Function to return the first time element from a GPX 1.1 file """ + tree = xml.etree.cElementTree.ElementTree(file=filename) + root = tree.getroot() + timeElement = root.find(".//{http://www.topografix.com/GPX/1/1}time") + if timeElement is None: + return None + else: + return timeElement.text + + Deleted: pytrainer/trunk/plugins/garmin-hr/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr/conf.xml 2009-11-09 11:07:55 UTC (rev 383) @@ -1,10 +0,0 @@ -<?xml version="1.0" ?> -<pytrainer-plugin - name="Garmin via GPSBabel 1.3.5" - description="Import your records directly from your Garmin GPS device (e.g. Forerunner 205 or 305) using GPSBabel (version 1.3.5)" - plugincode="garminhr" - pluginbutton="Import from Garmin GPS device (via GPSBabel)" - executable="garminhr" -> -<conf-values variable="device" value="usb:"/> -</pytrainer-plugin> Copied: pytrainer/trunk/plugins/garmin-hr/conf.xml (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml) =================================================================== --- pytrainer/trunk/plugins/garmin-hr/conf.xml (rev 0) +++ pytrainer/trunk/plugins/garmin-hr/conf.xml 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<pytrainer-plugin + name="Garmin via GPSBabel 1.3.5" + description="Import your records directly from your Garmin GPS device (e.g. Forerunner 205 or 305) using GPSBabel (version 1.3.5)" + plugincode="garminhr" + pluginbutton="Import from Garmin GPS device (via GPSBabel)" + executable="garminhr" +> +<conf-values variable="device" value="usb:"/> +</pytrainer-plugin> Deleted: pytrainer/trunk/plugins/garmin-hr/garminhr.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr/garminhr.py 2009-11-09 11:07:55 UTC (rev 383) @@ -1,174 +0,0 @@ -#!/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 os, sys -import logging -from lxml import etree -from lib.xmlUtils import XMLParser - -import commands - -class garminhr(): - """ Plugin to import from a Garmin device using gpsbabel - Checks each activity to see if any entries are in the database with the same start time - Creates GPX files for each activity not in the database - - Note: using lxml see http://codespeak.net/lxml - """ - def __init__(self, parent = None, validate=False): - self.parent = parent - self.tmpdir = self.parent.conf.getValue("tmpdir") - self.data_path = os.path.dirname(__file__) - self.validate = validate - self.input_dev = self.getConfValue("device") - self.sport = self.getConfValue("Force_sport_to") - - def getConfValue(self, confVar): - info = XMLParser(self.data_path+"/conf.xml") - code = info.getValue("pytrainer-plugin","plugincode") - plugindir = self.parent.conf.getValue("plugindir") - if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): - value = None - else: - info = XMLParser(plugindir+"/"+code+"/conf.xml") - value = info.getValue("pytrainer-plugin",confVar) - return value - - def run(self): - logging.debug(">>") - importfiles = [] - if not self.checkGPSBabelVersion("1.3.5"): - #TODO Remove Zenity below - os.popen("zenity --error --text='Must be using version 1.3.5 of GPSBabel for this plugin'"); - elif self.garminDeviceExists(): - try: - gpsbabelOutputFile = "%s/file.gtrnctr" % (self.tmpdir) - #TODO Remove Zenity below - outgps = commands.getstatusoutput("gpsbabel -t -i garmin -f %s -o gtrnctr -F %s | zenity --progress --pulsate --text='Loading Data' auto-close" % (self.input_dev, gpsbabelOutputFile) ) - if outgps[0]==0: - if outgps[1] == "Found no Garmin USB devices.": # check localizations - print "GPSBabel found no Garmin USB devices" - pass - else: #gpsbabel worked - now process file... - if self.valid_input_file(gpsbabelOutputFile): - for (sport, tracks) in self.getTracks(gpsbabelOutputFile): - logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, gpsbabelOutputFile)) - count = 0 - for track in tracks: #can be multiple tracks - if self.shouldImport(track): - count += 1 - gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) - self.createGPXfile(gpxfile, track) - if self.sport: #Option to overide sport is set - importfiles.append((gpxfile, self.sport)) - else: #Use sport from file - importfiles.append((gpxfile, sport)) - logging.debug("Importing %d of %d tracks for sport %s" % (count, len(tracks), sport) ) - else: - logging.info("File %s failed validation" % (gpsbabelOutputFile)) - except Exception: - #TODO Remove Zenity below - os.popen("zenity --error --text='Can not handle Garmin device\nCheck your configuration\nCurrent usb port is set to:\t %s'" %self.input_dev); - print sys.exc_info()[0] - else: #No garmin device found - #TODO Remove Zenity below - os.popen("zenity --error --text='Can not handle Garmin device\nCheck your configuration\nCurrent usb port is set to:\t %s'" %self.input_dev); - logging.debug("<<") - return importfiles - - def checkGPSBabelVersion(self, validVersion): - result = commands.getstatusoutput('gpsbabel -V') - if result[0] == 0: - version = result[1].split() - try: - if version[2] == validVersion: - return True - else: - print "GPSBabel at version %s instead of expected version %s" % (version[2], validVersion) - except: - print "Unexpected result from gpsbabel -V" - return False - return False - - def garminDeviceExists(self): - try: - outmod = commands.getstatusoutput('/sbin/lsmod | grep garmin_gps') - if outmod[0]==256: #there is no garmin_gps module loaded - self.input_dev = "usb:" - return True - else: - return False - except: - return False - - def valid_input_file(self, filename): - """ Function to validate input file if requested""" - if not self.validate: #not asked to validate - logging.debug("Not validating %s" % (filename) ) - return True - else: #Validate TCXv1, note are validating against gpsbabels 'broken' result... - xslfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/GarminTrainingCenterDatabase_v1-gpsbabel.xsd" - from lib.xmlValidation import xmlValidator - validator = xmlValidator() - return validator.validateXSL(filename, xslfile) - - def getTracks(self, filename): - """ Function to return all the tracks in a Garmin Training Center v1 file - """ - sportsList = ("Running", "Biking", "Other", "MultiSport") - result = [] - tree = etree.ElementTree(file=filename) - root = tree.getroot() - for sport in sportsList: - try: - sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) - tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") - result.append((sport, tracks)) - except: - print "No entries for sport %s" % sport - return result - - def shouldImport(self, track): - """ Function determines whether a track should be imported or not - Currently using time only - """ - timeElement = track.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Time") - if timeElement is None: - #print (etree.tostring(track, pretty_print=True)) - logging.debug("Error no time found in track") - return False - else: - time = timeElement.text - #comparing date and start time (sport may have been changed in DB after import) - if self.parent.parent.ddbb.select("records","*","date_time_utc=\"%s\"" % (time)): - logging.debug("Not importing track for time %s" % (time)) - return False - else: - return True - - def createGPXfile(self, gpxfile, track): - """ Function to transform a Garmin Training Center v1 Track to a valid GPX+ file - """ - xslt_doc = etree.parse(self.data_path+"/translate.xsl") - transform = etree.XSLT(xslt_doc) - result_tree = transform(track) - result_tree.write(gpxfile, xml_declaration=True) - - - Copied: pytrainer/trunk/plugins/garmin-hr/garminhr.py (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py) =================================================================== --- pytrainer/trunk/plugins/garmin-hr/garminhr.py (rev 0) +++ pytrainer/trunk/plugins/garmin-hr/garminhr.py 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,174 @@ +#!/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 os, sys +import logging +from lxml import etree +from lib.xmlUtils import XMLParser + +import commands + +class garminhr(): + """ Plugin to import from a Garmin device using gpsbabel + Checks each activity to see if any entries are in the database with the same start time + Creates GPX files for each activity not in the database + + Note: using lxml see http://codespeak.net/lxml + """ + def __init__(self, parent = None, validate=False): + self.parent = parent + self.tmpdir = self.parent.conf.getValue("tmpdir") + self.data_path = os.path.dirname(__file__) + self.validate = validate + self.input_dev = self.getConfValue("device") + self.sport = self.getConfValue("Force_sport_to") + + def getConfValue(self, confVar): + info = XMLParser(self.data_path+"/conf.xml") + code = info.getValue("pytrainer-plugin","plugincode") + plugindir = self.parent.conf.getValue("plugindir") + if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): + value = None + else: + info = XMLParser(plugindir+"/"+code+"/conf.xml") + value = info.getValue("pytrainer-plugin",confVar) + return value + + def run(self): + logging.debug(">>") + importfiles = [] + if not self.checkGPSBabelVersion("1.3.5"): + #TODO Remove Zenity below + os.popen("zenity --error --text='Must be using version 1.3.5 of GPSBabel for this plugin'"); + elif self.garminDeviceExists(): + try: + gpsbabelOutputFile = "%s/file.gtrnctr" % (self.tmpdir) + #TODO Remove Zenity below + outgps = commands.getstatusoutput("gpsbabel -t -i garmin -f %s -o gtrnctr -F %s | zenity --progress --pulsate --text='Loading Data' auto-close" % (self.input_dev, gpsbabelOutputFile) ) + if outgps[0]==0: + if outgps[1] == "Found no Garmin USB devices.": # check localizations + print "GPSBabel found no Garmin USB devices" + pass + else: #gpsbabel worked - now process file... + if self.valid_input_file(gpsbabelOutputFile): + for (sport, tracks) in self.getTracks(gpsbabelOutputFile): + logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, gpsbabelOutputFile)) + count = 0 + for track in tracks: #can be multiple tracks + if self.shouldImport(track): + count += 1 + gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) + self.createGPXfile(gpxfile, track) + if self.sport: #Option to overide sport is set + importfiles.append((gpxfile, self.sport)) + else: #Use sport from file + importfiles.append((gpxfile, sport)) + logging.debug("Importing %d of %d tracks for sport %s" % (count, len(tracks), sport) ) + else: + logging.info("File %s failed validation" % (gpsbabelOutputFile)) + except Exception: + #TODO Remove Zenity below + os.popen("zenity --error --text='Can not handle Garmin device\nCheck your configuration\nCurrent usb port is set to:\t %s'" %self.input_dev); + print sys.exc_info()[0] + else: #No garmin device found + #TODO Remove Zenity below + os.popen("zenity --error --text='Can not handle Garmin device\nCheck your configuration\nCurrent usb port is set to:\t %s'" %self.input_dev); + logging.debug("<<") + return importfiles + + def checkGPSBabelVersion(self, validVersion): + result = commands.getstatusoutput('gpsbabel -V') + if result[0] == 0: + version = result[1].split() + try: + if version[2] == validVersion: + return True + else: + print "GPSBabel at version %s instead of expected version %s" % (version[2], validVersion) + except: + print "Unexpected result from gpsbabel -V" + return False + return False + + def garminDeviceExists(self): + try: + outmod = commands.getstatusoutput('/sbin/lsmod | grep garmin_gps') + if outmod[0]==256: #there is no garmin_gps module loaded + self.input_dev = "usb:" + return True + else: + return False + except: + return False + + def valid_input_file(self, filename): + """ Function to validate input file if requested""" + if not self.validate: #not asked to validate + logging.debug("Not validating %s" % (filename) ) + return True + else: #Validate TCXv1, note are validating against gpsbabels 'broken' result... + xslfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/GarminTrainingCenterDatabase_v1-gpsbabel.xsd" + from lib.xmlValidation import xmlValidator + validator = xmlValidator() + return validator.validateXSL(filename, xslfile) + + def getTracks(self, filename): + """ Function to return all the tracks in a Garmin Training Center v1 file + """ + sportsList = ("Running", "Biking", "Other", "MultiSport") + result = [] + tree = etree.ElementTree(file=filename) + root = tree.getroot() + for sport in sportsList: + try: + sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) + tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + result.append((sport, tracks)) + except: + print "No entries for sport %s" % sport + return result + + def shouldImport(self, track): + """ Function determines whether a track should be imported or not + Currently using time only + """ + timeElement = track.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Time") + if timeElement is None: + #print (etree.tostring(track, pretty_print=True)) + logging.debug("Error no time found in track") + return False + else: + time = timeElement.text + #comparing date and start time (sport may have been changed in DB after import) + if self.parent.parent.ddbb.select("records","*","date_time_utc=\"%s\"" % (time)): + logging.debug("Not importing track for time %s" % (time)) + return False + else: + return True + + def createGPXfile(self, gpxfile, track): + """ Function to transform a Garmin Training Center v1 Track to a valid GPX+ file + """ + xslt_doc = etree.parse(self.data_path+"/translate.xsl") + transform = etree.XSLT(xslt_doc) + result_tree = transform(track) + result_tree.write(gpxfile, xml_declaration=True) + + + Deleted: pytrainer/trunk/plugins/garmin-hr/pytrainer.style =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr/pytrainer.style 2009-11-09 11:07:55 UTC (rev 383) @@ -1,39 +0,0 @@ -# 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" Copied: pytrainer/trunk/plugins/garmin-hr/pytrainer.style (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style) =================================================================== --- pytrainer/trunk/plugins/garmin-hr/pytrainer.style (rev 0) +++ pytrainer/trunk/plugins/garmin-hr/pytrainer.style 2009-11-09 11:07:55 UTC (rev 383) @@ -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" Deleted: pytrainer/trunk/plugins/garmin-hr/translate.xsl =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/translate.xsl 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr/translate.xsl 2009-11-09 11:07:55 UTC (rev 383) @@ -1,53 +0,0 @@ -<?xml version="1.0"?> - -<!-- note defining a namespace for TrainingCenterDatabase as the translation does not seem to work with a default namespace --> -<xsl:stylesheet version="1.0" -xmlns:t="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1" -xmlns:xsl="http://www.w3.org/1999/XSL/Transform" -> -<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/> - -<!-- this is a bit of a messy way to get whitespace into the output - but it works --> -<xsl:variable name="newline"><xsl:text> -</xsl:text></xsl:variable> - -<xsl:template match="/"> - <gpx creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" - xmlns="http://www.topografix.com/GPX/1/1" - xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" > - - <xsl:value-of select="$newline"/> - <xsl:variable name="sport">"Run"</xsl:variable> - <xsl:variable name="time"><xsl:value-of select="t:Track/t:Trackpoint/t:Time"/></xsl:variable> - <xsl:variable name="name"><xsl:value-of select="$sport"/><xsl:value-of select="substring($time, 1,10)"/></xsl:variable> - <metadata><xsl:value-of select="$newline"/> - <name><xsl:value-of select="$name"/></name><xsl:value-of select="$newline"/> - <link href="http://sourceforge.net/projects/pytrainer"/><xsl:value-of select="$newline"/> - <time><xsl:value-of select="$time"/></time><xsl:value-of select="$newline"/> - </metadata><xsl:value-of select="$newline"/> - <trk><xsl:value-of select="$newline"/> - <xsl:for-each select="t:Track"> - <trkseg><xsl:value-of select="$newline"/> - <xsl:for-each select="t:Trackpoint"> - <!-- only output a trkpt if a position exists --> - <xsl:if test="t:Position"> - <xsl:variable name="lat"><xsl:value-of select="t:Position/t:LatitudeDegrees"/></xsl:variable> - <xsl:variable name="lon"><xsl:value-of select="t:Position/t:LongitudeDegrees"/></xsl:variable> - <trkpt lat="{$lat}" lon="{$lon}"><xsl:value-of select="$newline"/> - <ele><xsl:value-of select="t:AltitudeMeters"/></ele><xsl:value-of select="$newline"/> - <time><xsl:value-of select="t:Time"/></time><xsl:value-of select="$newline"/> - <xsl:if test="t:HeartRateBpm"> - <extensions><xsl:value-of select="$newline"/> - <gpxdata:hr><xsl:value-of select="t:HeartRateBpm"/></gpxdata:hr><xsl:value-of select="$newline"/> - </extensions><xsl:value-of select="$newline"/> - </xsl:if> - </trkpt><xsl:value-of select="$newline"/> - </xsl:if> - </xsl:for-each> - <xsl:value-of select="$newline"/> - </trkseg><xsl:value-of select="$newline"/> - </xsl:for-each> - </trk><xsl:value-of select="$newline"/> - </gpx><xsl:value-of select="$newline"/> -</xsl:template> -</xsl:stylesheet> Copied: pytrainer/trunk/plugins/garmin-hr/translate.xsl (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr/translate.xsl) =================================================================== --- pytrainer/trunk/plugins/garmin-hr/translate.xsl (rev 0) +++ pytrainer/trunk/plugins/garmin-hr/translate.xsl 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,53 @@ +<?xml version="1.0"?> + +<!-- note defining a namespace for TrainingCenterDatabase as the translation does not seem to work with a default namespace --> +<xsl:stylesheet version="1.0" +xmlns:t="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1" +xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +> +<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/> + +<!-- this is a bit of a messy way to get whitespace into the output - but it works --> +<xsl:variable name="newline"><xsl:text> +</xsl:text></xsl:variable> + +<xsl:template match="/"> + <gpx creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" + xmlns="http://www.topografix.com/GPX/1/1" + xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" > + + <xsl:value-of select="$newline"/> + <xsl:variable name="sport">"Run"</xsl:variable> + <xsl:variable name="time"><xsl:value-of select="t:Track/t:Trackpoint/t:Time"/></xsl:variable> + <xsl:variable name="name"><xsl:value-of select="$sport"/><xsl:value-of select="substring($time, 1,10)"/></xsl:variable> + <metadata><xsl:value-of select="$newline"/> + <name><xsl:value-of select="$name"/></name><xsl:value-of select="$newline"/> + <link href="http://sourceforge.net/projects/pytrainer"/><xsl:value-of select="$newline"/> + <time><xsl:value-of select="$time"/></time><xsl:value-of select="$newline"/> + </metadata><xsl:value-of select="$newline"/> + <trk><xsl:value-of select="$newline"/> + <xsl:for-each select="t:Track"> + <trkseg><xsl:value-of select="$newline"/> + <xsl:for-each select="t:Trackpoint"> + <!-- only output a trkpt if a position exists --> + <xsl:if test="t:Position"> + <xsl:variable name="lat"><xsl:value-of select="t:Position/t:LatitudeDegrees"/></xsl:variable> + <xsl:variable name="lon"><xsl:value-of select="t:Position/t:LongitudeDegrees"/></xsl:variable> + <trkpt lat="{$lat}" lon="{$lon}"><xsl:value-of select="$newline"/> + <ele><xsl:value-of select="t:AltitudeMeters"/></ele><xsl:value-of select="$newline"/> + <time><xsl:value-of select="t:Time"/></time><xsl:value-of select="$newline"/> + <xsl:if test="t:HeartRateBpm"> + <extensions><xsl:value-of select="$newline"/> + <gpxdata:hr><xsl:value-of select="t:HeartRateBpm"/></gpxdata:hr><xsl:value-of select="$newline"/> + </extensions><xsl:value-of select="$newline"/> + </xsl:if> + </trkpt><xsl:value-of select="$newline"/> + </xsl:if> + </xsl:for-each> + <xsl:value-of select="$newline"/> + </trkseg><xsl:value-of select="$newline"/> + </xsl:for-each> + </trk><xsl:value-of select="$newline"/> + </gpx><xsl:value-of select="$newline"/> +</xsl:template> +</xsl:stylesheet> Deleted: pytrainer/trunk/plugins/garmin-hr-file/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr-file/conf.xml 2009-11-09 11:07:55 UTC (rev 383) @@ -1,10 +0,0 @@ -<?xml version="1.0" ?> -<pytrainer-plugin - name="Garmin Training Center file (v1)" - description="Import records from a garmin gps device with heart rate support (from training center version 1 file)" - plugincode="garminhrfile" - pluginbutton="Import from file: Garmin Training Center (version 1)" - executable="garminhrfile" -> -<conf-values variable="Force_sport_to" value=""/> -</pytrainer-plugin> Copied: pytrainer/trunk/plugins/garmin-hr-file/conf.xml (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml) =================================================================== --- pytrainer/trunk/plugins/garmin-hr-file/conf.xml (rev 0) +++ pytrainer/trunk/plugins/garmin-hr-file/conf.xml 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,10 @@ +<?xml version="1.0" ?> +<pytrainer-plugin + name="Garmin Training Center file (v1)" + description="Import records from a garmin gps device with heart rate support (from training center version 1 file)" + plugincode="garminhrfile" + pluginbutton="Import from file: Garmin Training Center (version 1)" + executable="garminhrfile" +> +<conf-values variable="Force_sport_to" value=""/> +</pytrainer-plugin> Deleted: pytrainer/trunk/plugins/garmin-hr-file/garminhrfile.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr-file/garminhrfile.py 2009-11-09 11:07:55 UTC (rev 383) @@ -1,135 +0,0 @@ -#!/usr/bin/python -# -*- coding: iso-8859-1 -*- - -#Copyright (C) - -#Based on plugin by 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 os -import logging -from lxml import etree -from lib.xmlUtils import XMLParser - -from gui.dialogs import fileChooserDialog, guiFlush - - -class garminhrfile(): - """ Plugin to import from a Garmin Training Center (version 1) file (as outputed from gpsbabel) - Can have multiple activities in the file - Checks to each activity to see if any entries are in the database with the same start time - Creates GPX files for each activity not in the database - - Note: using lxml see http://codespeak.net/lxml - """ - def __init__(self, parent = None, validate=False): - self.parent = parent - self.tmpdir = self.parent.conf.getValue("tmpdir") - self.data_path = os.path.dirname(__file__) - self.validate = validate - self.sport = self.getConfValue("Force_sport_to") - - def getConfValue(self, confVar): - info = XMLParser(self.data_path+"/conf.xml") - code = info.getValue("pytrainer-plugin","plugincode") - plugindir = self.parent.conf.getValue("plugindir") - if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): - value = None - else: - info = XMLParser(plugindir+"/"+code+"/conf.xml") - value = info.getValue("pytrainer-plugin",confVar) - return value - - def run(self): - logging.debug(">>") - selectedFiles = fileChooserDialog(title="Choose a Garmin Training Center file to import").getFiles() - guiFlush() - importfiles = [] - if not selectedFiles: - return importfiles - for filename in selectedFiles: #could be multiple files selected - currently only single selection enabled - if self.valid_input_file(filename): - for (sport, tracks) in self.getTracks(filename): - logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, filename)) - count = 0 - for track in tracks: #can be multiple tracks - if self.shouldImport(track): - count += 1 - gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) - self.createGPXfile(gpxfile, track) - if self.sport: #Option to overide sport is set - importfiles.append((gpxfile, self.sport)) - else: #Use sport from file - importfiles.append((gpxfile, sport)) - logging.debug("Importing %d of %d tracks for sport %s" % (count, len(tracks), sport) ) - else: - logging.info("File %s failed validation" % (filename)) - logging.debug("<<") - return importfiles - - def valid_input_file(self, filename): - """ Function to validate input file if requested""" - if not self.validate: #not asked to validate - logging.debug("Not validating %s" % (filename) ) - return True - else: #Validate TCXv1, note are validating against gpsbabels 'broken' result... - xslfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/GarminTrainingCenterDatabase_v1-gpsbabel.xsd" - from lib.xmlValidation import xmlValidator - validator = xmlValidator() - return validator.validateXSL(filename, xslfile) - - def shouldImport(self, track): - """ Function determines whether a track should be imported or not - Currently using time only - """ - timeElement = track.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Time") - if timeElement is None: - #print (etree.tostring(track, pretty_print=True)) - logging.debug("Error no time found in track") - return False - else: - time = timeElement.text - #comparing date and start time (sport may have been changed in DB after import) - if self.parent.parent.ddbb.select("records","*","date_time_utc=\"%s\"" % (time)): - logging.debug("Not importing track for time %s" % (time)) - return False - else: - return True - - def getTracks(self, filename): - """ Function to return all the tracks in a Garmin Training Center v1 file - """ - sportsList = ("Running", "Biking", "Other", "MultiSport") - result = [] - tree = etree.ElementTree(file=filename) - root = tree.getroot() - for sport in sportsList: - try: - sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) - tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") - result.append((sport, tracks)) - except: - print "No entries for sport %s" % sport - return result - - def createGPXfile(self, gpxfile, track): - """ Function to transform a Garmin Training Center v1 Track to a valid GPX+ file - """ - xslt_doc = etree.parse(self.data_path+"/translate.xsl") - transform = etree.XSLT(xslt_doc) - result_tree = transform(track) - result_tree.write(gpxfile, xml_declaration=True) - Copied: pytrainer/trunk/plugins/garmin-hr-file/garminhrfile.py (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py) =================================================================== --- pytrainer/trunk/plugins/garmin-hr-file/garminhrfile.py (rev 0) +++ pytrainer/trunk/plugins/garmin-hr-file/garminhrfile.py 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,135 @@ +#!/usr/bin/python +# -*- coding: iso-8859-1 -*- + +#Copyright (C) + +#Based on plugin by 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 os +import logging +from lxml import etree +from lib.xmlUtils import XMLParser + +from gui.dialogs import fileChooserDialog, guiFlush + + +class garminhrfile(): + """ Plugin to import from a Garmin Training Center (version 1) file (as outputed from gpsbabel) + Can have multiple activities in the file + Checks to each activity to see if any entries are in the database with the same start time + Creates GPX files for each activity not in the database + + Note: using lxml see http://codespeak.net/lxml + """ + def __init__(self, parent = None, validate=False): + self.parent = parent + self.tmpdir = self.parent.conf.getValue("tmpdir") + self.data_path = os.path.dirname(__file__) + self.validate = validate + self.sport = self.getConfValue("Force_sport_to") + + def getConfValue(self, confVar): + info = XMLParser(self.data_path+"/conf.xml") + code = info.getValue("pytrainer-plugin","plugincode") + plugindir = self.parent.conf.getValue("plugindir") + if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): + value = None + else: + info = XMLParser(plugindir+"/"+code+"/conf.xml") + value = info.getValue("pytrainer-plugin",confVar) + return value + + def run(self): + logging.debug(">>") + selectedFiles = fileChooserDialog(title="Choose a Garmin Training Center file to import").getFiles() + guiFlush() + importfiles = [] + if not selectedFiles: + return importfiles + for filename in selectedFiles: #could be multiple files selected - currently only single selection enabled + if self.valid_input_file(filename): + for (sport, tracks) in self.getTracks(filename): + logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, filename)) + count = 0 + for track in tracks: #can be multiple tracks + if self.shouldImport(track): + count += 1 + gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) + self.createGPXfile(gpxfile, track) + if self.sport: #Option to overide sport is set + importfiles.append((gpxfile, self.sport)) + else: #Use sport from file + importfiles.append((gpxfile, sport)) + logging.debug("Importing %d of %d tracks for sport %s" % (count, len(tracks), sport) ) + else: + logging.info("File %s failed validation" % (filename)) + logging.debug("<<") + return importfiles + + def valid_input_file(self, filename): + """ Function to validate input file if requested""" + if not self.validate: #not asked to validate + logging.debug("Not validating %s" % (filename) ) + return True + else: #Validate TCXv1, note are validating against gpsbabels 'broken' result... + xslfile = os.path.realpath(self.parent.parent.data_path)+ "/schemas/GarminTrainingCenterDatabase_v1-gpsbabel.xsd" + from lib.xmlValidation import xmlValidator + validator = xmlValidator() + return validator.validateXSL(filename, xslfile) + + def shouldImport(self, track): + """ Function determines whether a track should be imported or not + Currently using time only + """ + timeElement = track.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Time") + if timeElement is None: + #print (etree.tostring(track, pretty_print=True)) + logging.debug("Error no time found in track") + return False + else: + time = timeElement.text + #comparing date and start time (sport may have been changed in DB after import) + if self.parent.parent.ddbb.select("records","*","date_time_utc=\"%s\"" % (time)): + logging.debug("Not importing track for time %s" % (time)) + return False + else: + return True + + def getTracks(self, filename): + """ Function to return all the tracks in a Garmin Training Center v1 file + """ + sportsList = ("Running", "Biking", "Other", "MultiSport") + result = [] + tree = etree.ElementTree(file=filename) + root = tree.getroot() + for sport in sportsList: + try: + sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) + tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + result.append((sport, tracks)) + except: + print "No entries for sport %s" % sport + return result + + def createGPXfile(self, gpxfile, track): + """ Function to transform a Garmin Training Center v1 Track to a valid GPX+ file + """ + xslt_doc = etree.parse(self.data_path+"/translate.xsl") + transform = etree.XSLT(xslt_doc) + result_tree = transform(track) + result_tree.write(gpxfile, xml_declaration=True) + Deleted: pytrainer/trunk/plugins/garmin-hr-file/pytrainer.style =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/pytrainer.style 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr-file/pytrainer.style 2009-11-09 11:07:55 UTC (rev 383) @@ -1,39 +0,0 @@ -# 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" Copied: pytrainer/trunk/plugins/garmin-hr-file/pytrainer.style (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr-file/pytrainer.style) =================================================================== --- pytrainer/trunk/plugins/garmin-hr-file/pytrainer.style (rev 0) +++ pytrainer/trunk/plugins/garmin-hr-file/pytrainer.style 2009-11-09 11:07:55 UTC (rev 383) @@ -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" Deleted: pytrainer/trunk/plugins/garmin-hr-file/translate.xsl =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/translate.xsl 2009-11-09 10:34:52 UTC (rev 382) +++ pytrainer/trunk/plugins/garmin-hr-file/translate.xsl 2009-11-09 11:07:55 UTC (rev 383) @@ -1,53 +0,0 @@ -<?xml version="1.0"?> - -<!-- note defining a namespace for TrainingCenterDatabase as the translation does not seem to work with a default namespace --> -<xsl:stylesheet version="1.0" -xmlns:t="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1" -xmlns:xsl="http://www.w3.org/1999/XSL/Transform" -> -<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/> - -<!-- this is a bit of a messy way to get whitespace into the output - but it works --> -<xsl:variable name="newline"><xsl:text> -</xsl:text></xsl:variable> - -<xsl:template match="/"> - <gpx creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" - xmlns="http://www.topografix.com/GPX/1/1" - xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" > - - <xsl:value-of select="$newline"/> - <xsl:variable name="sport">"Run"</xsl:variable> - <xsl:variable name="time"><xsl:value-of select="t:Track/t:Trackpoint/t:Time"/></xsl:variable> - <xsl:variable name="name"><xsl:value-of select="$sport"/><xsl:value-of select="substring($time, 1,10)"/></xsl:variable> - <metadata><xsl:value-of select="$newline"/> - <name><xsl:value-of select="$name"/></name><xsl:value-of select="$newline"/> - <link href="http://sourceforge.net/projects/pytrainer"/><xsl:value-of select="$newline"/> - <time><xsl:value-of select="$time"/></time><xsl:value-of select="$newline"/> - </metadata><xsl:value-of select="$newline"/> - <trk><xsl:value-of select="$newline"/> - <xsl:for-each select="t:Track"> - <trkseg><xsl:value-of select="$newline"/> - <xsl:for-each select="t:Trackpoint"> - <!-- only output a trkpt if a position exists --> - <xsl:if test="t:Position"> - <xsl:variable name="lat"><xsl:value-of select="t:Position/t:LatitudeDegrees"/></xsl:variable> - <xsl:variable name="lon"><xsl:value-of select="t:Position/t:LongitudeDegrees"/></xsl:variable> - <trkpt lat="{$lat}" lon="{$lon}"><xsl:value-of select="$newline"/> - <ele><xsl:value-of select="t:AltitudeMeters"/></ele><xsl:value-of select="$newline"/> - <time><xsl:value-of select="t:Time"/></time><xsl:value-of select="$newline"/> - <xsl:if test="t:HeartRateBpm"> - <extensions><xsl:value-of select="$newline"/> - <gpxdata:hr><xsl:value-of select="t:HeartRateBpm"/></gpxdata:hr><xsl:value-of select="$newline"/> - </extensions><xsl:value-of select="$newline"/> - </xsl:if> - </trkpt><xsl:value-of select="$newline"/> - </xsl:if> - </xsl:for-each> - <xsl:value-of select="$newline"/> - </trkseg><xsl:value-of select="$newline"/> - </xsl:for-each> - </trk><xsl:value-of select="$newline"/> - </gpx><xsl:value-of select="$newline"/> -</xsl:template> -</xsl:stylesheet> Copied: pytrainer/trunk/plugins/garmin-hr-file/translate.xsl (from rev 382, pytrainer/branches/plugins-v2/plugins/garmin-hr-file/translate.xsl) =================================================================== --- pytrainer/trunk/plugins/garmin-hr-file/translate.xsl (rev 0) +++ pytrainer/trunk/plugins/garmin-hr-file/translate.xsl 2009-11-09 11:07:55 UTC (rev 383) @@ -0,0 +1,53 @@ +<?xml version="1.0"?> + +<!-- note defining a namespace for TrainingCenterDatabase as the translation does not seem to work with a default namespace --> +<xsl:stylesheet version="1.0" +xmlns:t="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1" +xmlns:xsl="http://www.w3.org/1999/XSL/Transform" +> +<xsl:output method="xml" indent="yes" omit-xml-declaration="no"/> + +<!-- this is a bit of a messy way to get whitespace into the output - but it works --> +<xsl:variable name="newline"><xsl:text> +</xsl:text></xsl:variable> + +<xsl:template match="/"> + <gpx creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" + xmlns="http://www.topografix.com/GPX/1/1" + xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" > + + <xsl:value-of select="$newline"/> + <xsl:variable name="sport">"Run"</xsl:variable> + <xsl:variable name="time"><xsl:value-of select="t:Track/t:Trackpoint/t:Time"/></xsl:variable> + <xsl:variable name="name"><xsl:value-of select="$sport"/><xsl:value-of select="substring($time, 1,10)"/></xsl:variable> + <metadata><xsl:value-of select="$newline"/> + <name><xsl:value-of select="$name"/></name><xsl:value-of select="$newli... [truncated message content] |
From: <jb...@us...> - 2009-11-09 10:35:01
|
Revision: 382 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=382&view=rev Author: jblance Date: 2009-11-09 10:34:52 +0000 (Mon, 09 Nov 2009) Log Message: ----------- Removed Paths: ------------- pytrainer/trunk/plugins/garmin-hr/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-09 10:33:10
|
Revision: 381 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=381&view=rev Author: jblance Date: 2009-11-09 10:33:03 +0000 (Mon, 09 Nov 2009) Log Message: ----------- Removed Paths: ------------- pytrainer/trunk/plugins/garmin-hr/conf.xml Deleted: pytrainer/trunk/plugins/garmin-hr/conf.xml =================================================================== --- pytrainer/trunk/plugins/garmin-hr/conf.xml 2009-11-09 09:46:38 UTC (rev 380) +++ pytrainer/trunk/plugins/garmin-hr/conf.xml 2009-11-09 10:33:03 UTC (rev 381) @@ -1,10 +0,0 @@ -<?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> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-09 09:46:55
|
Revision: 380 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=380&view=rev Author: jblance Date: 2009-11-09 09:46:38 +0000 (Mon, 09 Nov 2009) Log Message: ----------- cleanup mergeinfo Property Changed: ---------------- pytrainer/branches/plugins-v2/ pytrainer/branches/plugins-v2/plugins/garmin-gpx/ pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style pytrainer/branches/plugins-v2/plugins/garmin-hr-file/ Property changes on: pytrainer/branches/plugins-v2 ___________________________________________________________________ Modified: svn:mergeinfo - /pytrainer/trunk:345-378 + /pytrainer/trunk:345-379 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-gpx ___________________________________________________________________ Deleted: svn:mergeinfo - /pytrainer/trunk/plugins/garmingpx:345-347 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py ___________________________________________________________________ Deleted: svn:mergeinfo - /orig/pytrainer/trunk/plugins/garmin-gpx/garmingpx.py:5-244 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml ___________________________________________________________________ Deleted: svn:mergeinfo - /orig/pytrainer/trunk/plugins/garmin-hr/conf.xml:5-134 /pytrainer/trunk/plugins/garmin-hr/conf.xml:359-378 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style ___________________________________________________________________ Deleted: svn:mergeinfo - /orig/pytrainer/trunk/plugins/garmin-hr/pytrainer.style:5-134 /pytrainer/trunk/plugins/garmin-hr/pytrainer.style:359-378 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr-file ___________________________________________________________________ Deleted: svn:mergeinfo - /pytrainer/trunk/plugins/garmin-hr:345-347 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-09 09:27:57
|
Revision: 379 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=379&view=rev Author: jblance Date: 2009-11-09 09:27:51 +0000 (Mon, 09 Nov 2009) Log Message: ----------- Merge trunk changes to plugins-v2 branch Added Paths: ----------- pytrainer/branches/plugins-v2/plugins/googleearth/main.sh Removed Paths: ------------- pytrainer/branches/plugins-v2/plugins/googleearth/main.sh Property Changed: ---------------- pytrainer/branches/plugins-v2/ pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style Property changes on: pytrainer/branches/plugins-v2 ___________________________________________________________________ Modified: svn:mergeinfo - /pytrainer/trunk:345-347 + /pytrainer/trunk:345-378 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py ___________________________________________________________________ Modified: svn:mergeinfo - + /orig/pytrainer/trunk/plugins/garmin-gpx/garmingpx.py:5-244 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml ___________________________________________________________________ Modified: svn:mergeinfo - + /orig/pytrainer/trunk/plugins/garmin-hr/conf.xml:5-134 /pytrainer/trunk/plugins/garmin-hr/conf.xml:359-378 Property changes on: pytrainer/branches/plugins-v2/plugins/garmin-hr/pytrainer.style ___________________________________________________________________ Modified: svn:mergeinfo - + /orig/pytrainer/trunk/plugins/garmin-hr/pytrainer.style:5-134 /pytrainer/trunk/plugins/garmin-hr/pytrainer.style:359-378 Deleted: pytrainer/branches/plugins-v2/plugins/googleearth/main.sh =================================================================== --- pytrainer/branches/plugins-v2/plugins/googleearth/main.sh 2009-11-08 06:20:13 UTC (rev 378) +++ pytrainer/branches/plugins-v2/plugins/googleearth/main.sh 2009-11-09 09:27:51 UTC (rev 379) @@ -1,26 +0,0 @@ -#!/bin/sh -# -*- 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. - - -var=`zenity --file-selection` - -tmpgpx="/tmp/reg.gpx" -gpsbabel -t -i kml -f $var -o gpx -F $tmpgpx - -echo $tmpgpx Copied: pytrainer/branches/plugins-v2/plugins/googleearth/main.sh (from rev 378, pytrainer/trunk/plugins/googleearth/main.sh) =================================================================== --- pytrainer/branches/plugins-v2/plugins/googleearth/main.sh (rev 0) +++ pytrainer/branches/plugins-v2/plugins/googleearth/main.sh 2009-11-09 09:27:51 UTC (rev 379) @@ -0,0 +1,26 @@ +#!/bin/sh +# -*- 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. + + +var=`zenity --file-selection` + +tmpgpx="/tmp/reg.gpx" +gpsbabel -t -i kml -f $var -o gpx -F $tmpgpx + +echo $tmpgpx This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-11-08 06:20:24
|
Revision: 378 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=378&view=rev Author: jblance Date: 2009-11-08 06:20:13 +0000 (Sun, 08 Nov 2009) Log Message: ----------- Updated plugins setup to include new/changed plugins Modified Paths: -------------- pytrainer/branches/plugins-v2/setup.py Modified: pytrainer/branches/plugins-v2/setup.py =================================================================== --- pytrainer/branches/plugins-v2/setup.py 2009-10-29 04:57:47 UTC (rev 377) +++ pytrainer/branches/plugins-v2/setup.py 2009-11-08 06:20:13 UTC (rev 378) @@ -31,10 +31,11 @@ ('share/pytrainer/glade/',glob("glade/*.png")), ('share/pytrainer/glade/',glob("glade/*.jpg")), ('share/pytrainer/',glob("*.style")), - install_plugin("garmingpx"), + install_plugin("garmin-gpx"), install_plugin("garmin-hr"), + install_plugin("garmin-hr-file"), + install_plugin("garmin-tcxv2"), install_plugin("googleearth"), - install_plugin("ipod"), install_extension("wordpress"), (install_locale("es")), (install_locale("ca")), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-29 04:57:57
|
Revision: 377 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=377&view=rev Author: jblance Date: 2009-10-29 04:57:47 +0000 (Thu, 29 Oct 2009) Log Message: ----------- Fix to display correct sport if sports have been deleted Modified Paths: -------------- pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py pytrainer/branches/plugins-v2/pytrainer/profile.py Modified: pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py 2009-10-29 04:12:30 UTC (rev 376) +++ pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py 2009-10-29 04:57:47 UTC (rev 377) @@ -48,11 +48,9 @@ "rcd_maxpace", "rcd_maxvel" ] - count = 0 self.listSport = {} for i in listSport: - self.listSport[count] = i[0] - count = count+1 + self.listSport[i[3]] = i[0] #Create dictionary using SportID as key (may be non sequential if sports have been deleted) for i in self.listSport: self.rcd_sport.insert_text(i,self.listSport[i]) self.rcd_sport.set_active(0) @@ -153,12 +151,26 @@ self.setValue("rcd_pace",values[15]) self.setValue("rcd_maxbeats",values[16]) self.rcd_title.set_text("%s"%values[10]) - self.rcd_sport.set_active(int(values[2])-1) #TODO Fix - This does not work if a sport has been deleted... + sportID = values[2] + sportPosition = self.getSportPosition(sportID) + self.rcd_sport.set_active(sportPosition) buffer = self.rcd_comments.get_buffer() start,end = buffer.get_bounds() buffer.set_text(values[8]) self.mode = "editrecord" + def getSportPosition(self, sportID): + """ + Function to determin the position in the sport array for a given sport ID + Needed as once sports are deleted there are gaps in the list... + """ + count = 0 + for key, value in self.listSport.iteritems(): + if key == sportID: + return count + count +=1 + return 0 + def on_calctime_clicked(self,widget): try: distance = self.rcd_distance.get_text() Modified: pytrainer/branches/plugins-v2/pytrainer/profile.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/profile.py 2009-10-29 04:12:30 UTC (rev 376) +++ pytrainer/branches/plugins-v2/pytrainer/profile.py 2009-10-29 04:57:47 UTC (rev 377) @@ -130,7 +130,7 @@ connection = self.ddbb.connect() if (connection == 1): logging.debug("retrieving sports info") - return self.ddbb.select("sports","name,met,weight",None) + return self.ddbb.select("sports","name,met,weight,id_sports",None) else: return connection This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-29 04:12:41
|
Revision: 376 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=376&view=rev Author: jblance Date: 2009-10-29 04:12:30 +0000 (Thu, 29 Oct 2009) Log Message: ----------- Fix approach to getting sport from tcxv1 files Modified Paths: -------------- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-28 07:45:10 UTC (rev 375) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-29 04:12:30 UTC (rev 376) @@ -67,19 +67,19 @@ pass else: #gpsbabel worked - now process file... if self.valid_input_file(gpsbabelOutputFile): - sportsList = ("Running", "Biking", "Other", "MultiSport") # valid sports in training center v1 files - for sport in sportsList: - tracks = self.getTracks(gpsbabelOutputFile, sport) + for (sport, tracks) in self.getTracks(gpsbabelOutputFile): logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, gpsbabelOutputFile)) + count = 0 for track in tracks: #can be multiple tracks if self.shouldImport(track): + count += 1 gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) self.createGPXfile(gpxfile, track) if self.sport: #Option to overide sport is set importfiles.append((gpxfile, self.sport)) else: #Use sport from file importfiles.append((gpxfile, sport)) - logging.debug("Importing %s of %s tracks for sport %s" % (len(importfiles), len(tracks), sport) ) + logging.debug("Importing %d of %d tracks for sport %s" % (count, len(tracks), sport) ) else: logging.info("File %s failed validation" % (gpsbabelOutputFile)) except Exception: @@ -128,18 +128,21 @@ validator = xmlValidator() return validator.validateXSL(filename, xslfile) - def getTracks(self, filename, sport): + def getTracks(self, filename): """ Function to return all the tracks in a Garmin Training Center v1 file """ + sportsList = ("Running", "Biking", "Other", "MultiSport") + result = [] tree = etree.ElementTree(file=filename) root = tree.getroot() - try: - sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) - tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") - except: - print "No entries for sport %s" % sport - return [] - return tracks + for sport in sportsList: + try: + sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) + tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + result.append((sport, tracks)) + except: + print "No entries for sport %s" % sport + return result def shouldImport(self, track): """ Function determines whether a track should be imported or not Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-28 07:45:10 UTC (rev 375) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-29 04:12:30 UTC (rev 376) @@ -62,19 +62,19 @@ return importfiles for filename in selectedFiles: #could be multiple files selected - currently only single selection enabled if self.valid_input_file(filename): - sportsList = ("Running", "Biking", "Other", "MultiSport") # valid sports in training center v1 files - for sport in sportsList: - tracks = self.getTracks(filename, sport) + for (sport, tracks) in self.getTracks(filename): logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, filename)) + count = 0 for track in tracks: #can be multiple tracks if self.shouldImport(track): + count += 1 gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) self.createGPXfile(gpxfile, track) if self.sport: #Option to overide sport is set importfiles.append((gpxfile, self.sport)) else: #Use sport from file importfiles.append((gpxfile, sport)) - logging.debug("Importing %s of %s tracks for sport %s" % (len(importfiles), len(tracks), sport) ) + logging.debug("Importing %d of %d tracks for sport %s" % (count, len(tracks), sport) ) else: logging.info("File %s failed validation" % (filename)) logging.debug("<<") @@ -109,18 +109,21 @@ else: return True - def getTracks(self, filename, sport): + def getTracks(self, filename): """ Function to return all the tracks in a Garmin Training Center v1 file """ + sportsList = ("Running", "Biking", "Other", "MultiSport") + result = [] tree = etree.ElementTree(file=filename) root = tree.getroot() - try: - sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) - tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") - except: - print "No entries for sport %s" % sport - return [] - return tracks + for sport in sportsList: + try: + sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) + tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + result.append((sport, tracks)) + except: + print "No entries for sport %s" % sport + return result def createGPXfile(self, gpxfile, track): """ Function to transform a Garmin Training Center v1 Track to a valid GPX+ file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-28 07:45:23
|
Revision: 375 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=375&view=rev Author: jblance Date: 2009-10-28 07:45:10 +0000 (Wed, 28 Oct 2009) Log Message: ----------- Read sport from v1 garmin files Modified Paths: -------------- pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml Modified: pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml 2009-10-28 07:10:37 UTC (rev 374) +++ pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml 2009-10-28 07:45:10 UTC (rev 375) @@ -1,9 +1,9 @@ <?xml version="1.0" ?> <pytrainer-plugin - name="GarminGPX" + name="Garmin GPX file" description="Import your records directly from a garmin gpx file." plugincode="garmingpx" - pluginbutton="Import from Garmin GPX file" + pluginbutton="Import from file: Garmin GPX" executable="garmingpx" > <conf-values variable="Force_sport_to" value=""/> Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-28 07:10:37 UTC (rev 374) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-28 07:45:10 UTC (rev 375) @@ -67,15 +67,19 @@ pass else: #gpsbabel worked - now process file... if self.valid_input_file(gpsbabelOutputFile): - tracks = self.getTracks(gpsbabelOutputFile) - logging.debug("Found %d tracks in %s" % (len(tracks), gpsbabelOutputFile)) - for track in tracks: #can be multiple tracks - if self.shouldImport(track): - sport = self.getSport(track) #TODO need to fix this logic.... - gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) - self.createGPXfile(gpxfile, track) - importfiles.append((gpxfile, sport)) - logging.debug("Importing %s of %s tracks" % (len(importfiles), len(tracks)) ) + sportsList = ("Running", "Biking", "Other", "MultiSport") # valid sports in training center v1 files + for sport in sportsList: + tracks = self.getTracks(gpsbabelOutputFile, sport) + logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, gpsbabelOutputFile)) + for track in tracks: #can be multiple tracks + if self.shouldImport(track): + gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) + self.createGPXfile(gpxfile, track) + if self.sport: #Option to overide sport is set + importfiles.append((gpxfile, self.sport)) + else: #Use sport from file + importfiles.append((gpxfile, sport)) + logging.debug("Importing %s of %s tracks for sport %s" % (len(importfiles), len(tracks), sport) ) else: logging.info("File %s failed validation" % (gpsbabelOutputFile)) except Exception: @@ -124,12 +128,17 @@ validator = xmlValidator() return validator.validateXSL(filename, xslfile) - def getTracks(self, filename): + def getTracks(self, filename, sport): """ Function to return all the tracks in a Garmin Training Center v1 file """ tree = etree.ElementTree(file=filename) root = tree.getroot() - tracks = root.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + try: + sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) + tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + except: + print "No entries for sport %s" % sport + return [] return tracks def shouldImport(self, track): @@ -150,13 +159,6 @@ else: return True - def getSport(self, track): - #TODO return sport - if self.sport: - return self.sport - else: - return "import" - def createGPXfile(self, gpxfile, track): """ Function to transform a Garmin Training Center v1 Track to a valid GPX+ file """ Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml 2009-10-28 07:10:37 UTC (rev 374) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml 2009-10-28 07:45:10 UTC (rev 375) @@ -1,9 +1,9 @@ <?xml version="1.0" ?> <pytrainer-plugin - name="Garmin training center file import (version 1)" + name="Garmin Training Center file (v1)" description="Import records from a garmin gps device with heart rate support (from training center version 1 file)" plugincode="garminhrfile" - pluginbutton="Import from Garmin training center file (version 1)" + pluginbutton="Import from file: Garmin Training Center (version 1)" executable="garminhrfile" > <conf-values variable="Force_sport_to" value=""/> Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-28 07:10:37 UTC (rev 374) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-28 07:45:10 UTC (rev 375) @@ -62,15 +62,19 @@ return importfiles for filename in selectedFiles: #could be multiple files selected - currently only single selection enabled if self.valid_input_file(filename): - tracks = self.getTracks(filename) - logging.debug("Found %d tracks in %s" % (len(tracks), filename)) - for track in tracks: #can be multiple tracks - if self.shouldImport(track): - sport = self.getSport(track) #TODO need to fix this logic.... - gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) - self.createGPXfile(gpxfile, track) - importfiles.append((gpxfile, sport)) - logging.debug("Importing %s of %s tracks" % (len(importfiles), len(tracks)) ) + sportsList = ("Running", "Biking", "Other", "MultiSport") # valid sports in training center v1 files + for sport in sportsList: + tracks = self.getTracks(filename, sport) + logging.debug("Found %d tracks for %s sport in %s" % (len(tracks), sport, filename)) + for track in tracks: #can be multiple tracks + if self.shouldImport(track): + gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) + self.createGPXfile(gpxfile, track) + if self.sport: #Option to overide sport is set + importfiles.append((gpxfile, self.sport)) + else: #Use sport from file + importfiles.append((gpxfile, sport)) + logging.debug("Importing %s of %s tracks for sport %s" % (len(importfiles), len(tracks), sport) ) else: logging.info("File %s failed validation" % (filename)) logging.debug("<<") @@ -105,19 +109,17 @@ else: return True - def getSport(self, track): - #TODO return sport - if self.sport: - return self.sport - else: - return "import" - - def getTracks(self, filename): + def getTracks(self, filename, sport): """ Function to return all the tracks in a Garmin Training Center v1 file """ tree = etree.ElementTree(file=filename) root = tree.getroot() - tracks = root.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + try: + sportLevel = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}%s" % sport) + tracks = sportLevel.findall(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v1}Track") + except: + print "No entries for sport %s" % sport + return [] return tracks def createGPXfile(self, gpxfile, track): Modified: pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml 2009-10-28 07:10:37 UTC (rev 374) +++ pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml 2009-10-28 07:45:10 UTC (rev 375) @@ -1,9 +1,9 @@ <?xml version="1.0" ?> <pytrainer-plugin - name="Garmin v2 TCX" - description="Import your records from a version 2 TCX file from a Garmin gps device (i.e. Forerunner 405)" + name="Garmin Training Center file (v2)" + description="Import your records from a Garmin Training Center version 2 file (.tcx) e.g. from a Garmin gps device (i.e. Forerunner 405)" plugincode="garminTCXv2" - pluginbutton="Import from Garmin TCX file (version 2)" + pluginbutton="Import from file: Garmin Training Center (version 2)" executable="garmin-tcxv2" > <conf-values variable="Force_sport_to" value=""/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-28 07:10:49
|
Revision: 374 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=374&view=rev Author: jblance Date: 2009-10-28 07:10:37 +0000 (Wed, 28 Oct 2009) Log Message: ----------- Note to fix editrecord Modified Paths: -------------- pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py Modified: pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py 2009-10-22 09:18:04 UTC (rev 373) +++ pytrainer/branches/plugins-v2/pytrainer/gui/windowrecord.py 2009-10-28 07:10:37 UTC (rev 374) @@ -153,7 +153,7 @@ self.setValue("rcd_pace",values[15]) self.setValue("rcd_maxbeats",values[16]) self.rcd_title.set_text("%s"%values[10]) - self.rcd_sport.set_active(int(values[2])-1) + self.rcd_sport.set_active(int(values[2])-1) #TODO Fix - This does not work if a sport has been deleted... buffer = self.rcd_comments.get_buffer() start,end = buffer.get_bounds() buffer.set_text(values[8]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-22 09:18:16
|
Revision: 373 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=373&view=rev Author: jblance Date: 2009-10-22 09:18:04 +0000 (Thu, 22 Oct 2009) Log Message: ----------- Added some support for determining sport on import to plugins branch Modified Paths: -------------- pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py pytrainer/branches/plugins-v2/pytrainer/lib/xmlUtils.py pytrainer/branches/plugins-v2/pytrainer/main.py pytrainer/branches/plugins-v2/pytrainer/record.py Modified: pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/plugins/garmin-gpx/conf.xml 2009-10-22 09:18:04 UTC (rev 373) @@ -6,5 +6,5 @@ pluginbutton="Import from Garmin GPX file" executable="garmingpx" > -<!--<conf-values variable="device" value="/dev/ttyUSB0"/>--> +<conf-values variable="Force_sport_to" value=""/> </pytrainer-plugin> Modified: pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/plugins/garmin-gpx/garmingpx.py 2009-10-22 09:18:04 UTC (rev 373) @@ -20,8 +20,10 @@ import logging import os +import shutil from gui.dialogs import fileChooserDialog, guiFlush import xml.etree.cElementTree +from lib.xmlUtils import XMLParser class garmingpx(): """ Plugin to import from a GPX file or files @@ -32,16 +34,35 @@ self.parent = parent self.tmpdir = self.parent.conf.getValue("tmpdir") self.validate = validate + self.data_path = os.path.dirname(__file__) + self.sport = self.getConfValue("Force_sport_to") + def getConfValue(self, confVar): + info = XMLParser(self.data_path+"/conf.xml") + code = info.getValue("pytrainer-plugin","plugincode") + plugindir = self.parent.conf.getValue("plugindir") + if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): + value = None + else: + info = XMLParser(plugindir+"/"+code+"/conf.xml") + value = info.getValue("pytrainer-plugin",confVar) + return value + def run(self): logging.debug(">>") selectedFiles = fileChooserDialog(title="Choose a GPX file (or files) to import", multiple=True).getFiles() guiFlush() importfiles = [] + if not selectedFiles: + return importfiles for filename in selectedFiles: if self.valid_input_file(filename): if not self.inDatabase(filename): - importfiles.append(filename) + sport = self.getSport(filename) + gpxfile = "%s/garmin-gpx-%d.gpx" % (self.tmpdir, len(importfiles)) + shutil + shutil.copy(filename, gpxfile) + importfiles.append((gpxfile, sport)) else: logging.debug("%s already in database. Skipping import." % (filename) ) else: @@ -73,6 +94,13 @@ else: return False + def getSport(self, filename): + #return sport from overide if present or default to "import" + if self.sport: + return self.sport + sport = "import" + return sport + def detailsFromGPX(self, filename): """ Function to return the first time element from a GPX 1.1 file """ tree = xml.etree.cElementTree.ElementTree(file=filename) Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-22 09:18:04 UTC (rev 373) @@ -36,8 +36,20 @@ self.tmpdir = self.parent.conf.getValue("tmpdir") self.data_path = os.path.dirname(__file__) self.validate = validate - self.input_dev = None + self.input_dev = self.getConfValue("device") + self.sport = self.getConfValue("Force_sport_to") + def getConfValue(self, confVar): + info = XMLParser(self.data_path+"/conf.xml") + code = info.getValue("pytrainer-plugin","plugincode") + plugindir = self.parent.conf.getValue("plugindir") + if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): + value = None + else: + info = XMLParser(plugindir+"/"+code+"/conf.xml") + value = info.getValue("pytrainer-plugin",confVar) + return value + def run(self): logging.debug(">>") importfiles = [] @@ -59,9 +71,10 @@ logging.debug("Found %d tracks in %s" % (len(tracks), gpsbabelOutputFile)) for track in tracks: #can be multiple tracks if self.shouldImport(track): + sport = self.getSport(track) #TODO need to fix this logic.... gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) self.createGPXfile(gpxfile, track) - importfiles.append(gpxfile) + importfiles.append((gpxfile, sport)) logging.debug("Importing %s of %s tracks" % (len(importfiles), len(tracks)) ) else: logging.info("File %s failed validation" % (gpsbabelOutputFile)) @@ -90,11 +103,6 @@ return False def garminDeviceExists(self): - info = XMLParser(self.data_path+"/conf.xml") - prefs = info.getAllValues("conf-values") - for (variable, value) in prefs: - if variable == "device": - self.input_dev = value try: outmod = commands.getstatusoutput('/sbin/lsmod | grep garmin_gps') if outmod[0]==256: #there is no garmin_gps module loaded @@ -142,6 +150,13 @@ else: return True + def getSport(self, track): + #TODO return sport + if self.sport: + return self.sport + else: + return "import" + def createGPXfile(self, gpxfile, track): """ Function to transform a Garmin Training Center v1 Track to a valid GPX+ file """ Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/conf.xml 2009-10-22 09:18:04 UTC (rev 373) @@ -1,9 +1,10 @@ <?xml version="1.0" ?> <pytrainer-plugin - name="Garmin Import with HR (from TCXv1file)" - description="Import records from a garmin gps device with heart rate support (from TCXv1 file)" + name="Garmin training center file import (version 1)" + description="Import records from a garmin gps device with heart rate support (from training center version 1 file)" plugincode="garminhrfile" - pluginbutton="Import from Garmin file (HR support)" + pluginbutton="Import from Garmin training center file (version 1)" executable="garminhrfile" > +<conf-values variable="Force_sport_to" value=""/> </pytrainer-plugin> Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-22 09:18:04 UTC (rev 373) @@ -22,6 +22,7 @@ import os import logging from lxml import etree +from lib.xmlUtils import XMLParser from gui.dialogs import fileChooserDialog, guiFlush @@ -39,7 +40,19 @@ self.tmpdir = self.parent.conf.getValue("tmpdir") self.data_path = os.path.dirname(__file__) self.validate = validate + self.sport = self.getConfValue("Force_sport_to") + def getConfValue(self, confVar): + info = XMLParser(self.data_path+"/conf.xml") + code = info.getValue("pytrainer-plugin","plugincode") + plugindir = self.parent.conf.getValue("plugindir") + if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): + value = None + else: + info = XMLParser(plugindir+"/"+code+"/conf.xml") + value = info.getValue("pytrainer-plugin",confVar) + return value + def run(self): logging.debug(">>") selectedFiles = fileChooserDialog(title="Choose a Garmin Training Center file to import").getFiles() @@ -53,9 +66,10 @@ logging.debug("Found %d tracks in %s" % (len(tracks), filename)) for track in tracks: #can be multiple tracks if self.shouldImport(track): + sport = self.getSport(track) #TODO need to fix this logic.... gpxfile = "%s/garminhrfile%d.gpx" % (self.tmpdir, len(importfiles)) self.createGPXfile(gpxfile, track) - importfiles.append(gpxfile) + importfiles.append((gpxfile, sport)) logging.debug("Importing %s of %s tracks" % (len(importfiles), len(tracks)) ) else: logging.info("File %s failed validation" % (filename)) @@ -91,6 +105,13 @@ else: return True + def getSport(self, track): + #TODO return sport + if self.sport: + return self.sport + else: + return "import" + def getTracks(self, filename): """ Function to return all the tracks in a Garmin Training Center v1 file """ Modified: pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/conf.xml 2009-10-22 09:18:04 UTC (rev 373) @@ -6,4 +6,5 @@ pluginbutton="Import from Garmin TCX file (version 2)" executable="garmin-tcxv2" > +<conf-values variable="Force_sport_to" value=""/> </pytrainer-plugin> Modified: pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py 2009-10-22 09:18:04 UTC (rev 373) @@ -20,6 +20,7 @@ import logging import os from lxml import etree +from lib.xmlUtils import XMLParser from gui.dialogs import fileChooserDialog, guiFlush @@ -29,7 +30,19 @@ self.tmpdir = self.parent.conf.getValue("tmpdir") self.data_path = os.path.dirname(__file__) self.validate = validate + self.sport = self.getConfValue("Force_sport_to") + def getConfValue(self, confVar): + info = XMLParser(self.data_path+"/conf.xml") + code = info.getValue("pytrainer-plugin","plugincode") + plugindir = self.parent.conf.getValue("plugindir") + if not os.path.isfile(plugindir+"/"+code+"/conf.xml"): + value = None + else: + info = XMLParser(plugindir+"/"+code+"/conf.xml") + value = info.getValue("pytrainer-plugin",confVar) + return value + def run(self): logging.debug(">>") # able to select multiple files.... @@ -41,9 +54,10 @@ for filename in selectedFiles: if self.valid_input_file(filename): if not self.inDatabase(filename): + sport = self.getSport(filename) gpxfile = "%s/garmin-tcxv2-%d.gpx" % (self.tmpdir, len(importfiles)) self.createGPXfile(gpxfile, filename) - importfiles.append(gpxfile) + importfiles.append((gpxfile, sport)) else: logging.debug("%s already in database. Skipping import." % (filename,) ) else: @@ -70,6 +84,19 @@ else: return False + def getSport(self, filename): + #return sport from file or overide if present + if self.sport: + return self.sport + tree = etree.ElementTree(file=filename) + root = tree.getroot() + sportElement = root.find(".//{http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2}Activity") + try: + sport = sportElement.get("Sport") + except: + sport = "import" + return sport + def detailsFromTCX(self, filename): tree = etree.ElementTree(file=filename) root = tree.getroot() Modified: pytrainer/branches/plugins-v2/pytrainer/lib/xmlUtils.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/lib/xmlUtils.py 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/pytrainer/lib/xmlUtils.py 2009-10-22 09:18:04 UTC (rev 373) @@ -75,8 +75,11 @@ def getValue(self,tagname,variable): self._load() - root = self.xmldoc.getElementsByTagName(tagname)[0] - value = root.attributes[variable].value + try: + root = self.xmldoc.getElementsByTagName(tagname)[0] + value = root.attributes[variable].value + except KeyError: + value = "" return value def getAllValues(self,tagname): Modified: pytrainer/branches/plugins-v2/pytrainer/main.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/main.py 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/pytrainer/main.py 2009-10-22 09:18:04 UTC (rev 373) @@ -172,14 +172,14 @@ def runPlugin(self,widget,pathPlugin): logging.debug('>>') self.pluginClass = self.plugins.importClass(pathPlugin) - pluginFiles = self.pluginClass.run() + pluginFiles = self.pluginClass.run() if pluginFiles is not None: - logging.debug("Plugin returned " +str(len(pluginFiles)) + " files: " +','.join(pluginFiles) ) + logging.debug("Plugin returned %d files" % (len(pluginFiles)) ) #process returned GPX files - for pluginFile in pluginFiles: + for (pluginFile, sport) in pluginFiles: if os.path.isfile(pluginFile): - logging.info('File exists. Size: '+ str(os.path.getsize(pluginFile))) - self.record.importFromGPX(pluginFile) + logging.info('File exists. Size: %d. Sport: %s' % (os.path.getsize(pluginFile), sport)) + self.record.importFromGPX(pluginFile, sport) else: logging.error('File '+pluginFile+' not valid') else: Modified: pytrainer/branches/plugins-v2/pytrainer/record.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/record.py 2009-10-21 09:50:08 UTC (rev 372) +++ pytrainer/branches/plugins-v2/pytrainer/record.py 2009-10-22 09:18:04 UTC (rev 373) @@ -411,14 +411,15 @@ self.recordwindow.run() logging.debug('<<') - def importFromGPX(self, gpxFile): + def importFromGPX(self, gpxFile, sport): """ Add a record from a valid pytrainer type GPX file """ logging.debug('>>') logging.info('Retrieving data from '+gpxFile) - #create an entry, defaulting sport to 'import' - in future could get actual sport from gpxFile.... - entry = ["import",""] + if not sport: + sport = "import" + entry = [sport,""] entry_id = self.insertNewRecord(gpxFile, entry) if entry_id is None: logging.error("Entry not created for file %s" % gpxFile) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-21 09:50:17
|
Revision: 372 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=372&view=rev Author: jblance Date: 2009-10-21 09:50:08 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Fix for XML declaration in GPX files Modified Paths: -------------- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-21 09:22:52 UTC (rev 371) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-21 09:50:08 UTC (rev 372) @@ -148,7 +148,7 @@ xslt_doc = etree.parse(self.data_path+"/translate.xsl") transform = etree.XSLT(xslt_doc) result_tree = transform(track) - result_tree.write(gpxfile) + result_tree.write(gpxfile, xml_declaration=True) Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-21 09:22:52 UTC (rev 371) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/garminhrfile.py 2009-10-21 09:50:08 UTC (rev 372) @@ -105,5 +105,5 @@ xslt_doc = etree.parse(self.data_path+"/translate.xsl") transform = etree.XSLT(xslt_doc) result_tree = transform(track) - result_tree.write(gpxfile) + result_tree.write(gpxfile, xml_declaration=True) Modified: pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py 2009-10-21 09:22:52 UTC (rev 371) +++ pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/garmin-tcxv2.py 2009-10-21 09:50:08 UTC (rev 372) @@ -86,5 +86,5 @@ transform = etree.XSLT(xslt_doc) xml_doc = etree.parse(filename) result_tree = transform(xml_doc) - result_tree.write(gpxfile) + result_tree.write(gpxfile, xml_declaration=True) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-21 09:22:59
|
Revision: 371 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=371&view=rev Author: jblance Date: 2009-10-21 09:22:52 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Added GPSBabel version check to plugin (in plugins-v2 branch) Modified Paths: -------------- pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml 2009-10-21 07:40:17 UTC (rev 370) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/conf.xml 2009-10-21 09:22:52 UTC (rev 371) @@ -1,9 +1,9 @@ <?xml version="1.0" ?> <pytrainer-plugin - name="Garmin Heart Rate" - description="Import yor records direclty from your garmin gps device with heart rate support" + name="Garmin via GPSBabel 1.3.5" + description="Import your records directly from your Garmin GPS device (e.g. Forerunner 205 or 305) using GPSBabel (version 1.3.5)" plugincode="garminhr" - pluginbutton="Import from Garmin (HR support)" + pluginbutton="Import from Garmin GPS device (via GPSBabel)" executable="garminhr" > <conf-values variable="device" value="usb:"/> Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-21 07:40:17 UTC (rev 370) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/garminhr.py 2009-10-21 09:22:52 UTC (rev 371) @@ -20,6 +20,7 @@ import os, sys import logging from lxml import etree +from lib.xmlUtils import XMLParser import commands @@ -40,10 +41,12 @@ def run(self): logging.debug(">>") importfiles = [] - if self.garminDeviceExists(): + if not self.checkGPSBabelVersion("1.3.5"): + #TODO Remove Zenity below + os.popen("zenity --error --text='Must be using version 1.3.5 of GPSBabel for this plugin'"); + elif self.garminDeviceExists(): try: gpsbabelOutputFile = "%s/file.gtrnctr" % (self.tmpdir) - testInputFile = "/home/johnb/garmin/2009.07.26\ 143201.TCX" #TODO Remove Zenity below outgps = commands.getstatusoutput("gpsbabel -t -i garmin -f %s -o gtrnctr -F %s | zenity --progress --pulsate --text='Loading Data' auto-close" % (self.input_dev, gpsbabelOutputFile) ) if outgps[0]==0: @@ -72,8 +75,26 @@ logging.debug("<<") return importfiles + def checkGPSBabelVersion(self, validVersion): + result = commands.getstatusoutput('gpsbabel -V') + if result[0] == 0: + version = result[1].split() + try: + if version[2] == validVersion: + return True + else: + print "GPSBabel at version %s instead of expected version %s" % (version[2], validVersion) + except: + print "Unexpected result from gpsbabel -V" + return False + return False def garminDeviceExists(self): + info = XMLParser(self.data_path+"/conf.xml") + prefs = info.getAllValues("conf-values") + for (variable, value) in prefs: + if variable == "device": + self.input_dev = value try: outmod = commands.getstatusoutput('/sbin/lsmod | grep garmin_gps') if outmod[0]==256: #there is no garmin_gps module loaded This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-21 07:40:27
|
Revision: 370 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=370&view=rev Author: jblance Date: 2009-10-21 07:40:17 +0000 (Wed, 21 Oct 2009) Log Message: ----------- Fix to schema defns for xslt in plugin branch Modified Paths: -------------- pytrainer/branches/plugins-v2/plugins/garmin-hr/translate.xsl pytrainer/branches/plugins-v2/plugins/garmin-hr-file/translate.xsl pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/translate.xsl Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr/translate.xsl =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr/translate.xsl 2009-10-19 10:19:03 UTC (rev 369) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr/translate.xsl 2009-10-21 07:40:17 UTC (rev 370) @@ -12,14 +12,9 @@ </xsl:text></xsl:variable> <xsl:template match="/"> - <gpx xmlns="http://www.topografix.com/GPX/1/1" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" - creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" - 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"> + <gpx creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" + xmlns="http://www.topografix.com/GPX/1/1" + xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" > <xsl:value-of select="$newline"/> <xsl:variable name="sport">"Run"</xsl:variable> Modified: pytrainer/branches/plugins-v2/plugins/garmin-hr-file/translate.xsl =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-hr-file/translate.xsl 2009-10-19 10:19:03 UTC (rev 369) +++ pytrainer/branches/plugins-v2/plugins/garmin-hr-file/translate.xsl 2009-10-21 07:40:17 UTC (rev 370) @@ -12,14 +12,9 @@ </xsl:text></xsl:variable> <xsl:template match="/"> - <gpx xmlns="http://www.topografix.com/GPX/1/1" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" - creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" - 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"> + <gpx creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" + xmlns="http://www.topografix.com/GPX/1/1" + xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" > <xsl:value-of select="$newline"/> <xsl:variable name="sport">"Run"</xsl:variable> Modified: pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/translate.xsl =================================================================== --- pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/translate.xsl 2009-10-19 10:19:03 UTC (rev 369) +++ pytrainer/branches/plugins-v2/plugins/garmin-tcxv2/translate.xsl 2009-10-21 07:40:17 UTC (rev 370) @@ -12,14 +12,9 @@ </xsl:text></xsl:variable> <xsl:template match="/"> - <gpx xmlns="http://www.topografix.com/GPX/1/1" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" - creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" - 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"> + <gpx creator="pytrainer http://sourceforge.net/projects/pytrainer" version="1.1" + xmlns="http://www.topografix.com/GPX/1/1" + xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" > <xsl:value-of select="$newline"/> <xsl:variable name="sport"><xsl:value-of select="t:TrainingCenterDatabase/t:Activities/t:Activity/@Sport"/></xsl:variable> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jb...@us...> - 2009-10-19 10:19:13
|
Revision: 369 http://pytrainer.svn.sourceforge.net/pytrainer/?rev=369&view=rev Author: jblance Date: 2009-10-19 10:19:03 +0000 (Mon, 19 Oct 2009) Log Message: ----------- Updated record code to deal with time=0 files without erroring - in plugins-v2 branch Modified Paths: -------------- pytrainer/branches/plugins-v2/pytrainer/record.py Modified: pytrainer/branches/plugins-v2/pytrainer/record.py =================================================================== --- pytrainer/branches/plugins-v2/pytrainer/record.py 2009-10-19 09:41:47 UTC (rev 368) +++ pytrainer/branches/plugins-v2/pytrainer/record.py 2009-10-19 10:19:03 UTC (rev 369) @@ -146,6 +146,8 @@ def insertRecord(self, list_options): logging.debug('>>') + if list_options is None: + return None logging.debug('list_options: '+str(list_options)) cells,values = self._formatRecordNew(list_options) self.ddbb.insert("records",cells,values) @@ -155,7 +157,7 @@ gpxDest = self.conf.getValue("gpxdir") id_record = self.ddbb.lastRecord("records") gpxNew = gpxDest+"/%d.gpx"%id_record - shutil.copy2(gpxOrig, gpxNew) + shutil.move(gpxOrig, gpxNew) logging.debug('Moving '+gpxOrig+' to '+gpxNew) #self.parent.refreshListRecords() logging.debug('<<') @@ -176,6 +178,8 @@ logging.debug('>>') gpx = Gpx(self.data_path,gpxOrig) distance, time, maxspeed, maxheartrate = gpx.getMaxValues() + if time == 0: #invalid record + return None upositive,unegative = gpx.getUnevenness() speed = distance*3600/time time_hhmmss = [time//3600,(time/60)%60,time%60] @@ -416,7 +420,10 @@ #create an entry, defaulting sport to 'import' - in future could get actual sport from gpxFile.... entry = ["import",""] entry_id = self.insertNewRecord(gpxFile, entry) - logging.info('Entry '+str(entry_id)+' has been added') + if entry_id is None: + logging.error("Entry not created for file %s" % gpxFile) + else: + logging.info("Entry %d has been added" % entry_id) logging.debug('<<') #def importFromGTRNCTR(self,gtrnctrFile): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |