Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Some corrections to pace display and calculation as suggested by Arnd

  • Loading branch information...
commit 3326bc8016e33a9b6487f7989acc65c3efe059bc 1 parent 271880b
@jblance jblance authored
View
9 pytrainer/activitypool.py
@@ -43,7 +43,14 @@ def clear_pool(self):
self.pool = {}
self.pool_queue = []
logging.debug("<<")
-
+
+ def remove_activity(self, id):
+ sid = str(id)
+ if sid in self.pool.keys():
+ logging.debug("Found activity in pool")
+ self.pool_queue.remove(sid)
+ del self.pool[sid]
+
def get_activity(self, id):
sid = str(id)
if sid in self.pool.keys():
View
43 pytrainer/gui/windowmain.py
@@ -28,6 +28,7 @@
from popupmenu import PopupMenu
from aboutdialog import About
+from pytrainer.record import Record
from pytrainer.lib.date import Date
from pytrainer.lib.xmlUtils import XMLParser
#from pytrainer.lib.gpx import Gpx
@@ -244,8 +245,8 @@ def actualize_recordview(self,activity):
self.record_unegative.set_text("%0.2f" %activity.unegative)
self.record_average.set_text("%0.2f" %activity.average)
self.record_maxspeed.set_text("%0.2f" %activity.maxspeed)
- self.record_pace.set_text("%0.2f" %activity.pace)
- self.record_maxpace.set_text("%0.2f" %activity.maxpace)
+ self.record_pace.set_text(Record().pace_from_float(activity.pace))
+ self.record_maxpace.set_text(Record().pace_from_float(activity.maxpace))
self.record_sport.set_text(activity.sport_name)
#self.record_date.set_text(str(date))
@@ -344,8 +345,8 @@ def actualize_dayview(self,record_list):
maxbeats = 0
maxspeed = 0
average = 0
- maxpace = "0.00"
- pace = "0.00"
+ maxpace = "0:00"
+ pace = "0:00"
for record in record_list:
distance += self.parseFloat(record[2])
calories += self.parseFloat(record[7])
@@ -367,9 +368,9 @@ def actualize_dayview(self,record_list):
if distance > 0:
average = distance/(timeinseconds/60/60)
if maxspeed > 0:
- maxpace = "%d.%02d" %((3600/maxspeed)/60,(3600/maxspeed)%60)
+ maxpace = "%d:%02d" %((3600/maxspeed)/60,(3600/maxspeed)%60)
if average > 0:
- pace = "%d.%02d" %((3600/average)/60,(3600/average)%60)
+ pace = "%d:%02d" %((3600/average)/60,(3600/average)%60)
self.dayview.set_sensitive(1)
self.day_distance.set_text("%0.2f" %distance)
@@ -381,15 +382,15 @@ def actualize_dayview(self,record_list):
self.day_maxbeats.set_text("%0.2f" %maxbeats)
self.day_average.set_text("%0.2f" %average)
self.day_maxspeed.set_text("%0.2f" %maxspeed)
- self.day_pace.set_text(pace)
- self.day_maxpace.set_text(maxpace)
+ self.day_pace.set_text("%s" %pace)
+ self.day_maxpace.set_text("%s" %maxpace)
self.day_calories.set_text("%0.0f" %calories)
self.day_topic.set_text(str(record[1]))
else:
self.dayview.set_sensitive(0)
logging.debug("<<")
-
+
def actualize_daygraph(self,record_list):
logging.debug(">>")
if len(record_list)>0:
@@ -435,8 +436,8 @@ def actualize_weekview(self, record_list, date_ini, date_end):
time_in_min = 0
tbeats = 0
maxspeed = 0
- pace = "0.00"
- maxpace = "0.00"
+ pace = "0:00"
+ maxpace = "0:00"
maxbeats = 0
if self.pytrainer_main.profile.getValue("pytraining","prf_us_system") == "True":
@@ -482,10 +483,10 @@ def actualize_weekview(self, record_list, date_ini, date_end):
if maxspeed > 0:
#maxpace = 60/maxspeed
- maxpace = "%d.%02d" %((3600/maxspeed)/60,(3600/maxspeed)%60)
+ maxpace = "%d:%02d" %((3600/maxspeed)/60,(3600/maxspeed)%60)
if average > 0:
#pace = 60/average
- pace = "%d.%02d" %((3600/average)/60,(3600/average)%60)
+ pace = "%d:%02d" %((3600/average)/60,(3600/average)%60)
self.weeka_distance.set_text("%0.2f" %km)
hour,min,sec = self.parent.date.second2time(time)
@@ -513,8 +514,8 @@ def actualize_monthview(self,record_list, nameMonth):
time_in_min = 0
tbeats = 0
maxspeed = 0
- pace = "0.00"
- maxpace = "0.00"
+ pace = "0:00"
+ maxpace = "0:00"
maxbeats = 0
if self.pytrainer_main.profile.getValue("pytraining","prf_us_system") == "True":
@@ -560,10 +561,10 @@ def actualize_monthview(self,record_list, nameMonth):
if maxspeed > 0:
#maxpace = 60/maxspeed
- maxpace = "%d.%02d" %((3600/maxspeed)/60,(3600/maxspeed)%60)
+ maxpace = "%d:%02d" %((3600/maxspeed)/60,float(3600/maxspeed)%60)
if average > 0:
#pace = 60/average
- pace = "%d.%02d" %((3600/average)/60,(3600/average)%60)
+ pace = "%d:%02d" %((3600/average)/60,float(3600/average)%60)
self.montha_distance.set_text("%0.2f" %km)
hour,min,sec = self.parent.date.second2time(time)
@@ -595,8 +596,8 @@ def actualize_yearview(self,record_list, year):
time_in_min = 0
tbeats = 0
maxspeed = 0
- pace = "0.00"
- maxpace = "0.00"
+ pace = "0:00"
+ maxpace = "0:00"
maxbeats = 0
if num_records>0:
for record in record_list:
@@ -623,10 +624,10 @@ def actualize_yearview(self,record_list, year):
if maxspeed > 0:
#maxpace = 60/maxspeed
- maxpace = "%d.%02d" %((3600/maxspeed)/60,(3600/maxspeed)%60)
+ maxpace = "%d:%02d" %((3600/maxspeed)/60,(3600/maxspeed)%60)
if average > 0:
#pace = 60/average
- pace = "%d.%02d" %((3600/average)/60,(3600/average)%60)
+ pace = "%d:%02d" %((3600/average)/60,(3600/average)%60)
self.yeara_distance.set_text("%0.2f" %km)
hour,min,sec = self.parent.date.second2time(time)
View
11 pytrainer/gui/windowrecord.py
@@ -21,6 +21,7 @@
import gtk, gobject
from SimpleGladeApp import SimpleGladeApp
from windowcalendar import WindowCalendar
+
from filechooser import FileChooser
from pytrainer.lib.date import Date
import dateutil.parser
@@ -504,8 +505,16 @@ def on_calcpace_clicked(self,widget):
distance = float(self.rcd_distance.get_text())
if distance<1:
return False
+ #Calc Pace
average = time_in_min/distance
- self.rcd_pace.set_text("%0.2f" %average)
+ #Tranform pace to mm.ss
+ min = int(average)
+ per_min = average - min
+ sec = float(per_min) * 60 / 100
+ dec_pace = min + sec
+ #Transform pace to mm:ss
+ pace = self.parent.pace_from_float(dec_pace)
+ self.rcd_pace.set_text(pace)
def on_calccalories_clicked(self,widget):
sport = self.rcd_sport.get_active_text()
View
2  pytrainer/main.py
@@ -49,7 +49,7 @@
class pyTrainer:
def __init__(self,filename = None, data_path = None):
#Version constants
- self.version ="1.7.2_svn#611"
+ self.version ="1.7.2_svn#612"
self.DB_version = 3
#Process command line options
self.startup_options = self.get_options()
View
30 pytrainer/record.py
@@ -107,11 +107,29 @@ def _formatRecord (self, list_options):
self.parseFloatRecord(list_options["rcd_unegative"]),
self.parseFloatRecord(list_options["rcd_maxvel"]),
self.parseFloatRecord(list_options["rcd_maxpace"]),
- self.parseFloatRecord(list_options["rcd_pace"]),
- self.parseFloatRecord(list_options["rcd_maxbeats"])
+ self.pace_to_float(list_options["rcd_pace"]),
+ self.pace_to_float(list_options["rcd_maxbeats"])
)
logging.debug('<<')
return cells,values
+
+ def pace_to_float(self, value):
+ '''Take a mm:ss or mm.ss and return float'''
+ value = value.replace(':', '.')
+ try:
+ value = float(value)
+ except ValueError:
+ value = None
+ return value
+
+ def pace_from_float(self, value):
+ '''Helper to generate mm:ss from float representation mm.ss (or mm,ss?)'''
+ #Check that value supplied is a float
+ try:
+ _value = "%0.2f" % float(value)
+ except ValueError:
+ _value = str(value)
+ return _value.replace('.',':')
def _formatRecordNew (self, list_options):
"""20.07.2008 - dgranda
@@ -141,8 +159,8 @@ def _formatRecordNew (self, list_options):
self.parseFloatRecord(list_options["rcd_upositive"]),
self.parseFloatRecord(list_options["rcd_unegative"]),
self.parseFloatRecord(list_options["rcd_maxvel"]),
- self.parseFloatRecord(list_options["rcd_maxpace"]),
- self.parseFloatRecord(list_options["rcd_pace"]),
+ self.pace_to_float(list_options["rcd_maxpace"]),
+ self.pace_to_float(list_options["rcd_pace"]),
self.parseFloatRecord(list_options["rcd_maxbeats"]),
list_options["date_time_utc"],
list_options["date_time_local"],
@@ -263,6 +281,8 @@ def summaryFromGPX(self, gpxOrig, entry):
def updateRecord(self, list_options, id_record):
logging.debug('>>')
+ #Remove activity from pool so data is updated
+ self.pytrainer_main.activitypool.remove_activity(id_record)
gpxfile = self.pytrainer_main.profile.gpxdir+"/%d.gpx"%int(id_record)
gpxOrig = list_options["rcd_gpxfile"]
if os.path.isfile(gpxOrig):
@@ -274,7 +294,7 @@ def updateRecord(self, list_options, id_record):
logging.debug('updating bbdd') #ein?
cells,values = self._formatRecord(list_options)
self.pytrainer_main.ddbb.update("records",cells,values," id_record=%d" %int(id_record))
- self.parent.refreshListView()
+ self.pytrainer_main.refreshListView()
logging.debug('<<')
def parseFloatRecord(self,string):
Please sign in to comment.
Something went wrong with that request. Please try again.