Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions gpxmaker.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ const isoData = (d) => (new Date(d)).toISOString();

const handleFileSelect = (evt) => {
const files = evt.target.files; // FileList object
const bulk = document.getElementById('separate').checked
const cnt = files.length;

if (bulk && (cnt % 2 == 1)) {
document.getElementById('result').innerHTML = 'For bulk, you need to upload files in multiples of 2';
return;
}

// files is a FileList of File objects. List some properties.
const output = [];
Expand All @@ -38,18 +44,17 @@ const handleFileSelect = (evt) => {
return;
}

const finalize = (data) => {
const finalize = (data, idx) => {
//console.log('final data:', data);
let gpx = `<?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" 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">
<metadata>
<time>${isoData(Object.keys(data)[0] * 1000)}</time>
</metadata>
<trk>
<name>My New Ride</name>
<name>Run</name>
<type>1</type>
<trkseg>`;

Object.values(data).reduce(function(previousValue, currentValue, index, array){
//console.log('index', index, 'currentValue', currentValue);
if(currentValue.latitude && currentValue.longitude){
Expand Down Expand Up @@ -78,8 +83,13 @@ const handleFileSelect = (evt) => {
</trkseg>
</trk>
</gpx>`;
if (bulk) {
save('workout_' + ((idx+1)/2).toString() + '.gpx', gpx);
}
else {
save('workout.gpx', gpx);
}

save('workout.gpx', gpx);
}

Object.keys(files).map((key, idx) => {
Expand All @@ -106,9 +116,19 @@ const handleFileSelect = (evt) => {

Object.assign(merged, formatted_result);

if(cnt === idx + 1){
finalize(merged);
}
if (bulk){
if((cnt === idx + 1) || (idx % 2 == 1)){
finalize(merged, idx);
merged = {};
}
}
else {
if(cnt === idx + 1){
finalize(merged, idx);
}
}


}
fr.readAsText(f);

Expand Down
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<html>
<head>
<title>GPXmaker - Samsung Health json to GPX converter</title>

<meta charset="UTF-8">
<script type="text/javascript" src="gpxmaker.js"></script>
<link href="style.css" rel="stylesheet" type="text/css"/>
</head>
Expand All @@ -11,7 +11,8 @@ <h1>GPXmaker</h1>
<h2>Samsung Health json to GPX converter</h2>
<p>This script allows you to convert json data from Samsung Health (originally S Health) to GPX file for Strava in pure Javascript</p>
<p>For more details <a href="https://github.com/shaderzz/gpxmaker" target="_blank">Click here</a></p>

<input type="checkbox" id="separate" name="separate">
<label for="separate">Create separate .gpx files for each workout (sort files alphabetically and disable browser download confirmation)</label><br><br>
<div id="result"></div>

<label for="files" class="button file-upload">
Expand Down