geo-activity-playground 1.9.3__py3-none-any.whl → 1.9.4__py3-none-any.whl

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.
@@ -66,8 +66,24 @@ GROUP_BY_VARIABLES = {
66
66
  VARIABLES_1 = {"": "", **DISCRETE_VARIABLES}
67
67
  VARIABLES_2 = {"": "", **DISCRETE_VARIABLES, **CONTINUOUS_VARIABLES}
68
68
 
69
+ RENAMES = {
70
+ "year(start):O": "year(start_local):O",
71
+ "yearquarter(start)": "yearquarter(start_local)",
72
+ "yearquartermonth(start)": "yearquartermonth(start_local)",
73
+ "yearmonth(start)": "yearmonth(start_local)",
74
+ "quarter(start)": "quarter(start_local)",
75
+ "quartermonth(start)": "quartermonth(start_local)",
76
+ "month(start)": "month(start_local)",
77
+ "date(start)": "date(start_local)",
78
+ "weekday(start)": "weekday(start_local)",
79
+ }
80
+
69
81
 
70
82
  def make_parametric_plot(df: pd.DataFrame, spec: PlotSpec) -> dict[str, str]:
83
+ # Update renamed fields.
84
+ for field in spec.FIELDS:
85
+ setattr(spec, field, RENAMES.get(getattr(spec, field), getattr(spec, field)))
86
+
71
87
  if spec.group_by:
72
88
  grouped = df.groupby(spec.group_by)
73
89
  else:
@@ -1,3 +1,4 @@
1
+ import hashlib
1
2
  import logging
2
3
  import pathlib
3
4
  import re
@@ -51,6 +52,17 @@ def import_from_directory(
51
52
  is None
52
53
  ]
53
54
 
55
+ for activity in DB.session.scalars(
56
+ sqlalchemy.select(Activity).filter(
57
+ Activity.upstream_id.is_(sqlalchemy.null()),
58
+ Activity.path.is_not(sqlalchemy.null()),
59
+ )
60
+ ):
61
+ assert activity.path is not None
62
+ if pathlib.Path(activity.path).exists():
63
+ activity.upstream_id = file_sha256(pathlib.Path(activity.path))
64
+ DB.session.commit()
65
+
54
66
  for i, activity_path in enumerate(
55
67
  tqdm(paths_to_import, desc="Importing activity files", delay=0)
56
68
  ):
@@ -58,10 +70,24 @@ def import_from_directory(
58
70
  activity = DB.session.scalar(
59
71
  sqlalchemy.select(Activity).filter(Activity.path == str(activity_path))
60
72
  )
61
- if activity is None:
62
- import_from_file(
63
- activity_path, repository, tile_visit_accessor, config, i
73
+ if activity is not None:
74
+ continue
75
+
76
+ with_same_hash = DB.session.scalars(
77
+ sqlalchemy.select(Activity).filter(
78
+ Activity.upstream_id == file_sha256(activity_path)
64
79
  )
80
+ ).all()
81
+ if with_same_hash:
82
+ if len(with_same_hash) == 1:
83
+ continue
84
+ else:
85
+ logger.warning(
86
+ "The following activities are duplicates: "
87
+ + ", ".join(str(activity.id) for activity in with_same_hash)
88
+ )
89
+
90
+ import_from_file(activity_path, repository, tile_visit_accessor, config, i)
65
91
 
66
92
 
67
93
  def import_from_file(
@@ -87,6 +113,7 @@ def import_from_file(
87
113
  return
88
114
 
89
115
  activity.path = str(path)
116
+ activity.upstream_id = file_sha256(path)
90
117
  if activity.name is None:
91
118
  activity.name = path.name.removesuffix("".join(path.suffixes))
92
119
 
@@ -120,3 +147,16 @@ def _get_metadata_from_path(
120
147
  if m := re.search(regex, str(path.relative_to(ACTIVITY_DIR))):
121
148
  return m.groupdict()
122
149
  return {}
150
+
151
+
152
+ def file_sha256(filename: pathlib.Path) -> str:
153
+ """
154
+ Based on https://stackoverflow.com/a/44873382/653152.
155
+ """
156
+ h = hashlib.sha256(usedforsecurity=False)
157
+ b = bytearray(128 * 1024)
158
+ mv = memoryview(b)
159
+ with open(filename, "rb", buffering=0) as f:
160
+ while n := f.readinto(mv):
161
+ h.update(mv[:n])
162
+ return h.hexdigest()
@@ -19,8 +19,6 @@ from ..core.datamodel import get_or_make_equipment
19
19
  from ..core.datamodel import get_or_make_kind
20
20
  from ..core.enrichment import update_and_commit
21
21
  from ..core.paths import activity_extracted_meta_dir
22
- from ..core.tasks import get_state
23
- from ..core.tasks import set_state
24
22
  from ..core.tasks import work_tracker_path
25
23
  from ..core.tasks import WorkTracker
26
24
  from .activity_parsers import ActivityParseError
@@ -132,6 +130,11 @@ EXPECTED_COLUMNS = [
132
130
  "Average Grade Adjusted Pace",
133
131
  "Timer Time",
134
132
  "Total Cycles",
133
+ "Regeneration",
134
+ "Mit Haustier",
135
+ "Wettbewerb",
136
+ "Langer Lauf",
137
+ "Für einen guten Zweck",
135
138
  "Media",
136
139
  ]
137
140
 
@@ -161,7 +164,12 @@ def import_from_strava_checkout(config: Config) -> None:
161
164
  if header[0] == EXPECTED_COLUMNS[0]:
162
165
  dayfirst = False
163
166
  elif header[0] == "Aktivitäts-ID":
164
- header = EXPECTED_COLUMNS
167
+ new_header = list(EXPECTED_COLUMNS)
168
+ if len(new_header) > len(header):
169
+ new_header = new_header[: len(header)]
170
+ elif len(new_header) < len(header):
171
+ new_header += [f"Ignored_{i}" for i in range(len(header) - len(new_header))]
172
+ header = new_header
165
173
  dayfirst = True
166
174
  else:
167
175
  logger.error(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: geo-activity-playground
3
- Version: 1.9.3
3
+ Version: 1.9.4
4
4
  Summary: Analysis of geo data activities like rides, runs or hikes.
5
5
  License: MIT
6
6
  Author: Martin Ueding
@@ -27,7 +27,7 @@ geo_activity_playground/core/export.py,sha256=ayOmhWL72263oP9NLIZRYCg_Db0GLUFhgN
27
27
  geo_activity_playground/core/heart_rate.py,sha256=-S3WAhS7AOywrw_Lk5jfuo_fu6zvZQ1VtjwEKSycWpU,1542
28
28
  geo_activity_playground/core/meta_search.py,sha256=Sevl4AtBwJZMW3VJ6ihRqwjC0M9fhJqX3MN6tw_hIFQ,6627
29
29
  geo_activity_playground/core/missing_values.py,sha256=HjonaLV0PFMICnuMrbdUNnK9uy_8PBh_RxI5GuEMQK0,250
30
- geo_activity_playground/core/parametric_plot.py,sha256=4MFm-KF5QgzLUZHWHKHlbDWAE_IM-raT1xOl_StKmkk,5797
30
+ geo_activity_playground/core/parametric_plot.py,sha256=sPaBnrcjvbzys0s0ge5OHtSSp1bJMaLtoO0UxXdffqo,6400
31
31
  geo_activity_playground/core/paths.py,sha256=qQ4ujaIHmsxTGEWzf-76XS8FclEI2RC5COTUeuLEbDI,2938
32
32
  geo_activity_playground/core/photos.py,sha256=pHdVUpgKfbyrTddZL_mgmsXQJ3k_IHKf70jtcIjjcCA,1229
33
33
  geo_activity_playground/core/privacy_zones.py,sha256=4TumHsVUN1uW6RG3ArqTXDykPVipF98DCxVBe7YNdO8,512
@@ -54,9 +54,9 @@ geo_activity_playground/heatmap_video.py,sha256=I8i1uVvbbPUXVtvLAROaLy58nQoUPnuM
54
54
  geo_activity_playground/importers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
55
55
  geo_activity_playground/importers/activity_parsers.py,sha256=lh7B_ZwZkcwZgrwLhptobcLfxvDIiPJRgWdE9fZzKw4,12475
56
56
  geo_activity_playground/importers/csv_parser.py,sha256=O1pP5GLhWhnWcy2Lsrr9g17Zspuibpt-GtZ3ZS5eZF4,2143
57
- geo_activity_playground/importers/directory.py,sha256=sHcLIi0DOPEATt4wiE_vp00h89fO940wUQyJZUzzpnw,3978
57
+ geo_activity_playground/importers/directory.py,sha256=UBs-iWGZx_LkknytsRykAo_BaScUg0wYkfThpk5HG-8,5338
58
58
  geo_activity_playground/importers/strava_api.py,sha256=1sRb_CD4tbsW-MwP6QPg7zpATlb6XpniS4rtH72iwkw,9606
59
- geo_activity_playground/importers/strava_checkout.py,sha256=j_M_FEEQocLWcnrgeLR9hEs3WNwhdLc88DaS5-UWjxs,9289
59
+ geo_activity_playground/importers/strava_checkout.py,sha256=Tpln_IweoTIo-dkkTyRsVPGWesSu3S3C3ifd874NqUA,9590
60
60
  geo_activity_playground/importers/test_csv_parser.py,sha256=nOTVTdlzIY0TDcbWp7xNyNaIO6Mkeu55hVziVl22QE4,1092
61
61
  geo_activity_playground/importers/test_directory.py,sha256=_fn_-y98ZyElbG0BRxAmGFdtGobUShPU86SdEOpuv-A,691
62
62
  geo_activity_playground/importers/test_strava_api.py,sha256=7b8bl5Rh2BctCmvTPEhCadxtUOq3mfzuadD6F5XxRio,398
@@ -175,8 +175,8 @@ geo_activity_playground/webui/templates/summary/vega-chart.html.j2,sha256=mw8Hti
175
175
  geo_activity_playground/webui/templates/time_zone_fixer/index.html.j2,sha256=s9r6BJMXmd7kLSyjkvH4xLi6e01S5bpGRcMgMMJyCAE,1760
176
176
  geo_activity_playground/webui/templates/upload/index.html.j2,sha256=5W2gpm4eSvidOyJOCSZZbvTZaTkSWNrOWux3-oIm0zI,784
177
177
  geo_activity_playground/webui/templates/upload/reload.html.j2,sha256=YZWX5eDeNyqKJdQAywDBcU8DZBm22rRBbZqFjrFrCvQ,556
178
- geo_activity_playground-1.9.3.dist-info/LICENSE,sha256=4RpAwKO8bPkfXH2lnpeUW0eLkNWglyG4lbrLDU_MOwY,1070
179
- geo_activity_playground-1.9.3.dist-info/METADATA,sha256=AEO2ezh1z0d7ZOpfNpJkLS6z1wb7p2Ps8tjGPvG-Ha4,1937
180
- geo_activity_playground-1.9.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
181
- geo_activity_playground-1.9.3.dist-info/entry_points.txt,sha256=pbNlLI6IIZIp7nPYCfAtiSiz2oxJSCl7DODD6SPkLKk,81
182
- geo_activity_playground-1.9.3.dist-info/RECORD,,
178
+ geo_activity_playground-1.9.4.dist-info/LICENSE,sha256=4RpAwKO8bPkfXH2lnpeUW0eLkNWglyG4lbrLDU_MOwY,1070
179
+ geo_activity_playground-1.9.4.dist-info/METADATA,sha256=TWDOnevm__CRkjcmlnfI73azWUZey8R5clp-0w3kgi8,1937
180
+ geo_activity_playground-1.9.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
181
+ geo_activity_playground-1.9.4.dist-info/entry_points.txt,sha256=pbNlLI6IIZIp7nPYCfAtiSiz2oxJSCl7DODD6SPkLKk,81
182
+ geo_activity_playground-1.9.4.dist-info/RECORD,,