fitbrowser 0.0.1__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.
- fitbrowser/__init__.py +18 -0
- fitbrowser/__main__.py +11 -0
- fitbrowser/activity.js +326 -0
- fitbrowser/activity.py +2203 -0
- fitbrowser/fitapp.py +402 -0
- fitbrowser/fitbrowser.css +140 -0
- fitbrowser/fitbrowser.py +50 -0
- fitbrowser/fitconfig.py +180 -0
- fitbrowser/fitcss.py +123 -0
- fitbrowser/fitgeo.py +201 -0
- fitbrowser/fithtml.py +638 -0
- fitbrowser/fithttp.py +103 -0
- fitbrowser/fitkey.py +129 -0
- fitbrowser/fitui.py +843 -0
- fitbrowser/overview.js +117 -0
- fitbrowser-0.0.1.dist-info/METADATA +216 -0
- fitbrowser-0.0.1.dist-info/RECORD +21 -0
- fitbrowser-0.0.1.dist-info/WHEEL +5 -0
- fitbrowser-0.0.1.dist-info/entry_points.txt +5 -0
- fitbrowser-0.0.1.dist-info/licenses/LICENSE.txt +674 -0
- fitbrowser-0.0.1.dist-info/top_level.txt +1 -0
fitbrowser/__init__.py
ADDED
fitbrowser/__main__.py
ADDED
fitbrowser/activity.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2026 Google LLC. All Rights Reserved.
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Activity file parsing happens out-of-band, in activity_to_json.py. This
|
|
9
|
+
// page just fetches the resulting data.json and renders it on the map.
|
|
10
|
+
|
|
11
|
+
function pausedSecondsBetween(pauses, from, to) {
|
|
12
|
+
let paused = 0;
|
|
13
|
+
for (const pause of pauses) {
|
|
14
|
+
const overlapStart = Math.max(pause.start.getTime(), from.getTime());
|
|
15
|
+
const overlapEnd = Math.min(pause.end.getTime(), to.getTime());
|
|
16
|
+
if (overlapEnd > overlapStart) paused += (overlapEnd - overlapStart) / 1000;
|
|
17
|
+
}
|
|
18
|
+
return paused;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function movingSecondsBetween(pauses, from, to) {
|
|
22
|
+
return (to.getTime() - from.getTime()) / 1000 - pausedSecondsBetween(pauses, from, to);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// --- Map wiring -------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
const mapElement = document.getElementById('map');
|
|
28
|
+
|
|
29
|
+
let map;
|
|
30
|
+
let Polyline;
|
|
31
|
+
let Marker;
|
|
32
|
+
let InfoWindow;
|
|
33
|
+
let infoWindow;
|
|
34
|
+
let currentPolyline;
|
|
35
|
+
let startMarker;
|
|
36
|
+
let endMarker;
|
|
37
|
+
let kmMarkers = [];
|
|
38
|
+
let pauseMarkers = [];
|
|
39
|
+
|
|
40
|
+
function haversineMeters(a, b) {
|
|
41
|
+
const R = 6371000;
|
|
42
|
+
const toRad = (d) => (d * Math.PI) / 180;
|
|
43
|
+
const dLat = toRad(b.lat - a.lat);
|
|
44
|
+
const dLng = toRad(b.lng - a.lng);
|
|
45
|
+
const h =
|
|
46
|
+
Math.sin(dLat / 2) ** 2 +
|
|
47
|
+
Math.cos(toRad(a.lat)) * Math.cos(toRad(b.lat)) * Math.sin(dLng / 2) ** 2;
|
|
48
|
+
return 2 * R * Math.asin(Math.sqrt(h));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function formatDuration(seconds) {
|
|
52
|
+
const h = Math.floor(seconds / 3600);
|
|
53
|
+
const m = Math.floor((seconds % 3600) / 60);
|
|
54
|
+
const s = Math.floor(seconds % 60);
|
|
55
|
+
return `${h > 0 ? h + 'h ' : ''}${m}m ${s}s`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const KM_IN_METERS = 1000;
|
|
59
|
+
|
|
60
|
+
function computeKmSplits(records, pauses) {
|
|
61
|
+
const splits = [];
|
|
62
|
+
const startTime = records[0].time;
|
|
63
|
+
let lastSplitTime = startTime;
|
|
64
|
+
let lastEle = records[0].ele;
|
|
65
|
+
let cumulativeDistance = 0;
|
|
66
|
+
let nextTarget = KM_IN_METERS;
|
|
67
|
+
|
|
68
|
+
for (let i = 1; i < records.length; i++) {
|
|
69
|
+
const prev = records[i - 1];
|
|
70
|
+
const curr = records[i];
|
|
71
|
+
const segmentStart = cumulativeDistance;
|
|
72
|
+
const segmentDistance = haversineMeters(prev, curr);
|
|
73
|
+
cumulativeDistance += segmentDistance;
|
|
74
|
+
|
|
75
|
+
while (segmentDistance > 0 && nextTarget <= cumulativeDistance) {
|
|
76
|
+
const fraction = (nextTarget - segmentStart) / segmentDistance;
|
|
77
|
+
const lat = prev.lat + (curr.lat - prev.lat) * fraction;
|
|
78
|
+
const lng = prev.lng + (curr.lng - prev.lng) * fraction;
|
|
79
|
+
const time =
|
|
80
|
+
prev.time && curr.time
|
|
81
|
+
? new Date(prev.time.getTime() + (curr.time.getTime() - prev.time.getTime()) * fraction)
|
|
82
|
+
: undefined;
|
|
83
|
+
const ele =
|
|
84
|
+
prev.ele !== undefined && curr.ele !== undefined
|
|
85
|
+
? prev.ele + (curr.ele - prev.ele) * fraction
|
|
86
|
+
: undefined;
|
|
87
|
+
|
|
88
|
+
splits.push({
|
|
89
|
+
km: nextTarget / KM_IN_METERS,
|
|
90
|
+
lat,
|
|
91
|
+
lng,
|
|
92
|
+
splitSeconds: time && lastSplitTime ? movingSecondsBetween(pauses, lastSplitTime, time) : undefined,
|
|
93
|
+
elapsedSeconds: time && startTime ? movingSecondsBetween(pauses, startTime, time) : undefined,
|
|
94
|
+
elevationChange: ele !== undefined && lastEle !== undefined ? ele - lastEle : undefined,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (time) lastSplitTime = time;
|
|
98
|
+
if (ele !== undefined) lastEle = ele;
|
|
99
|
+
nextTarget += KM_IN_METERS;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return splits;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function clearKmMarkers() {
|
|
107
|
+
kmMarkers.forEach((marker) => marker.setMap(null));
|
|
108
|
+
kmMarkers = [];
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function addKmMarkers(records, pauses) {
|
|
112
|
+
clearKmMarkers();
|
|
113
|
+
|
|
114
|
+
computeKmSplits(records, pauses).forEach(({ km, lat, lng, splitSeconds, elapsedSeconds, elevationChange }) => {
|
|
115
|
+
const splitText = splitSeconds !== undefined ? formatDuration(splitSeconds) : 'n/a';
|
|
116
|
+
const elevationText =
|
|
117
|
+
elevationChange !== undefined
|
|
118
|
+
? `${elevationChange >= 0 ? '+' : ''}${Math.round(elevationChange)} m`
|
|
119
|
+
: undefined;
|
|
120
|
+
const marker = new Marker({
|
|
121
|
+
position: { lat, lng },
|
|
122
|
+
map,
|
|
123
|
+
title: `Km ${km}: ${splitText}`,
|
|
124
|
+
label: { text: String(km), fontSize: '10px', color: '#ffffff' },
|
|
125
|
+
icon: {
|
|
126
|
+
path: google.maps.SymbolPath.CIRCLE,
|
|
127
|
+
scale: 9,
|
|
128
|
+
fillColor: '#4285F4',
|
|
129
|
+
fillOpacity: 1,
|
|
130
|
+
strokeColor: '#ffffff',
|
|
131
|
+
strokeWeight: 1.5,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
marker.addListener('click', () => {
|
|
136
|
+
infoWindow.setContent(
|
|
137
|
+
`<div><strong>Km ${km}</strong><br>Split: ${splitText}` +
|
|
138
|
+
(elapsedSeconds !== undefined ? `<br>Total: ${formatDuration(elapsedSeconds)}` : '') +
|
|
139
|
+
(elevationText !== undefined ? `<br>Elevation: ${elevationText}` : '') +
|
|
140
|
+
`</div>`,
|
|
141
|
+
);
|
|
142
|
+
infoWindow.open({ map, anchor: marker });
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
kmMarkers.push(marker);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function clearPauseMarkers() {
|
|
150
|
+
pauseMarkers.forEach((marker) => marker.setMap(null));
|
|
151
|
+
pauseMarkers = [];
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Finds where on the track the runner was at a given time, interpolating
|
|
155
|
+
// between the two surrounding GPS points (or clamping to the nearest end).
|
|
156
|
+
function findPositionAtTime(records, time) {
|
|
157
|
+
for (let i = 1; i < records.length; i++) {
|
|
158
|
+
const prev = records[i - 1];
|
|
159
|
+
const curr = records[i];
|
|
160
|
+
if (prev.time && curr.time && prev.time <= time && time <= curr.time) {
|
|
161
|
+
const span = curr.time.getTime() - prev.time.getTime();
|
|
162
|
+
const fraction = span > 0 ? (time.getTime() - prev.time.getTime()) / span : 0;
|
|
163
|
+
return {
|
|
164
|
+
lat: prev.lat + (curr.lat - prev.lat) * fraction,
|
|
165
|
+
lng: prev.lng + (curr.lng - prev.lng) * fraction,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
const first = records[0];
|
|
170
|
+
const last = records[records.length - 1];
|
|
171
|
+
return first.time && time <= first.time ? { lat: first.lat, lng: first.lng } : { lat: last.lat, lng: last.lng };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function pauseIcon() {
|
|
175
|
+
const svg =
|
|
176
|
+
'<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 22 22">' +
|
|
177
|
+
'<circle cx="11" cy="11" r="10" fill="#FB8C00" stroke="#ffffff" stroke-width="1.5"/>' +
|
|
178
|
+
'<rect x="7" y="6" width="3" height="10" rx="1" fill="#ffffff"/>' +
|
|
179
|
+
'<rect x="12" y="6" width="3" height="10" rx="1" fill="#ffffff"/>' +
|
|
180
|
+
'</svg>';
|
|
181
|
+
return {
|
|
182
|
+
url: 'data:image/svg+xml;charset=UTF-8,' + encodeURIComponent(svg),
|
|
183
|
+
scaledSize: new google.maps.Size(22, 22),
|
|
184
|
+
anchor: new google.maps.Point(11, 11),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function addPauseMarkers(records, pauses) {
|
|
189
|
+
clearPauseMarkers();
|
|
190
|
+
|
|
191
|
+
pauses.forEach(({ start, end }) => {
|
|
192
|
+
const position = findPositionAtTime(records, start);
|
|
193
|
+
const durationText = formatDuration((end - start) / 1000);
|
|
194
|
+
const marker = new Marker({
|
|
195
|
+
position,
|
|
196
|
+
map,
|
|
197
|
+
title: `Pause: ${durationText}`,
|
|
198
|
+
icon: pauseIcon(),
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
marker.addListener('click', () => {
|
|
202
|
+
infoWindow.setContent(`<div><strong>Pause</strong><br>${durationText}</div>`);
|
|
203
|
+
infoWindow.open({ map, anchor: marker });
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
pauseMarkers.push(marker);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function plotTrack(records, pauses, elevation, movingTimeLabel) {
|
|
211
|
+
if (currentPolyline) currentPolyline.setMap(null);
|
|
212
|
+
if (startMarker) startMarker.setMap(null);
|
|
213
|
+
if (endMarker) endMarker.setMap(null);
|
|
214
|
+
clearKmMarkers();
|
|
215
|
+
clearPauseMarkers();
|
|
216
|
+
|
|
217
|
+
const path = records.map((r) => ({ lat: r.lat, lng: r.lng }));
|
|
218
|
+
|
|
219
|
+
currentPolyline = new Polyline({
|
|
220
|
+
path,
|
|
221
|
+
geodesic: true,
|
|
222
|
+
strokeColor: '#EA4335',
|
|
223
|
+
strokeOpacity: 0.95,
|
|
224
|
+
strokeWeight: 4,
|
|
225
|
+
});
|
|
226
|
+
currentPolyline.setMap(map);
|
|
227
|
+
|
|
228
|
+
const bounds = new google.maps.LatLngBounds();
|
|
229
|
+
path.forEach((p) => bounds.extend(p));
|
|
230
|
+
map.fitBounds(bounds);
|
|
231
|
+
|
|
232
|
+
startMarker = new Marker({ position: path[0], map, label: 'S', title: 'Start' });
|
|
233
|
+
endMarker = new Marker({
|
|
234
|
+
position: path[path.length - 1],
|
|
235
|
+
map,
|
|
236
|
+
label: 'F',
|
|
237
|
+
title: 'Finish',
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
addKmMarkers(records, pauses);
|
|
241
|
+
addPauseMarkers(records, pauses);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// data.json's sport field is already one of 'running' / 'cycling' / 'moving'
|
|
245
|
+
// (see activity_to_json.py); this just turns it into a label for the stats bar.
|
|
246
|
+
function sportLabel(sport) {
|
|
247
|
+
return `${sport.charAt(0).toUpperCase()}${sport.slice(1)}`;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Derives the data file's URL from the page's own location by swapping its
|
|
251
|
+
// .html extension for .json - e.g. index.html loads index.json, foo.html
|
|
252
|
+
// loads foo.json - so the data file's name never has to be hardcoded here.
|
|
253
|
+
function dataUrlFromLocation(location) {
|
|
254
|
+
return location.pathname.replace(/\.html?$/i, '.json');
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
async function loadData(location) {
|
|
258
|
+
const dataUrl = dataUrlFromLocation(location);
|
|
259
|
+
try {
|
|
260
|
+
const response = await fetch(dataUrl);
|
|
261
|
+
if (!response.ok) {
|
|
262
|
+
throw new Error(`Failed to fetch ${dataUrl} (HTTP ${response.status})`);
|
|
263
|
+
}
|
|
264
|
+
const data = await response.json();
|
|
265
|
+
|
|
266
|
+
const records = data.records.map((r) => ({
|
|
267
|
+
lat: r.lat,
|
|
268
|
+
lng: r.lng,
|
|
269
|
+
time: r.time ? new Date(r.time) : undefined,
|
|
270
|
+
ele: r.ele === null || r.ele === undefined ? undefined : r.ele,
|
|
271
|
+
}));
|
|
272
|
+
if (records.length === 0) {
|
|
273
|
+
throw new Error(`No GPS records found in ${dataUrl}.`);
|
|
274
|
+
}
|
|
275
|
+
const pauses = data.pauses.map((p) => ({ start: new Date(p.start), end: new Date(p.end) }));
|
|
276
|
+
|
|
277
|
+
plotTrack(records, pauses, data.elevation, sportLabel(data.sport));
|
|
278
|
+
} catch (err) {
|
|
279
|
+
console.error(err);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function loadGoogleMapsApiKey() {
|
|
284
|
+
const response = await fetch('gmapikey.json');
|
|
285
|
+
if (!response.ok) {
|
|
286
|
+
throw new Error(`Failed to fetch gmapikey.json (HTTP ${response.status})`);
|
|
287
|
+
}
|
|
288
|
+
const { key } = await response.json();
|
|
289
|
+
if (!key) {
|
|
290
|
+
throw new Error('gmapikey.json is missing a "key" field.');
|
|
291
|
+
}
|
|
292
|
+
return key;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// location: the page's own Location object (e.g. document.location), passed
|
|
296
|
+
// in by the HTML that loads this module - see dataUrlFromLocation above.
|
|
297
|
+
async function init(location) {
|
|
298
|
+
let key;
|
|
299
|
+
try {
|
|
300
|
+
key = await loadGoogleMapsApiKey();
|
|
301
|
+
} catch (err) {
|
|
302
|
+
console.error(err);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
window.initGoogleMapsLoader({ key });
|
|
306
|
+
|
|
307
|
+
const mapsLibrary = await google.maps.importLibrary('maps');
|
|
308
|
+
const markerLibrary = await google.maps.importLibrary('marker');
|
|
309
|
+
Polyline = mapsLibrary.Polyline;
|
|
310
|
+
InfoWindow = mapsLibrary.InfoWindow;
|
|
311
|
+
Marker = markerLibrary.Marker;
|
|
312
|
+
// World view until a track is loaded; plotTrack then fits the map to it.
|
|
313
|
+
map = new mapsLibrary.Map(mapElement, {
|
|
314
|
+
center: { lat: 20, lng: 0 },
|
|
315
|
+
zoom: 2,
|
|
316
|
+
mapTypeId: 'terrain',
|
|
317
|
+
});
|
|
318
|
+
// headerDisabled removes the InfoWindow's reserved title/close-button row,
|
|
319
|
+
// which otherwise leaves a blank strip above short content like ours.
|
|
320
|
+
infoWindow = new InfoWindow({ headerDisabled: true });
|
|
321
|
+
map.addListener('click', () => infoWindow.close());
|
|
322
|
+
|
|
323
|
+
await loadData(location);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export { init };
|