def leaflet_map_html(self): gpxpy_instance = self.get_gpxpy_instance() lat_list, lon_list = get_2d_coordinate_list(gpxpy_instance) coordinates = zip(lat_list, lon_list) km_gpx_points = iter_distance(gpxpy_instance, distance=1000) context = { "short_start_address": self.short_start_address, "start_time": self.start_time, "start_latitude": self.start_latitude, "start_longitude": self.start_longitude, "short_finish_address": self.short_finish_address, "finish_time": self.finish_time, "finish_latitude": self.finish_latitude, "finish_longitude": self.finish_longitude, "coordinates": coordinates, "km_gpx_points": km_gpx_points, } return render_to_string(template_name="for_runners/leaflet_map.html", context=context)
def dygraphs_html(self, obj): """ Use dygraphs array format: http://dygraphs.com/data.html#array """ gpxpy_instance = obj.get_gpxpy_instance() times = [] has_hr = None has_cad = None elevation_label = _("Elevation") labels = [_("Date"), elevation_label] columns = [] time2coordinates = {} for point in iter_points(gpxpy_instance): add_extension_data(point) timestamp = point.time.timestamp() * 1000 time2coordinates[timestamp] = (point.latitude, point.longitude) row = ["new Date(%i)" % timestamp, point.elevation] if has_hr is None or has_hr == True: try: row.append(point.extension_data["hr"]) except KeyError: has_hr = False else: if has_hr is None: has_hr = True labels.append(_("heart rate")) if has_cad is None or has_cad == True: try: row.append(point.extension_data["cad"]) except KeyError: has_cad = False else: if has_cad is None: has_cad = True labels.append(_("cadence")) columns.append(",".join([str(i) for i in row])) km_points = [] for point, distance_m, distance_km in iter_distance(gpxpy_instance, distance=1000): km_points.append({ "x": "%i" % (point.time.timestamp() * 1000), "distance_m": distance_m, "distance_km": distance_km, }) context = { "instance": obj, "labels": labels, "columns": columns, "elevation_label": elevation_label, "km_points": km_points, "time2coordinates": time2coordinates, } return render_to_string( template_name="admin/for_runners/gpxmodel/dygraphs.html", context=context)