cancel
Showing results for 
Search instead for 
Did you mean: 

How to Associate a Strava Activity to Device Record

strideon
Mt. Kenya

In my app, athletes can connect their Strava, Garmin Connect and COROS accounts to, among other things, capture completed activities. So if they've connected both Strava and, say, Garmin, then when they complete workouts, we'll receive activity records from both accounts. Problem is we only want the workout to appear once in their calendars, and to accomplish this, I've used date/time and other logic to try to detect duplicates. But that isn't foolproof since start time, distance and completion time can all be different for the same workout.

Is there anything available in the Activity record that would definitively say which device activity record it's associated with, or is there a more robust way to associate the two records? I see there's an external_id field, but sometimes it references a ping record, sometimes it references a FIT file, and sometimes it's empty. It used to contain the Garmin activity ID which directly referenced the ID in Garmin's record, and that was perfect, but it doesn't seem to be happening anymore.

Thanks,

Louis
Strava Paid Subscriber

1 ACCEPTED SOLUTION

ActivityFix
Kilimanjaro

There isn't a 100% foolproof method. What I use is a combination of several methods, in this order:

  1. If external_id has the Garmin activity ID (and it matches an ID I received from Garmin) I use that.
  2. Second I try to match based on activity start time, I have a margin of error around that. I can't remember the exact number but it's something like +/- 20 seconds. If I get a single activity matching this, I use it.
  3. If #1 and #2 fail, I try to compare across other metrics like distance, start time, duration. I add a margin of error for all of these since Strava does its own processing of the data so it may not exactly match.

99% of the time one of the 3 will give a match. If they don't, there's not much that can be done so I give up.

The other interesting case is if the person is recording with two devices, e.g. a Garmin watch + Garmin edge, in which case you get two almost identical activities. My solution is to just take the first match but in your case you'd want both I guess?

View solution in original post

2 REPLIES 2

ActivityFix
Kilimanjaro

There isn't a 100% foolproof method. What I use is a combination of several methods, in this order:

  1. If external_id has the Garmin activity ID (and it matches an ID I received from Garmin) I use that.
  2. Second I try to match based on activity start time, I have a margin of error around that. I can't remember the exact number but it's something like +/- 20 seconds. If I get a single activity matching this, I use it.
  3. If #1 and #2 fail, I try to compare across other metrics like distance, start time, duration. I add a margin of error for all of these since Strava does its own processing of the data so it may not exactly match.

99% of the time one of the 3 will give a match. If they don't, there's not much that can be done so I give up.

The other interesting case is if the person is recording with two devices, e.g. a Garmin watch + Garmin edge, in which case you get two almost identical activities. My solution is to just take the first match but in your case you'd want both I guess?

Thanks for clarifying that we'll need to compare different types of values to link Strava records to device records. I was primarily using the start time with a 60 sec margin of error, which worked fine until we got a workout yesterday where the times between Garmin and Strava were somehow 5 minutes apart. I like the order of checks you have in place since it tries several ways to match records.

I haven't yet tested cases where an athlete records a workout on two different devices, but current logic will just choose the first record we receive from Garmin, similar to your process.