Esempio n. 1
0
 def _make_strava_cache_dict(track: Track) -> typing.Dict[str, Any]:
     lines_data = []
     for line in track.polylines:
         lines_data.append([{"lat": latlng.lat().degrees, "lng": latlng.lng().degrees} for latlng in line])
     return {
         "name": track.file_names[0],  # strava id
         "start": track.start_time().strftime("%Y-%m-%d %H:%M:%S"),
         "end": track.end_time().strftime("%Y-%m-%d %H:%M:%S"),
         "length": track.length_meters,
         "segments": lines_data,
     }
Esempio n. 2
0
 def _strava_cache_to_track(data: typing.Dict[str, Any]) -> "Track":
     t = Track()
     t.file_names = [data["name"]]
     t.start_time = datetime.datetime.strptime(data["start"],
                                               "%Y-%m-%d %H:%M:%S")
     t.end_time = datetime.datetime.strptime(data["end"],
                                             "%Y-%m-%d %H:%M:%S")
     t.length_meters = float(data["length"])
     t.polylines = []
     for data_line in data["segments"]:
         t.polylines.append([
             s2sphere.LatLng.from_degrees(float(d["lat"]), float(d["lng"]))
             for d in data_line
         ])
     return t
Esempio n. 3
0
    def _draw_track(self, dr: svgwrite.Drawing, g: svgwrite.container.Group,
                    tr: Track, size: XY, offset: XY) -> None:
        color = self.color(self.poster.length_range, tr.length(), tr.special)
        str_length = utils.format_float(self.poster.m2u(tr.length()))

        date_title = str(tr.start_time().date())
        for line in utils.project(tr.bbox(), size, offset, tr.polylines):
            polyline = dr.polyline(
                points=line,
                stroke=color,
                fill="none",
                stroke_width=0.5,
                stroke_linejoin="round",
                stroke_linecap="round",
            )
            polyline.set_desc(
                title=f"{date_title} {str_length} {self.poster.u()}")
            g.add(polyline)