dblock / slack-strava

(Re)Post Strava activities to Slack
https://slava.playplay.io
MIT License
37 stars 6 forks source link

Club and user activities may be duplicated #56

Closed dblock closed 5 years ago

dblock commented 5 years ago

image

https://www.strava.com/activities/1979758638 https://www.strava.com/clubs/nimble

dblock commented 5 years ago
#<ClubActivity _id: 5bf7376e617a6f00eddb2123, created_at: 2018-11-22 23:10:38 UTC, updated_at: 2018-11-22 23:10:44 UTC, strava_id: "260c7ad5f2193828a747c5e3dd9ccf1f", name: "Morning Run", distance: 10480.2, description: nil, moving_time: 3840.0, elapsed_time: 3840.0, average_speed: 2.7292187500000002, bragged_at: 2018-11-22 23:10:44 UTC, total_elevation_gain: 96.9, private: nil, type: "Run", _type: "ClubActivity", athlete_name: "Olivier R.", club_id: BSON::ObjectId('5bf60373617a6f00eddb1df7')>
#<UserActivity _id: 5bf7376d617a6f00eddb2120, created_at: 2018-11-22 23:10:37 UTC, updated_at: 2018-11-22 23:10:38 UTC, strava_id: "1979758638", name: "Morning Run", distance: 10480.2, description: nil, moving_time: 3840.0, elapsed_time: 3840.0, average_speed: 2.729, bragged_at: 2018-11-22 23:10:38 UTC, total_elevation_gain: 96.9, private: false, type: "Run", _type: "UserActivity", start_date: 2018-11-22 22:02:28 UTC, start_date_local: 2018-11-23 05:02:28 UTC, user_id: BSON::ObjectId('5bc9792bdfe37500ec41632b')>
dblock commented 5 years ago

The problem is that Strava API does not include the activity ID or the athlete ID in the club's activities (I asked about it). This makes finding whether the activity is a duplicate of another one already posted quite difficult.

Could turn off user activity notifications if you're subscribed to any club in the same channel, but we also have the same problem if a user belonging to multiple clubs - you'll get a notification per club.

olivierobert commented 5 years ago

@dblock The only workaround I could think of is to have a method to check if both activities are identical by comparing the activity data (pseudo code below):

def is_duplicate_update?
  club_activity.distance == user_activity.distance && 
  club_activity.elapsed_time == user_activity. elapsed_time &&
  club_activity.moving_time == user_activity.moving_time &&
  club_activity.average_speed == user_activity.average_speed && 
  club_activity.total_elevation_gain == user_activity.total_elevation_gain
end

Even for regular runners, it's close to impossible to have all of these elements matching at the same time.

dblock commented 5 years ago

@olivierobert This would have some false positives (no big deal), but would often be wrong when two people run together, posting 2 separate activities. I am just not sure it's worth it, yet.

dblock commented 5 years ago

I ended up implementing this in https://github.com/dblock/slack-strava/commit/c9ee1219245e123c40bb5b763a33d42668c73eda. Because club bragging happens after user bragging, it should work well enough until Strava gives us a better way to de-dup activities.