Last active
January 22, 2018 20:50
-
-
Save ryanlitalien/3bec282887d9861b8da9b3e418cb9352 to your computer and use it in GitHub Desktop.
FinalSurge to TrainingPeaks converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Background: I needed to get FinalSurge workouts into TrainingPeaks | |
// Requires: | |
// * TrainingPeaks Javascript from: https://github.com/pchalacis/trainerroad-to-trainingpeaks | |
// * TrainingPeaks Premium account to add workouts | |
// Usage: | |
// * Make sure as many weeks are visible via the "weeks" button in calendar mode | |
// ** https://log.finalsurge.com/Calendar.cshtml?v=ws&vw=16b&y=2018&m=1&d=24 | |
// * Run script in console | |
// * Use "pchalacis/trainerroad-to-trainingpeaks" instructions | |
// ** Set date to 2018-01-01 (as array is 0 based and will add the day to the day of the workout) | |
Number.prototype.times = function(cb) { | |
var i = -1; | |
while (++i < this) { | |
cb(i); | |
} | |
return +this; | |
} | |
var types = { | |
"00000001-0001-0001-0001-000000000001": 'run', | |
"00000002-0002-0002-0002-000000000002": 'bike', | |
"00000003-0003-0003-0003-000000000003": 'swim', | |
"00000005-0005-0005-0005-000000000005": 'strength' | |
} | |
var data = {}; | |
(53).times(function(i){ | |
data[i] = { | |
"sunday": [], | |
"monday": [], | |
"tuesday": [], | |
"wednesday": [], | |
"thursday": [], | |
"friday": [], | |
"saturday": [] | |
} | |
}) | |
fetch('https://momentjs.com/downloads/moment.min.js') | |
.then(response => response.text()) | |
.then(text => eval(text)) | |
.then(function () { | |
$('a[data-description][data-description!=""]').each((key, value) => { | |
var parentDiv = $(value).closest('.calendarworkout'); | |
var date = parentDiv.data('date'); | |
var desc = $(value).data('description'); | |
var distance = $(value).data('pdist'); | |
var activityType = $(value).data('type'); | |
var name = $(value).data('name'); | |
var activityDuration = $(value).data('pduration'); | |
var paddedDuration = ""; | |
if ((activityDuration.split(":").length - 1) == 1) { | |
paddedDuration = "0:" + activityDuration; | |
} else if((activityDuration.split(":").length - 1) == 2) { | |
paddedDuration = activityDuration; | |
} else { | |
paddedDuration = "0:0:0"; | |
} | |
var duration = moment.duration(paddedDuration).asMinutes(); | |
var momentDate = moment(date); | |
var dayOfWeek = momentDate.format('dddd').toLowerCase(); | |
var weekOfYear = momentDate.format('W'); | |
var newActivity = { | |
type: types[activityType] || 'other', | |
title: name, | |
tss: 0, | |
description: desc, | |
distance: distance, | |
duration: duration | |
}; | |
var index = data[weekOfYear][dayOfWeek].findIndex(x => x.description==desc) | |
if (index === -1){ | |
data[weekOfYear][dayOfWeek].push(newActivity); | |
} | |
console.log(data[weekOfYear][dayOfWeek]); | |
}) | |
}) | |
console.log('var TRData = ' + JSON.stringify(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment