geo-activity-playground 0.21.2__tar.gz → 0.23.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/PKG-INFO +1 -1
  2. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/__main__.py +7 -27
  3. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/activities.py +9 -3
  4. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/activity_parsers.py +14 -5
  5. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/heatmap.py +2 -2
  6. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/explorer/grid_file.py +7 -5
  7. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/explorer/tile_visits.py +51 -31
  8. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/explorer/video.py +3 -2
  9. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/importers/directory.py +4 -4
  10. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/importers/strava_api.py +6 -6
  11. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/importers/strava_checkout.py +8 -0
  12. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/app.py +60 -10
  13. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/calendar_controller.py +0 -3
  14. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/eddington_controller.py +0 -3
  15. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/entry_controller.py +3 -3
  16. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/equipment_controller.py +0 -3
  17. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/explorer_controller.py +16 -18
  18. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/heatmap_controller.py +16 -23
  19. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/square_planner_controller.py +6 -7
  20. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/calendar.html.j2 +2 -2
  21. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/page.html.j2 +13 -0
  22. geo_activity_playground-0.23.0/geo_activity_playground/webui/templates/upload.html.j2 +37 -0
  23. geo_activity_playground-0.23.0/geo_activity_playground/webui/upload_controller.py +114 -0
  24. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/pyproject.toml +10 -4
  25. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/LICENSE +0 -0
  26. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/__init__.py +0 -0
  27. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/__init__.py +0 -0
  28. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/cache_migrations.py +0 -0
  29. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/config.py +0 -0
  30. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/coordinates.py +0 -0
  31. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/paths.py +0 -0
  32. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/similarity.py +0 -0
  33. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/tasks.py +0 -0
  34. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/test_tiles.py +0 -0
  35. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/core/tiles.py +0 -0
  36. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/explorer/__init__.py +0 -0
  37. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/importers/test_directory.py +0 -0
  38. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/importers/test_strava_api.py +0 -0
  39. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/activity_controller.py +0 -0
  40. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/config_controller.py +0 -0
  41. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/locations_controller.py +0 -0
  42. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/search_controller.py +0 -0
  43. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/android-chrome-192x192.png +0 -0
  44. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/android-chrome-384x384.png +0 -0
  45. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/android-chrome-512x512.png +0 -0
  46. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/apple-touch-icon.png +0 -0
  47. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/browserconfig.xml +0 -0
  48. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/favicon-16x16.png +0 -0
  49. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/favicon-32x32.png +0 -0
  50. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/favicon.ico +0 -0
  51. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/mstile-150x150.png +0 -0
  52. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/safari-pinned-tab.svg +0 -0
  53. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/static/site.webmanifest +0 -0
  54. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/strava_controller.py +0 -0
  55. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/summary_controller.py +0 -0
  56. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/activity-day.html.j2 +0 -0
  57. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/activity-lines.html.j2 +0 -0
  58. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/activity-name.html.j2 +0 -0
  59. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/activity.html.j2 +0 -0
  60. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/calendar-month.html.j2 +0 -0
  61. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/config.html.j2 +0 -0
  62. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/eddington.html.j2 +0 -0
  63. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/equipment.html.j2 +0 -0
  64. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/explorer.html.j2 +0 -0
  65. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/heatmap.html.j2 +0 -0
  66. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/index.html.j2 +0 -0
  67. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/locations.html.j2 +0 -0
  68. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/search.html.j2 +0 -0
  69. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/square-planner.html.j2 +0 -0
  70. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/strava-connect.html.j2 +0 -0
  71. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/templates/summary.html.j2 +0 -0
  72. {geo_activity_playground-0.21.2 → geo_activity_playground-0.23.0}/geo_activity_playground/webui/tile_controller.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: geo-activity-playground
3
- Version: 0.21.2
3
+ Version: 0.23.0
4
4
  Summary: Analysis of geo data activities like rides, runs or hikes.
5
5
  License: MIT
6
6
  Author: Martin Ueding
@@ -7,17 +7,13 @@ import sys
7
7
  import coloredlogs
8
8
 
9
9
  from .importers.strava_checkout import convert_strava_checkout
10
- from .importers.strava_checkout import import_from_strava_checkout
11
10
  from geo_activity_playground.core.activities import ActivityRepository
12
- from geo_activity_playground.core.activities import embellish_time_series
13
11
  from geo_activity_playground.core.cache_migrations import apply_cache_migrations
14
12
  from geo_activity_playground.core.config import get_config
15
- from geo_activity_playground.explorer.tile_visits import compute_tile_evolution
16
- from geo_activity_playground.explorer.tile_visits import compute_tile_visits
13
+ from geo_activity_playground.explorer.tile_visits import TileVisitAccessor
17
14
  from geo_activity_playground.explorer.video import explorer_video_main
18
- from geo_activity_playground.importers.directory import import_from_directory
19
- from geo_activity_playground.importers.strava_api import import_from_strava_api
20
15
  from geo_activity_playground.webui.app import webui_main
16
+ from geo_activity_playground.webui.upload_controller import scan_for_activities
21
17
 
22
18
  logger = logging.getLogger(__name__)
23
19
 
@@ -68,7 +64,7 @@ def main() -> None:
68
64
  subparser = subparsers.add_parser("serve", help="Launch webserver")
69
65
  subparser.set_defaults(
70
66
  func=lambda options: webui_main(
71
- make_activity_repository(options.basedir, options.skip_strava),
67
+ *make_activity_repository(options.basedir, options.skip_strava),
72
68
  host=options.host,
73
69
  port=options.port,
74
70
  )
@@ -99,7 +95,7 @@ def main() -> None:
99
95
 
100
96
  def make_activity_repository(
101
97
  basedir: pathlib.Path, skip_strava: bool
102
- ) -> ActivityRepository:
98
+ ) -> tuple[ActivityRepository, TileVisitAccessor, dict]:
103
99
  os.chdir(basedir)
104
100
  apply_cache_migrations()
105
101
  config = get_config()
@@ -111,27 +107,11 @@ def make_activity_repository(
111
107
  sys.exit(1)
112
108
 
113
109
  repository = ActivityRepository()
110
+ tile_visit_accessor = TileVisitAccessor()
114
111
 
115
- if pathlib.Path("Activities").exists():
116
- import_from_directory(
117
- repository,
118
- config.get("metadata_extraction_regexes", []),
119
- )
120
- if pathlib.Path("Strava Export").exists():
121
- import_from_strava_checkout(repository)
122
- if "strava" in config and not skip_strava:
123
- import_from_strava_api(repository)
124
-
125
- if len(repository) == 0:
126
- logger.error(
127
- f"No activities found. You need to either add activity files (GPX, FIT, …) to {basedir/'Activities'} or set up the Strava API. Starting without any activities is unfortunately not supported."
128
- )
129
- sys.exit(1)
112
+ scan_for_activities(repository, tile_visit_accessor, config, skip_strava)
130
113
 
131
- embellish_time_series(repository)
132
- compute_tile_visits(repository)
133
- compute_tile_evolution()
134
- return repository
114
+ return repository, tile_visit_accessor, config
135
115
 
136
116
 
137
117
  if __name__ == "__main__":
@@ -78,6 +78,11 @@ class ActivityRepository:
78
78
  f"Adding {len(self._loose_activities)} activities to the repository …"
79
79
  )
80
80
  new_df = pd.DataFrame(self._loose_activities)
81
+ if not pd.api.types.is_dtype_equal(
82
+ new_df["start"].dtype, "datetime64[ns, UTC]"
83
+ ):
84
+ new_df["start"] = new_df["start"].dt.tz_localize("UTC")
85
+ new_df["start"] = new_df["start"].dt.tz_convert("UTC")
81
86
  if len(self.meta):
82
87
  new_ids_set = set(new_df["id"])
83
88
  is_kept = [
@@ -89,7 +94,7 @@ class ActivityRepository:
89
94
  self.meta = pd.concat([old_df, new_df])
90
95
  assert pd.api.types.is_dtype_equal(
91
96
  self.meta["start"].dtype, "datetime64[ns, UTC]"
92
- ), self.meta["start"].dtype
97
+ ), (self.meta["start"].dtype, self.meta["start"].iloc[0])
93
98
  self.save()
94
99
  self._loose_activities = []
95
100
 
@@ -120,10 +125,11 @@ class ActivityRepository:
120
125
  def activity_ids(self) -> set[int]:
121
126
  return set(self.meta.index)
122
127
 
123
- def iter_activities(self, new_to_old=True) -> Iterator[ActivityMeta]:
128
+ def iter_activities(self, new_to_old=True, dropna=False) -> Iterator[ActivityMeta]:
124
129
  direction = -1 if new_to_old else 1
125
130
  for index, row in self.meta[::direction].iterrows():
126
- yield row
131
+ if not dropna or not pd.isna(row["start"]):
132
+ yield row
127
133
 
128
134
  @functools.lru_cache()
129
135
  def get_activity_by_id(self, id: int) -> ActivityMeta:
@@ -12,6 +12,7 @@ import numpy as np
12
12
  import pandas as pd
13
13
  import tcxreader.tcxreader
14
14
  import xmltodict
15
+ from pandas._libs import NaTType
15
16
 
16
17
  from geo_activity_playground.core.activities import ActivityMeta
17
18
  from geo_activity_playground.core.activities import embellish_single_time_series
@@ -126,8 +127,12 @@ def read_fit_activity(path: pathlib.Path, open) -> tuple[ActivityMeta, pd.DataFr
126
127
  and values.get("position_long", None)
127
128
  ):
128
129
  time = values["timestamp"]
129
- assert isinstance(time, datetime.datetime)
130
- time = time.astimezone(datetime.timezone.utc)
130
+ if isinstance(time, datetime.datetime):
131
+ time = time.astimezone(datetime.timezone.utc)
132
+ elif time is None or isinstance(time, int):
133
+ time = pd.NaT
134
+ else:
135
+ raise RuntimeError(f"Cannot parse time: {time} in {path}.")
131
136
  row = {
132
137
  "time": time,
133
138
  "latitude": values["position_lat"] / ((2**32) / 360),
@@ -202,10 +207,13 @@ def read_gpx_activity(path: pathlib.Path, open) -> pd.DataFrame:
202
207
  for point in segment.points:
203
208
  if isinstance(point.time, datetime.datetime):
204
209
  time = point.time
205
- else:
210
+ time = time.astimezone(datetime.timezone.utc)
211
+ elif isinstance(point.time, str):
206
212
  time = dateutil.parser.parse(str(point.time))
207
- assert isinstance(time, datetime.datetime)
208
- time = time.astimezone(datetime.timezone.utc)
213
+ time = time.astimezone(datetime.timezone.utc)
214
+ else:
215
+ time = pd.NaT
216
+ time.tz_localize("UTC")
209
217
  points.append((time, point.latitude, point.longitude, point.elevation))
210
218
 
211
219
  df = pd.DataFrame(points, columns=["time", "latitude", "longitude", "altitude"])
@@ -233,6 +241,7 @@ def read_tcx_activity(path: pathlib.Path, opener) -> pd.DataFrame:
233
241
  content = f.read().strip()
234
242
 
235
243
  stripped_file = pathlib.Path("Cache/temp.tcx")
244
+ stripped_file.parent.mkdir(exist_ok=True)
236
245
  with open(stripped_file, "wb") as f:
237
246
  f.write(content)
238
247
  data = tcx_reader.read(str(stripped_file))
@@ -22,7 +22,7 @@ class GeoBounds:
22
22
  lon_max: float
23
23
 
24
24
 
25
- def get_bounds(lat_lon_data: np.array) -> GeoBounds:
25
+ def get_bounds(lat_lon_data: np.ndarray) -> GeoBounds:
26
26
  return GeoBounds(*np.min(lat_lon_data, axis=0), *np.max(lat_lon_data, axis=0))
27
27
 
28
28
 
@@ -106,7 +106,7 @@ def get_sensible_zoom_level(
106
106
  )
107
107
 
108
108
 
109
- def build_map_from_tiles(tile_bounds: TileBounds) -> np.array:
109
+ def build_map_from_tiles(tile_bounds: TileBounds) -> np.ndarray:
110
110
  background = np.zeros((*tile_bounds.shape, 3))
111
111
 
112
112
  for x in range(tile_bounds.x_tile_min, tile_bounds.x_tile_max):
@@ -16,7 +16,7 @@ logger = logging.getLogger(__name__)
16
16
 
17
17
  def get_border_tiles(
18
18
  tiles: pd.DataFrame, zoom: int, tile_bounds: Bounds
19
- ) -> list[list[list[float]]]:
19
+ ) -> list[list[tuple[float, float]]]:
20
20
  logger.info("Generate border tiles …")
21
21
  tile_set = set(zip(tiles["tile_x"], tiles["tile_y"]))
22
22
  border_tiles = set()
@@ -28,7 +28,9 @@ def get_border_tiles(
28
28
  return make_grid_points(border_tiles, zoom)
29
29
 
30
30
 
31
- def get_explored_tiles(tiles: pd.DataFrame, zoom: int) -> list[list[list[float]]]:
31
+ def get_explored_tiles(
32
+ tiles: pd.DataFrame, zoom: int
33
+ ) -> list[list[tuple[float, float]]]:
32
34
  return make_grid_points(zip(tiles["tile_x"], tiles["tile_y"]), zoom)
33
35
 
34
36
 
@@ -66,7 +68,7 @@ def make_explorer_rectangle(
66
68
 
67
69
  def make_grid_points(
68
70
  tiles: Iterable[tuple[int, int]], zoom: int
69
- ) -> list[list[list[float]]]:
71
+ ) -> list[list[tuple[float, float]]]:
70
72
  result = []
71
73
  for tile_x, tile_y in tiles:
72
74
  tile = [
@@ -80,7 +82,7 @@ def make_grid_points(
80
82
  return result
81
83
 
82
84
 
83
- def make_grid_file_gpx(grid_points: list[list[list[float]]]) -> str:
85
+ def make_grid_file_gpx(grid_points: list[list[tuple[float, float]]]) -> str:
84
86
  gpx = gpxpy.gpx.GPX()
85
87
  gpx_track = gpxpy.gpx.GPXTrack()
86
88
  gpx.tracks.append(gpx_track)
@@ -93,7 +95,7 @@ def make_grid_file_gpx(grid_points: list[list[list[float]]]) -> str:
93
95
  return gpx.to_xml()
94
96
 
95
97
 
96
- def make_grid_file_geojson(grid_points: list[list[list[float]]]) -> str:
98
+ def make_grid_file_geojson(grid_points: list[list[tuple[float, float]]]) -> str:
97
99
  fc = geojson.FeatureCollection(
98
100
  [
99
101
  geojson.Feature(
@@ -20,18 +20,39 @@ from geo_activity_playground.core.tiles import interpolate_missing_tile
20
20
 
21
21
  logger = logging.getLogger(__name__)
22
22
 
23
- TILE_EVOLUTION_STATES_PATH = pathlib.Path("Cache/tile-evolution-state.pickle")
24
- TILE_HISTORIES_PATH = pathlib.Path(f"Cache/tile-history.pickle")
25
- TILE_VISITS_PATH = pathlib.Path(f"Cache/tile-visits.pickle")
26
23
 
24
+ class TileVisitAccessor:
25
+ TILE_EVOLUTION_STATES_PATH = pathlib.Path("Cache/tile-evolution-state.pickle")
26
+ TILE_HISTORIES_PATH = pathlib.Path(f"Cache/tile-history.pickle")
27
+ TILE_VISITS_PATH = pathlib.Path(f"Cache/tile-visits.pickle")
27
28
 
28
- def compute_tile_visits(repository: ActivityRepository) -> None:
29
- tile_visits: dict[int, dict[tuple[int, int], dict[str, Any]]] = try_load_pickle(
30
- TILE_VISITS_PATH
31
- ) or collections.defaultdict(dict)
32
- tile_history: dict[int, pd.DataFrame] = try_load_pickle(
33
- TILE_HISTORIES_PATH
34
- ) or collections.defaultdict(pd.DataFrame)
29
+ def __init__(self) -> None:
30
+ self.visits: dict[int, dict[tuple[int, int], dict[str, Any]]] = try_load_pickle(
31
+ self.TILE_VISITS_PATH
32
+ ) or collections.defaultdict(dict)
33
+
34
+ self.histories: dict[int, pd.DataFrame] = try_load_pickle(
35
+ self.TILE_HISTORIES_PATH
36
+ ) or collections.defaultdict(pd.DataFrame)
37
+
38
+ self.states = try_load_pickle(
39
+ self.TILE_EVOLUTION_STATES_PATH
40
+ ) or collections.defaultdict(TileEvolutionState)
41
+
42
+ def save(self) -> None:
43
+ with open(self.TILE_VISITS_PATH, "wb") as f:
44
+ pickle.dump(self.visits, f)
45
+
46
+ with open(self.TILE_HISTORIES_PATH, "wb") as f:
47
+ pickle.dump(self.histories, f)
48
+
49
+ with open(self.TILE_EVOLUTION_STATES_PATH, "wb") as f:
50
+ pickle.dump(self.states, f)
51
+
52
+
53
+ def compute_tile_visits(
54
+ repository: ActivityRepository, tile_visits_accessor: TileVisitAccessor
55
+ ) -> None:
35
56
 
36
57
  work_tracker = WorkTracker("tile-visits")
37
58
  activity_ids_to_process = work_tracker.filter(repository.activity_ids)
@@ -43,8 +64,8 @@ def compute_tile_visits(repository: ActivityRepository) -> None:
43
64
  for zoom in range(20):
44
65
  for time, tile_x, tile_y in _tiles_from_points(time_series, zoom):
45
66
  tile = (tile_x, tile_y)
46
- if tile in tile_visits[zoom]:
47
- d = tile_visits[zoom][tile]
67
+ if tile in tile_visits_accessor.visits[zoom]:
68
+ d = tile_visits_accessor.visits[zoom][tile]
48
69
  if d["first_time"] > time:
49
70
  d["first_time"] = time
50
71
  d["first_id"] = activity_id
@@ -53,7 +74,7 @@ def compute_tile_visits(repository: ActivityRepository) -> None:
53
74
  d["last_id"] = activity_id
54
75
  d["activity_ids"].add(activity_id)
55
76
  else:
56
- tile_visits[zoom][tile] = {
77
+ tile_visits_accessor.visits[zoom][tile] = {
57
78
  "first_time": time,
58
79
  "first_id": activity_id,
59
80
  "last_time": time,
@@ -71,16 +92,19 @@ def compute_tile_visits(repository: ActivityRepository) -> None:
71
92
  work_tracker.mark_done(activity_id)
72
93
 
73
94
  if activity_ids_to_process:
74
- with open(TILE_VISITS_PATH, "wb") as f:
75
- pickle.dump(tile_visits, f)
76
-
77
95
  for zoom, new_rows in new_tile_history_rows.items():
78
96
  new_df = pd.DataFrame(new_rows)
97
+ if not pd.api.types.is_dtype_equal(
98
+ new_df["time"].dtype, "datetime64[ns, UTC]"
99
+ ):
100
+ new_df["time"] = new_df["time"].dt.tz_localize("UTC")
101
+ new_df["time"] = new_df["time"].dt.tz_convert("UTC")
79
102
  new_df.sort_values("time", inplace=True)
80
- tile_history[zoom] = pd.concat([tile_history[zoom], new_df])
103
+ tile_visits_accessor.histories[zoom] = pd.concat(
104
+ [tile_visits_accessor.histories[zoom], new_df]
105
+ )
81
106
 
82
- with open(TILE_HISTORIES_PATH, "wb") as f:
83
- pickle.dump(tile_history, f)
107
+ tile_visits_accessor.save()
84
108
 
85
109
  work_tracker.close()
86
110
 
@@ -123,23 +147,19 @@ class TileEvolutionState:
123
147
  self.square_y: Optional[int] = None
124
148
 
125
149
 
126
- def compute_tile_evolution() -> None:
127
- with open(TILE_HISTORIES_PATH, "rb") as f:
128
- tile_histories = pickle.load(f)
129
-
130
- states = try_load_pickle(TILE_EVOLUTION_STATES_PATH) or collections.defaultdict(
131
- TileEvolutionState
132
- )
133
-
150
+ def compute_tile_evolution(tile_visits_accessor: TileVisitAccessor) -> None:
134
151
  zoom_levels = list(reversed(list(range(20))))
135
152
 
136
153
  for zoom in tqdm(zoom_levels, desc="Compute explorer cluster evolution"):
137
- _compute_cluster_evolution(tile_histories[zoom], states[zoom])
154
+ _compute_cluster_evolution(
155
+ tile_visits_accessor.histories[zoom], tile_visits_accessor.states[zoom]
156
+ )
138
157
  for zoom in tqdm(zoom_levels, desc="Compute explorer square evolution"):
139
- _compute_square_history(tile_histories[zoom], states[zoom])
158
+ _compute_square_history(
159
+ tile_visits_accessor.histories[zoom], tile_visits_accessor.states[zoom]
160
+ )
140
161
 
141
- with open(TILE_EVOLUTION_STATES_PATH, "wb") as f:
142
- pickle.dump(states, f)
162
+ tile_visits_accessor.save()
143
163
 
144
164
 
145
165
  def _compute_cluster_evolution(tiles: pd.DataFrame, s: TileEvolutionState) -> None:
@@ -3,6 +3,7 @@ import math
3
3
  import pathlib
4
4
  from typing import Generator
5
5
  from typing import List
6
+ from typing import Optional
6
7
  from typing import Set
7
8
  from typing import Tuple
8
9
 
@@ -23,8 +24,8 @@ def build_image(
23
24
  brightness: float = 1.0,
24
25
  width: int = 1920,
25
26
  height: int = 1080,
26
- frame_counter: int = None,
27
- ) -> Image.Image:
27
+ frame_counter: int = 0,
28
+ ) -> Optional[Image.Image]:
28
29
  path = pathlib.Path(f"video/{frame_counter:06d}.png")
29
30
  if path.exists():
30
31
  return None
@@ -49,9 +49,9 @@ def import_from_directory(
49
49
  paths_with_errors = [error for error in paths_with_errors if error]
50
50
 
51
51
  for path in tqdm(new_activity_paths, desc="Collate activity metadata"):
52
- activity_id = _get_file_hash(path)
52
+ activity_id = get_file_hash(path)
53
53
  file_metadata_path = file_metadata_dir / f"{activity_id}.pickle"
54
- work_tracker.mark_done(activity_id)
54
+ work_tracker.mark_done(path)
55
55
 
56
56
  if not file_metadata_path.exists():
57
57
  continue
@@ -87,7 +87,7 @@ def _cache_single_file(path: pathlib.Path) -> Optional[tuple[pathlib.Path, str]]
87
87
  activity_stream_dir = pathlib.Path("Cache/Activity Timeseries")
88
88
  file_metadata_dir = pathlib.Path("Cache/Activity Metadata")
89
89
 
90
- activity_id = _get_file_hash(path)
90
+ activity_id = get_file_hash(path)
91
91
  timeseries_path = activity_stream_dir / f"{activity_id}.parquet"
92
92
  file_metadata_path = file_metadata_dir / f"{activity_id}.pickle"
93
93
 
@@ -110,7 +110,7 @@ def _cache_single_file(path: pathlib.Path) -> Optional[tuple[pathlib.Path, str]]
110
110
  pickle.dump(activity_meta_from_file, f)
111
111
 
112
112
 
113
- def _get_file_hash(path: pathlib.Path) -> int:
113
+ def get_file_hash(path: pathlib.Path) -> int:
114
114
  file_hash = hashlib.blake2s()
115
115
  with open(path, "rb") as f:
116
116
  while chunk := f.read(8192):
@@ -103,12 +103,12 @@ def import_from_strava_api(repository: ActivityRepository) -> None:
103
103
  time.sleep(seconds_to_wait)
104
104
 
105
105
 
106
- def try_import_strava(repository: ActivityRepository) -> None:
107
- get_after = (
108
- repository.last_activity_date().isoformat().replace("+00:00", "Z")
109
- if repository.last_activity_date() is not None
110
- else "2000-01-01T00:00:00Z"
111
- )
106
+ def try_import_strava(repository: ActivityRepository) -> bool:
107
+ last = repository.last_activity_date()
108
+ if last is None:
109
+ get_after = "2000-01-01T00:00:00Z"
110
+ else:
111
+ get_after = last.isoformat().replace("+00:00", "Z")
112
112
 
113
113
  gear_names = {None: "None"}
114
114
 
@@ -2,6 +2,7 @@ import datetime
2
2
  import logging
3
3
  import pathlib
4
4
  import shutil
5
+ import sys
5
6
  import traceback
6
7
  from typing import Optional
7
8
  from typing import Union
@@ -133,6 +134,13 @@ def import_from_strava_checkout(repository: ActivityRepository) -> None:
133
134
  dayfirst = False
134
135
  if activities.columns[0] == "Aktivitäts-ID":
135
136
  activities = pd.read_csv(checkout_path / "activities.csv", decimal=",")
137
+ if len(activities.columns) != len(EXPECTED_COLUMNS):
138
+ logger.error(
139
+ f"You are trying to import a Strava checkout where the `activities.csv` contains German column headers. In order to import this, we need to map these to the English ones. Unfortunately Strava has changed the number of columns. Your file has {len(activities.columns)} but we expect {len(EXPECTED_COLUMNS)}. This means that the program needs to be updated to match the new Strava export format. Please go to https://github.com/martin-ueding/geo-activity-playground/issues and open a new issue and share the following output in the ticket:"
140
+ )
141
+ print(activities.columns)
142
+ print(activities.dtypes)
143
+ sys.exit(1)
136
144
  activities.columns = EXPECTED_COLUMNS
137
145
  dayfirst = True
138
146
 
@@ -1,3 +1,6 @@
1
+ import json
2
+ import pathlib
3
+ import secrets
1
4
  import urllib
2
5
 
3
6
  from flask import Flask
@@ -9,6 +12,7 @@ from flask import Response
9
12
  from .locations_controller import LocationsController
10
13
  from .search_controller import SearchController
11
14
  from geo_activity_playground.core.activities import ActivityRepository
15
+ from geo_activity_playground.explorer.tile_visits import TileVisitAccessor
12
16
  from geo_activity_playground.webui.activity_controller import ActivityController
13
17
  from geo_activity_playground.webui.calendar_controller import CalendarController
14
18
  from geo_activity_playground.webui.config_controller import ConfigController
@@ -26,6 +30,7 @@ from geo_activity_playground.webui.summary_controller import SummaryController
26
30
  from geo_activity_playground.webui.tile_controller import (
27
31
  TileController,
28
32
  )
33
+ from geo_activity_playground.webui.upload_controller import UploadController
29
34
 
30
35
 
31
36
  def route_activity(app: Flask, repository: ActivityRepository) -> None:
@@ -113,8 +118,10 @@ def route_equipment(app: Flask, repository: ActivityRepository) -> None:
113
118
  return render_template("equipment.html.j2", **equipment_controller.render())
114
119
 
115
120
 
116
- def route_explorer(app: Flask, repository: ActivityRepository) -> None:
117
- explorer_controller = ExplorerController(repository)
121
+ def route_explorer(
122
+ app: Flask, repository: ActivityRepository, tile_visit_accessor: TileVisitAccessor
123
+ ) -> None:
124
+ explorer_controller = ExplorerController(repository, tile_visit_accessor)
118
125
 
119
126
  @app.route("/explorer/<zoom>")
120
127
  def explorer(zoom: str):
@@ -159,8 +166,10 @@ def route_explorer(app: Flask, repository: ActivityRepository) -> None:
159
166
  )
160
167
 
161
168
 
162
- def route_heatmap(app: Flask, repository: ActivityRepository) -> None:
163
- heatmap_controller = HeatmapController(repository)
169
+ def route_heatmap(
170
+ app: Flask, repository: ActivityRepository, tile_visit_accessor: TileVisitAccessor
171
+ ) -> None:
172
+ heatmap_controller = HeatmapController(repository, tile_visit_accessor)
164
173
 
165
174
  @app.route("/heatmap")
166
175
  def heatmap():
@@ -207,8 +216,10 @@ def route_search(app: Flask, repository: ActivityRepository) -> None:
207
216
  )
208
217
 
209
218
 
210
- def route_square_planner(app: Flask, repository: ActivityRepository) -> None:
211
- controller = SquarePlannerController(repository)
219
+ def route_square_planner(
220
+ app: Flask, repository: ActivityRepository, tile_visit_accessor: TileVisitAccessor
221
+ ) -> None:
222
+ controller = SquarePlannerController(repository, tile_visit_accessor)
212
223
 
213
224
  @app.route("/square-planner/<zoom>/<x>/<y>/<size>")
214
225
  def square_planner_planner(zoom, x, y, size):
@@ -303,7 +314,42 @@ def route_tiles(app: Flask, repository: ActivityRepository) -> None:
303
314
  )
304
315
 
305
316
 
306
- def webui_main(repository: ActivityRepository, host: str, port: int) -> None:
317
+ def route_upload(
318
+ app: Flask,
319
+ repository: ActivityRepository,
320
+ tile_visit_accessor: TileVisitAccessor,
321
+ config: dict,
322
+ ):
323
+ upload_controller = UploadController(repository, tile_visit_accessor, config)
324
+
325
+ @app.route("/upload")
326
+ def form():
327
+ return render_template("upload.html.j2", **upload_controller.render_form())
328
+
329
+ @app.route("/upload/receive", methods=["POST"])
330
+ def receive():
331
+ return upload_controller.receive()
332
+
333
+
334
+ def get_secret_key():
335
+ secret_file = pathlib.Path("Cache/flask-secret.json")
336
+ if secret_file.exists():
337
+ with open(secret_file) as f:
338
+ secret = json.load(f)
339
+ else:
340
+ secret = secrets.token_hex()
341
+ with open(secret_file, "w") as f:
342
+ json.dump(secret, f)
343
+ return secret
344
+
345
+
346
+ def webui_main(
347
+ repository: ActivityRepository,
348
+ tile_visit_accessor: TileVisitAccessor,
349
+ config: dict,
350
+ host: str,
351
+ port: int,
352
+ ) -> None:
307
353
  app = Flask(__name__)
308
354
 
309
355
  route_activity(app, repository)
@@ -311,14 +357,18 @@ def webui_main(repository: ActivityRepository, host: str, port: int) -> None:
311
357
  route_config(app, repository)
312
358
  route_eddington(app, repository)
313
359
  route_equipment(app, repository)
314
- route_explorer(app, repository)
315
- route_heatmap(app, repository)
360
+ route_explorer(app, repository, tile_visit_accessor)
361
+ route_heatmap(app, repository, tile_visit_accessor)
316
362
  route_locations(app, repository)
317
363
  route_search(app, repository)
318
- route_square_planner(app, repository)
364
+ route_square_planner(app, repository, tile_visit_accessor)
319
365
  route_start(app, repository)
320
366
  route_strava(app, host, port)
321
367
  route_summary(app, repository)
322
368
  route_tiles(app, repository)
369
+ route_upload(app, repository, tile_visit_accessor, config)
370
+
371
+ app.config["UPLOAD_FOLDER"] = "Activities"
372
+ app.secret_key = get_secret_key()
323
373
 
324
374
  app.run(host=host, port=port)
@@ -1,6 +1,5 @@
1
1
  import collections
2
2
  import datetime
3
- import functools
4
3
 
5
4
  from geo_activity_playground.core.activities import ActivityRepository
6
5
 
@@ -9,7 +8,6 @@ class CalendarController:
9
8
  def __init__(self, repository: ActivityRepository) -> None:
10
9
  self._repository = repository
11
10
 
12
- @functools.cache
13
11
  def render_overview(self) -> dict:
14
12
  meta = self._repository.meta.copy()
15
13
  meta["date"] = meta["start"].dt.date
@@ -41,7 +39,6 @@ class CalendarController:
41
39
  "yearly_distances": yearly_distances,
42
40
  }
43
41
 
44
- @functools.cache
45
42
  def render_month(self, year: int, month: int) -> dict:
46
43
  meta = self._repository.meta.copy()
47
44
  meta["date"] = meta["start"].dt.date
@@ -1,5 +1,3 @@
1
- import functools
2
-
3
1
  import altair as alt
4
2
  import numpy as np
5
3
  import pandas as pd
@@ -11,7 +9,6 @@ class EddingtonController:
11
9
  def __init__(self, repository: ActivityRepository) -> None:
12
10
  self._repository = repository
13
11
 
14
- @functools.cache
15
12
  def render(self) -> dict:
16
13
  activities = self._repository.meta.copy()
17
14
  activities["day"] = [start.date() for start in activities["start"]]
@@ -1,5 +1,4 @@
1
1
  import datetime
2
- import functools
3
2
  import itertools
4
3
 
5
4
  import altair as alt
@@ -13,7 +12,6 @@ class EntryController:
13
12
  def __init__(self, repository: ActivityRepository) -> None:
14
13
  self._repository = repository
15
14
 
16
- @functools.cache
17
15
  def render(self) -> dict:
18
16
  result = {
19
17
  "distance_last_30_days_plot": distance_last_30_days_meta_plot(
@@ -22,7 +20,9 @@ class EntryController:
22
20
  "latest_activities": [],
23
21
  }
24
22
 
25
- for activity in itertools.islice(self._repository.iter_activities(), 15):
23
+ for activity in itertools.islice(
24
+ self._repository.iter_activities(dropna=True), 15
25
+ ):
26
26
  time_series = self._repository.get_time_series(activity["id"])
27
27
  result["latest_activities"].append(
28
28
  {
@@ -1,5 +1,3 @@
1
- import functools
2
-
3
1
  import altair as alt
4
2
  import pandas as pd
5
3
 
@@ -11,7 +9,6 @@ class EquipmentController:
11
9
  def __init__(self, repository: ActivityRepository) -> None:
12
10
  self._repository = repository
13
11
 
14
- @functools.cache
15
12
  def render(self) -> dict:
16
13
  total_distances = (
17
14
  self._repository.meta.groupby("equipment")