def drawMap(self, activity, linetype): '''Draw OSM map create HTML file using Open Layers and Open Street Map render using embedded Webkit ''' logging.debug(">>") points = [] levels = [] pointlist = [] polyline = [] attrlist = [] try: list_values = activity.tracks if list_values is not None and list_values != [] and len( list_values) > 0: for i in list_values: lat, lon = float(i[4]), float(i[5]) pointlist.append((lat, lon)) polyline.append("[%s, %s]" % (lon, lat)) attrlist.append((i[3], i[6])) # (Speed, HR) points, levels = Points.encodePoints(pointlist) points = points.replace("\\", "\\\\") laps = activity.laps timeHours = int(activity.time) / 3600 timeMin = (float(activity.time) / 3600.0 - timeHours) * 60 time = "%d%s %02d%s" % (timeHours, _("h"), timeMin, _("min")) startinfo = "<div class='info_content'>%s: %s</div>" % ( activity.sport_name, activity.title) finishinfo = "<div class='info_content'>%s: %s<br>%s: %s%s</div>" % (_("Time"), \ time, _("Distance"), activity.distance, activity.distance_unit) startinfo = startinfo.encode( 'ascii', 'xmlcharrefreplace') #Encode for html finishinfo = finishinfo.encode( 'ascii', 'xmlcharrefreplace') #Encode for html self.createHtml_osm(polyline, startinfo, finishinfo, laps, attrlist, linetype) else: self.createErrorHtml() except Exception as e: self.createErrorHtml(e) return self.htmlfile logging.debug("<<")
def drawMap(self, activity, linetype): '''Draw OSM map create HTML file using Open Layers and Open Street Map render using embedded Webkit ''' logging.debug(">>") points = [] levels = [] pointlist = [] polyline = [] attrlist = [] try : list_values = activity.tracks if list_values is not None and list_values != [] and len(list_values) > 0: for i in list_values: lat, lon = float(i[4]), float(i[5]) pointlist.append((lat,lon)) polyline.append("[%s, %s]" % (lon, lat)) attrlist.append((i[3],i[6])) # (Speed, HR) points,levels = Points.encodePoints(pointlist) points = points.replace("\\","\\\\") laps = activity.laps timeHours = int(activity.time) / 3600 timeMin = (float(activity.time) / 3600.0 - timeHours) * 60 time = "%d%s %02d%s" % (timeHours, _("h"), timeMin, _("min")) startinfo = "<div class='info_content'>%s: %s</div>" % (activity.sport_name, activity.title) finishinfo = "<div class='info_content'>%s: %s<br>%s: %s%s</div>" % (_("Time"), \ time, _("Distance"), activity.distance, activity.distance_unit) startinfo = startinfo.encode('ascii', 'xmlcharrefreplace') #Encode for html finishinfo = finishinfo.encode('ascii', 'xmlcharrefreplace') #Encode for html self.createHtml_osm(polyline, startinfo, finishinfo, laps, attrlist, linetype) else: self.createErrorHtml() except Exception as e: self.createErrorHtml(e) return self.htmlfile logging.debug("<<")
def drawMap(self,activity, linetype): '''Draw google map create html file using Google API version3 render using embedded Webkit ''' logging.debug(">>") points = [] levels = [] pointlist = [] polyline = [] list_values = activity.tracks # (accum distance, elevation, total duration, speed, lat, lon, bpm, cadence, corrected elevation) # (19.963867183986643, 7.34716797, 6488, 13.791899119294959, 43.53392358, -5.634736, 146, None, None) if list_values is not None and list_values != [] and len(list_values) > 0: minlat, minlon = float(list_values[0][4]),float(list_values[0][5]) maxlat=minlat maxlon=minlon av_sum = 0 variance_sum = 0 n = 0 #logging.debug("\n, ".join(map(str, list_values))) for i in list_values: if linetype==1: if i[3] is not None: val = i[3] else: val = 0 logging.error("No valid speed value for trackpoint: distance: %s | lat: %s | lon: %s" %(i[0],i[4],i[5])) elif linetype==2: val = i[6] if i[6] else 0 elif linetype==3: val = i[7] if i[7]!=None else 1 else: val = 1 variance_sum += (val)**2 av_sum += val n += 1 lat, lon = float(i[4]), float(i[5]) minlat = min(minlat, lat) maxlat = max(maxlat, lat) minlon = min(minlon, lon) maxlon = max(maxlon, lon) pointlist.append((lat,lon)) polyline.append(["new google.maps.LatLng(%s, %s)" % (lat, lon), val, ""]) av_speed = av_sum / float(n) variance = (variance_sum / float(n)) - av_speed**2 variance = max(variance, 16) self.colorLine(polyline, av_speed, variance) #self.colorLineAbs(polyline) logging.debug("minlat: %s, maxlat: %s" % (minlat, maxlat)) logging.debug("minlon: %s, maxlon: %s" % (minlon, maxlon)) points,levels = Points.encodePoints(pointlist) points = points.replace("\\","\\\\") logging.debug("Using Google Maps version 3 API") laps = activity.laps timeHours = int(activity.time) / 3600 timeMin = (float(activity.time) / 3600.0 - timeHours) * 60 time = "%d%s %02d%s" % (timeHours, _("h"), timeMin, _("min")) startinfo = "<div class='info_content'>%s: %s</div>" % (activity.sport_name, activity.title) finishinfo = "<div class='info_content'>%s: %s<br>%s: %s%s</div>" % (_("Time"), time, _("Distance"), activity.distance, activity.distance_unit) startinfo = startinfo.encode('ascii', 'xmlcharrefreplace') #Encode for html finishinfo = finishinfo.encode('ascii', 'xmlcharrefreplace') #Encode for html self.createHtml_api3(polyline, minlat, minlon, maxlat, maxlon, startinfo, finishinfo, laps, linetype) else: self.createErrorHtml() return self.htmlfile logging.debug("<<")