mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-10-10 07:36:29 +00:00
progress
This commit is contained in:
1 parent
606a0e974a
commit
67a4c090bd
107 files changed
+3474
-3948
No files matched your search
@@ -1,4 +1,63 @@
|
||||
import { parseGPX } from 'gpx';
|
||||
export const exampleGPXFile = parseGPX(
|
||||
`<?xml version="1.0" encoding="UTF-8"?><gpx creator="StravaGPX" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www.garmin.com/xmlschemas/GpxExtensionsv3.xsd http://www.garmin.com/xmlschemas/TrackPointExtension/v1 http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd http://www.garmin.com/xmlschemas/PowerExtension/v1 http://www.garmin.com/xmlschemas/PowerExtensionv1.xsd http://www.topografix.com/GPX/gpx_style/0/2 http://www.topografix.com/GPX/gpx_style/0/2/gpx_style.xsd" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns:gpxpx="http://www.garmin.com/xmlschemas/PowerExtension/v1" xmlns:gpx_style="http://www.topografix.com/GPX/gpx_style/0/2"><metadata><name>Example</name><author><name>gpx.studio</name><link href="https://gpx.studio"/></author><time>2023-08-20T12:42:07.000Z</time></metadata><trk><name>Example</name><type>cycling</type><trkseg><trkpt lat="48.745764" lon="-66.658624"><ele>290.4</ele><time>2022-12-31T23:00:00.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>18</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.745974" lon="-66.658127"><ele>292.8</ele><time>2022-12-31T23:00:14.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>18</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.746592" lon="-66.658472"><ele>303.6</ele><time>2022-12-31T23:00:46.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>18</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.748063" lon="-66.660451"><ele>331.8</ele><time>2022-12-31T23:02:31.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>19</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.749297" lon="-66.650629"><ele>366</ele><time>2022-12-31T23:05:46.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>22</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.751879" lon="-66.646183"><ele>371.2</ele><time>2022-12-31T23:07:04.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>22</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.754389" lon="-66.646388"><ele>376</ele><time>2022-12-31T23:08:01.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>22</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.755973" lon="-66.642677"><ele>376.6</ele><time>2022-12-31T23:09:01.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>21</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.756134" lon="-66.640854"><ele>377.6</ele><time>2022-12-31T23:09:27.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>20</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.759941" lon="-66.633175"><ele>376.8</ele><time>2022-12-31T23:11:23.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>20</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.765632" lon="-66.635593"><ele>410.6</ele><time>2022-12-31T23:14:38.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>23</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.764883" lon="-66.630508"><ele>390.4</ele><time>2022-12-31T23:15:42.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>23</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.772418" lon="-66.633652"><ele>419.8</ele><time>2022-12-31T23:19:41.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>19</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.775935" lon="-66.633982"><ele>430</ele><time>2022-12-31T23:21:25.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>19</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.779656" lon="-66.636621"><ele>430.2</ele><time>2022-12-31T23:23:04.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>18</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.780914" lon="-66.636833"><ele>431.2</ele><time>2022-12-31T23:23:32.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>18</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.7868" lon="-66.632505"><ele>434</ele><time>2022-12-31T23:26:05.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>17</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions></trkpt><trkpt lat="48.787548" lon="-66.632642"><ele>435.6</ele><time>2022-12-31T23:26:28.024Z</time><extensions><gpxtpx:TrackPointExtension><gpxtpx:atemp>17</gpxtpx:atemp></gpxtpx:TrackPointExtension></extensions>
Line truncated
|
||||
);
|
||||
/**
|
||||
* The statistics of an example file (a ride of 102 trackpoints with timestamps and temperatures),
|
||||
* for the pages that show the elevation profile and the statistics without a file: the home page
|
||||
* and the documentation. They are the ones that the engine computes for `example.gpx`, kept as
|
||||
* they are (see `example-data.ts`) so that the example does not need the engine.
|
||||
*/
|
||||
import type { GlobalStatistics, SelectionStatistics } from '$lib/engine';
|
||||
import { exampleData as data } from './example-data';
|
||||
|
||||
const length = data.lng.length;
|
||||
|
||||
// the values that are cumulative over the selection: those of a range are the difference of its ends
|
||||
const cumulative = {
|
||||
totalDistance: data.totalDistance,
|
||||
movingDistance: data.movingDistance,
|
||||
totalTime: data.totalTime,
|
||||
movingTime: data.movingTime,
|
||||
elevationGain: data.elevationGain,
|
||||
elevationLoss: data.elevationLoss,
|
||||
};
|
||||
|
||||
/** The statistics of the trackpoints from `start` to `end` (both included), as the engine does. */
|
||||
function slice(start: number, end: number): GlobalStatistics | undefined {
|
||||
if (!(start >= 0 && start <= end && end < length)) {
|
||||
return undefined;
|
||||
}
|
||||
const delta = (values: number[]) => values[end] - values[start];
|
||||
// the times are in ms, in seconds in the statistics; a range cannot last a negative time
|
||||
const totalTime = Math.max(0, delta(cumulative.totalTime));
|
||||
const movingTime = Math.max(0, delta(cumulative.movingTime));
|
||||
const totalDistance = delta(cumulative.totalDistance);
|
||||
const movingDistance = delta(cumulative.movingDistance);
|
||||
const hours = (ms: number) => ms / 3_600_000;
|
||||
return {
|
||||
...data.global,
|
||||
totalDistance,
|
||||
movingDistance,
|
||||
totalTime: totalTime / 1000,
|
||||
movingTime: movingTime / 1000,
|
||||
elevationGain: delta(cumulative.elevationGain),
|
||||
elevationLoss: delta(cumulative.elevationLoss),
|
||||
startTime: data.timestamps[start],
|
||||
endTime: data.timestamps[end],
|
||||
totalSpeed: totalTime > 0 ? totalDistance / hours(totalTime) : undefined,
|
||||
movingSpeed: movingTime > 0 ? movingDistance / hours(movingTime) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export const exampleStatistics: SelectionStatistics = {
|
||||
global: data.global,
|
||||
length,
|
||||
totalDistance: Float64Array.from(data.totalDistance),
|
||||
slope: Float64Array.from(data.slope),
|
||||
lng: Float64Array.from(data.lng),
|
||||
lat: Float64Array.from(data.lat),
|
||||
ele: Float64Array.from(data.ele),
|
||||
timestamps: BigInt64Array.from(data.timestamps, (time) => BigInt(time)),
|
||||
speed: Float64Array.from(data.speed),
|
||||
atemp: Float64Array.from(data.atemp),
|
||||
slopeSegmentSlope: Float64Array.from(data.slopeSegmentSlope),
|
||||
slopeSegmentDistance: Float64Array.from(data.slopeSegmentDistance),
|
||||
slice,
|
||||
};
|
||||
Reference in new issue
Block a user