class HeartRateGraph: def __init__(self, vbox = None, window = None, vbox2 = None, pytrainer_main = None): logging.debug('>>') self.drawarea = DrawArea(vbox, window) self.drawarea2 = DrawArea(vbox2, window) self.pytrainer_main = pytrainer_main logging.debug('<<') def drawgraph(self,values): logging.debug('>>') zones = self.pytrainer_main.profile.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]) logging.debug('<<') return xvalue,yvalue def getFloatValue(self, value): try: return float(value) except: return float(0)
def __init__(self, vbox=None, window=None, vbox2=None, pytrainer_main=None): logging.debug('>>') self.drawarea = DrawArea(vbox, window) self.drawarea2 = DrawArea(vbox2, window) self.pytrainer_main = pytrainer_main logging.debug('<<')
def __init__(self, vbox=None, window=None, combovalue=None, combovalue2=None, btnShowLaps=None, tableConfig=None, pytrainer_main=None): logging.debug(">>") self.pytrainer_main = pytrainer_main self.drawarea = DrawArea(vbox, window) self.combovalue = combovalue self.combovalue2 = combovalue2 self.showLaps = btnShowLaps self.config_table = tableConfig logging.debug("<<")
def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None, btnShowLaps = None, tableConfig = None, pytrainer_main=None): logging.debug(">>") self.pytrainer_main = pytrainer_main self.drawarea = DrawArea(vbox, window) self.combovalue = combovalue self.combovalue2 = combovalue2 self.showLaps = btnShowLaps self.config_table = tableConfig logging.debug("<<")
class HeartRateGraph: def __init__(self, vbox=None, window=None, vbox2=None, pytrainer_main=None): logging.debug('>>') self.drawarea = DrawArea(vbox, window) self.drawarea2 = DrawArea(vbox2, window) self.pytrainer_main = pytrainer_main logging.debug('<<') def drawgraph(self, values): logging.debug('>>') zones = self.pytrainer_main.profile.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]) logging.debug('<<') return xvalue, yvalue def getFloatValue(self, value): try: return float(value) except: return float(0)
class RecordGraph: def __init__(self, vbox=None, window=None, combovalue=None, combovalue2=None, btnShowLaps=None, tableConfig=None, pytrainer_main=None): logging.debug(">>") self.pytrainer_main = pytrainer_main self.drawarea = DrawArea(vbox, window) self.combovalue = combovalue self.combovalue2 = combovalue2 self.showLaps = btnShowLaps self.config_table = tableConfig logging.debug("<<") def drawgraph(self, values, laps=None, y1limits=None, y1color=None, y1_linewidth=1): logging.debug(">>") #Get the config options for child in self.config_table.get_children(): if child.get_name() == "spinbuttonY1Max": spinbuttonY1Max = child elif child.get_name() == "spinbuttonY1Min": spinbuttonY1Min = child elif child.get_name() == "colorbuttonY1LineColor": colorbuttonY1LineColor = child elif child.get_name() == "spinbuttonY1LineWeight": spinbuttonY1LineWeight = child xval = [] yval = [] xlab = [] ylab = [] tit = [] col = [] value_selected = self.combovalue.get_active() logging.debug("Value selected 1: " + str(value_selected)) value_selected2 = self.combovalue2.get_active() logging.debug("Value selected 2: " + str(value_selected2)) showLaps = self.showLaps.get_active() logging.debug("Show laps: " + str(showLaps)) #Determine left and right lap boundaries if laps is not None and showLaps: lapValues = [] lastPoint = 0.0 for lap in laps: thisPoint = float(lap['distance']) / 1000.0 + lastPoint lapValues.append((lastPoint, thisPoint)) lastPoint = thisPoint else: lapValues = None if value_selected < 0: self.combovalue.set_active(0) value_selected = 0 if value_selected2 < 0: self.combovalue2.set_active(0) value_selected2 = 0 xvalues, yvalues = self.get_values(values, value_selected) max_yvalue = max(yvalues) min_yvalue = min(yvalues) xlabel, ylabel, title, color = self.get_value_params(value_selected) if y1color is not None: _color = gtk.gdk.Color(y1color) color = y1color else: _color = gtk.gdk.Color(color) xval.append(xvalues) yval.append(yvalues) if value_selected2 > 0: xlab.append("") else: xlab.append(xlabel) ylab.append(ylabel) tit.append(title) col.append(color) #_color = gtk.gdk.Color(color) colorbuttonY1LineColor.set_color(_color) if value_selected2 > 0: value_selected2 = value_selected2 - 1 xlabel, ylabel, title, color = self.get_value_params( value_selected2) xvalues, yvalues = self.get_values(values, value_selected2) max_yvalue = max(max(yvalues), max_yvalue) min_yvalue = min(min(yvalues), min_yvalue) xval.append(xvalues) yval.append(yvalues) xlab.append(xlabel) ylab.append(ylabel) tit.append("") col.append(color) logging.info("To show: tit: " + str(tit) + " | col: " + str(col) + " | xlab: " + str(xlab) + " | ylab: " + str(ylab)) #self.drawPlot(xvalues,yvalues,xlabel,ylabel,title,color,zones) plot_stats = self.drawarea.drawPlot(xval, yval, xlab, ylab, tit, col, None, lapValues, ylimits=y1limits, y1_linewidth=y1_linewidth) ymin = plot_stats['y1_min'] ymax = plot_stats['y1_max'] y1_linewidth = plot_stats['y1_linewidth'] max_yvalue = max(max_yvalue, ymax) min_yvalue = min(min_yvalue, ymin) adjY1Min = gtk.Adjustment(value=ymin, lower=min_yvalue, upper=max_yvalue, step_incr=1, page_incr=10) adjY1Max = gtk.Adjustment(value=ymax, lower=min_yvalue, upper=max_yvalue, step_incr=1, page_incr=10) spinbuttonY1Min.set_adjustment(adjY1Min) spinbuttonY1Max.set_adjustment(adjY1Max) spinbuttonY1Min.set_value(ymin) spinbuttonY1Max.set_value(ymax) spinbuttonY1LineWeight.set_value(y1_linewidth) logging.debug("<<") def get_value_params(self, value): if value == 0: return _("Distance (km)"), _("Height (m)"), _( "Stage Profile"), "#000000" if value == 1: return _("Distance (km)"), _("Speed (Km/h)"), _("Speed"), "#00ff00" if value == 2: return _("Distance (km)"), _("Pace (min/km)"), _("Pace"), "#0000ff" if value == 3: return _("Distance (km)"), _("Beats (bpm)"), _( "Heart Rate"), "#ff0000" if value == 4: return _("Distance (km)"), _("Cadence (rpm)"), _( "Cadence"), "#7B3F00" if value == 5: return _("Distance (km)"), _("Beats (%)"), _("Beats"), "#ff0000" if value == 6: return _("Distance (km)"), _("Zone"), _("Zone"), "#ff0000" def get_values(self, values, value_selected): logging.debug(">>") xvalue = [] yvalue = [] zones = self.pytrainer_main.profile.getZones() for value in values: xvalue.append(value[0]) if value_selected == 0: yvalue.append(value[1]) if value_selected == 1: yvalue.append(value[3]) if value_selected == 2: try: yvalue.append(60 / value[3]) except: yvalue.append(0) if value_selected == 3: yvalue.append(value[6]) if value_selected == 4: yvalue.append(value[7]) if value_selected == 5: if value[6] <= zones[4][0]: yvalue.append(50.0 * value[6] / zones[4][0]) else: yvalue.append(50.0 + 50.0 * ((value[6] - zones[4][0]) / (zones[0][1] - zones[4][0]))) if value_selected == 6: if value[6] <= zones[4][0]: yvalue.append(1.0 * value[6] / zones[4][0]) else: yvalue.append(1.0 + 5.0 * ((value[6] - zones[4][0]) / (zones[0][1] - zones[4][0]))) logging.debug("<<") return xvalue, yvalue def getFloatValue(self, value): try: return float(value) except: return float(0)
def __init__(self, sports, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None): self.drawarea = DrawArea(vbox, window) self.SPORT_FIELD = 9 self.sport_colors = dict([(sport.name, sport.color.to_hex_string()) for sport in sports])
class TimeGraph(object): def __init__(self, sports, vbox = None, window = None, combovalue = None, combovalue2 = None, main = None): self.drawarea = DrawArea(vbox, window) self.SPORT_FIELD = 9 self.sport_colors = dict([(sport.name, sport.color.to_hex_string()) for sport in sports]) def getFloatValue(self, value): try: return float(value) except: return float(0) def getValue(self,record,value_selected): #hacemos una relacion entre el value_selected y los values / we make a relation between value_selected and the values conv = { 0: 1, #value 0 es kilometros (1) 1: 2, #value 1 es tiempo (2) 2: 3, #value 2 es pulsaciones(3) 3: 5, #value 3 es media(5) 4: 6 #value 4 es calorias(6) } value_sel = conv[value_selected] #si la opcion es tiempo lo pasamos a horas / if the option is time we passed it to hours if (value_sel == 2): return self.getFloatValue(record[value_sel])/3600 else: return self.getFloatValue(record[value_sel]) def get_values(self, values, value_selected, key_format, sportfield=9): valueDict = {} #Stores the totals valueCount = {} #Counts the totals to allow for averaging if needed sportColors = {} for record in values: if record[0]: day = unicode(datetime.datetime.strptime(record[0], "%Y-%m-%d").strftime(key_format)) # Gives year for this record sport = record[sportfield] value = self.getValue(record, value_selected) if sport in valueDict: #Already got this sport if day in valueDict[sport]: #Already got this sport on this day valueDict[sport][day] += value valueCount[sport][day] += 1 else: #New day for this sport valueDict[sport][day] = value valueCount[sport][day] = 1 else: #New sport valueDict[sport] = {day: value} valueCount[sport] = {day: 1} else: logging.debug("No date string found, skipping entry: " + str(record)) if value_selected in (2, 3): total = {} count = {} for sport in valueDict.keys(): for day in valueDict[sport].keys(): if valueCount[sport][day] > 1: #Only average if 2 or more entries on this day valueDict[sport][day] /= valueCount[sport][day] if value_selected == 1: #Values are of time type valuesAreTime=True else: valuesAreTime=False return valueDict, valuesAreTime def drawgraph(self,values, extra=None, x_func=None): xval = [] yval = [] xlab = [] ylab = [] tit = [] valsAreTime = [] value_selected = self.combovalue.get_active() value_selected2 = self.combovalue2.get_active() if value_selected < 0: self.combovalue.set_active(0) value_selected = 0 y1,ylabel,title,y2 = self.get_value_params(value_selected) ylab.append(ylabel) tit.append(title) yvalues, valuesAreTime = self.get_values(values,value_selected, self.KEY_FORMAT, sportfield=self.SPORT_FIELD) if not len(values): return xvalues = x_func(yvalues) yval.append(yvalues) xlab.append(xvalues) valsAreTime.append(valuesAreTime) #Second combobox used if value_selected2 > 0: value_selected2 = value_selected2-1 y1, ylabel,title,y2 = self.get_value_params(value_selected2) ylab.append(ylabel) tit.append(title) yvalues, valuesAreTime = self.get_values(values,value_selected2, self.KEY_FORMAT, sportfield=self.SPORT_FIELD) yval.append(yvalues) xlab.append(xvalues) valsAreTime.append(valuesAreTime) #Draw chart self.drawarea.drawStackedBars(xlab,yval,ylab,tit,valsAreTime, colors = self.sport_colors) def get_value_params(self,value): return self.value_params[value]
def __init__(self, vbox = None, window = None, vbox2 = None, pytrainer_main = None): logging.debug('>>') self.drawarea = DrawArea(vbox, window) self.drawarea2 = DrawArea(vbox2, window) self.pytrainer_main = pytrainer_main logging.debug('<<')
class RecordGraph: def __init__(self, vbox = None, window = None, combovalue = None, combovalue2 = None, btnShowLaps = None, tableConfig = None, pytrainer_main=None): logging.debug(">>") self.pytrainer_main = pytrainer_main self.drawarea = DrawArea(vbox, window) self.combovalue = combovalue self.combovalue2 = combovalue2 self.showLaps = btnShowLaps self.config_table = tableConfig logging.debug("<<") def drawgraph(self,values,laps=None, y1limits=None, y1color=None, y1_linewidth=1): logging.debug(">>") #Get the config options for child in self.config_table.get_children(): if child.get_name() == "spinbuttonY1Max": spinbuttonY1Max = child elif child.get_name() == "spinbuttonY1Min": spinbuttonY1Min = child elif child.get_name() == "colorbuttonY1LineColor": colorbuttonY1LineColor = child elif child.get_name() == "spinbuttonY1LineWeight": spinbuttonY1LineWeight = child xval = [] yval = [] xlab = [] ylab = [] tit = [] col = [] value_selected = self.combovalue.get_active() logging.debug("Value selected 1: "+ str(value_selected)) value_selected2 = self.combovalue2.get_active() logging.debug("Value selected 2: "+ str(value_selected2)) showLaps = self.showLaps.get_active() logging.debug("Show laps: "+ str(showLaps)) #Determine left and right lap boundaries if laps is not None and showLaps: lapValues = [] lastPoint = 0.0 for lap in laps: thisPoint = float(lap['distance'])/1000.0 + lastPoint lapValues.append((lastPoint, thisPoint)) lastPoint = thisPoint else: lapValues = None if value_selected < 0: self.combovalue.set_active(0) value_selected = 0 if value_selected2 < 0: self.combovalue2.set_active(0) value_selected2 = 0 xvalues, yvalues = self.get_values(values,value_selected) max_yvalue = max(yvalues) min_yvalue = min(yvalues) xlabel,ylabel,title,color = self.get_value_params(value_selected) if y1color is not None: _color = gtk.gdk.Color(y1color) color = y1color else: _color = gtk.gdk.Color(color) xval.append(xvalues) yval.append(yvalues) if value_selected2 > 0: xlab.append("") else: xlab.append(xlabel) ylab.append(ylabel) tit.append(title) col.append(color) #_color = gtk.gdk.Color(color) colorbuttonY1LineColor.set_color(_color) if value_selected2 > 0: value_selected2 = value_selected2-1 xlabel,ylabel,title,color = self.get_value_params(value_selected2) xvalues,yvalues = self.get_values(values,value_selected2) max_yvalue=max(max(yvalues), max_yvalue) min_yvalue=min(min(yvalues), min_yvalue) xval.append(xvalues) yval.append(yvalues) xlab.append(xlabel) ylab.append(ylabel) tit.append("") col.append(color) logging.info("To show: tit: "+str(tit)+" | col: "+str(col)+" | xlab: "+str(xlab)+" | ylab: "+str(ylab)) #self.drawPlot(xvalues,yvalues,xlabel,ylabel,title,color,zones) plot_stats = self.drawarea.drawPlot(xval,yval,xlab,ylab,tit,col,None,lapValues, ylimits=y1limits, y1_linewidth=y1_linewidth) ymin = plot_stats['y1_min'] ymax = plot_stats['y1_max'] y1_linewidth = plot_stats['y1_linewidth'] max_yvalue = max(max_yvalue, ymax) min_yvalue = min(min_yvalue, ymin) adjY1Min = gtk.Adjustment(value=ymin, lower=min_yvalue,upper=max_yvalue, step_incr=1, page_incr=10) adjY1Max = gtk.Adjustment(value=ymax, lower=min_yvalue,upper=max_yvalue, step_incr=1, page_incr=10) spinbuttonY1Min.set_adjustment(adjY1Min) spinbuttonY1Max.set_adjustment(adjY1Max) spinbuttonY1Min.set_value(ymin) spinbuttonY1Max.set_value(ymax) spinbuttonY1LineWeight.set_value(y1_linewidth) logging.debug("<<") def get_value_params(self,value): if value == 0: return _("Distance (km)"),_("Height (m)"),_("Stage Profile"),"#000000" if value == 1: return _("Distance (km)"),_("Speed (Km/h)"),_("Speed"),"#00ff00" if value == 2: return _("Distance (km)"),_("Pace (min/km)"),_("Pace"),"#0000ff" if value == 3: return _("Distance (km)"),_("Beats (bpm)"),_("Heart Rate"),"#ff0000" if value == 4: return _("Distance (km)"),_("Cadence (rpm)"),_("Cadence"),"#7B3F00" if value == 5: return _("Distance (km)"),_("Beats (%)"),_("Beats"),"#ff0000" if value == 6: return _("Distance (km)"),_("Zone"),_("Zone"),"#ff0000" def get_values(self,values, value_selected): logging.debug(">>") xvalue = [] yvalue = [] zones = self.pytrainer_main.profile.getZones() for value in values: xvalue.append(value[0]) if value_selected==0: yvalue.append(value[1]) if value_selected==1: yvalue.append(value[3]) if value_selected==2: try: yvalue.append(60/value[3]) except: yvalue.append(0) if value_selected==3: yvalue.append(value[6]) if value_selected==4: yvalue.append(value[7]) if value_selected==5: if value[6] <= zones[4][0]: yvalue.append(50.0*value[6]/zones[4][0]) else: yvalue.append(50.0+50.0*((value[6]-zones[4][0])/(zones[0][1]-zones[4][0]))) if value_selected==6: if value[6] <= zones[4][0]: yvalue.append(1.0*value[6]/zones[4][0]) else: yvalue.append(1.0+5.0*((value[6]-zones[4][0])/(zones[0][1]-zones[4][0]))) logging.debug("<<") return xvalue,yvalue def getFloatValue(self, value): try: return float(value) except: return float(0)