Fixing Garmin's Duration Bug in GoldenCheetah
Sometimes, my Garmin Forerunner 225 watch records a weird timejump in an activity (like a run). One second everything will be fine, the next second it adds millions of seconds to all the subsequent data points in the activity. When I notice this after importing the activity in GoldenCheetah, I am often unable to fix it there. The time column in the Edit tab does not show days, so I cannot fix them there. Instead, I end up fixing it in Vim using some find and replace magic. If you are not a Vim user, I am sure you can do something similar in your editor of choice.
Note: This method does not consider situations in which you stopped your watch for any period past the time bug. These will be scrubbed from the data.
To start off, if you care about your lap times, note them down now from the
GoldenCheetah overview. You will need the times later if you want to reinstate
them after you fixed the activity itself. Next, close GoldenCheetah and go to
your GoldenCheetah data folder (~/.goldencheetah
in my case). Go in the
folder of the correct athlete, then into their activities
folder. Open the
correct .json
file in Vim.
Find the spot in the file where the data points fuck up. Note down the line number lnr of the first broken line. Also note down the number of seconds nos from the line before it. Next, do a line select (Shift + v) of the offending line and all subsequent lines that have data points. Perform the following substitution.
:%s/"SECS":.\{-},/\=printf('"SECS":%d,', line('.') + nos + 1 - lnr)
\=printf
is your usual printf, the second argument passed to it will be the number of seconds for each lineline('.')
gives the current line number for the match- The addition and subtraction should put the correct second on each line using the nos and lnr you noted down.
This fixes your data points, now you just want to fix your lap times too. You can find these near the start of the file. Look at the number of seconds on the final data point final_s. Add one to this and use it as the end time for the final lap. Next, subtract the time you had noted down earlier for that final lap: final_s + 1 - final_lap_time. Use that number as the start of the final lap. Subtract one from that start to use as the end time for the lap before it. Subtract the time of the lap before it from the start of the final lap to find the start time of the lap before it: final_s + 1 - final_lap_time - lap_before_time. Continue this process till you reach the parts before the time jump. Save and double check things in GoldenCheetah.