fitbit-googlefit icon indicating copy to clipboard operation
fitbit-googlefit copied to clipboard

Exercise distance not sync'd

Open jikamens opened this issue 6 years ago • 1 comments

I told the FitBit app on my phone to track my bike ride, which it did successfully. After finishing the tracking on my app, FitBit correctly reports the total distance biked, so the information is definitely available in FitBit. However, after I use the code in this project to sync FitBit over to Google Fit, that exercise activity shows up with a distance of 0 miles. The whole reason why I'm trying to sync is because I want to track total distance for all activities (walking, biking, etc.) every day and FitBit refuses to do that, so I want to use Google Fit for it. If exercise distances aren't sync'd, alas the sync'ing is useless to me. :-/

jikamens avatar Jun 06 '18 15:06 jikamens

This seems to help, kind of, maybe, but I'm not certain:

diff --git a/remote.py b/remote.py
index ad9a639..5bbc739 100644
--- a/remote.py
+++ b/remote.py
@@ -259,6 +259,7 @@ class Remote:
 		# Fitbit activities list endpoint is in beta stage. It may break in the future and not directly supported
 		# by the python client library.
 		dataSourceId = self.convertor.GetDataSourceId('activity')
+		distanceDataSourceId = self.convertor.GetDataSourceId('distance')
 		if not callurl:
 			callurl = '{}/user/-/activities/list.json?afterDate={}&sort=asc&offset=0&limit=20'.format(self.FITBIT_API_URL,start_date)
 		activities_raw = self.ReadFromFitbit(self.fitbitClient.make_request, callurl)
@@ -279,6 +280,17 @@ class Remote:
 				)
 			self.WriteToGoogleFit(dataSourceId, [activity_segment])
 
+			if "distance" in activity:
+				if activity["distanceUnit"] != 'Mile':
+					raise Exception("Don't know how to deal with distance unit {}".format(
+						activity["distanceUnit"]))
+				distance_delta = dict(
+					dataTypeName='com.google.distance.delta',
+					startTimeNanos=activity_segment['startTimeNanos'],
+					endTimeNanos=activity_segment['endTimeNanos'],
+					value=[dict(fpVal=activity['distance'] * self.convertor.METERS_PER_MILE)])
+				self.WriteToGoogleFit(distanceDataSourceId, [distance_delta])
+
 			# Just for user output
 			startTimeMillis.append(google_session['startTimeMillis'])
 			endTimeMillis.append(google_session['endTimeMillis'])

Weirdly, it seems like activities sync'd with this patch show up in the Android Google Fit app but not on fit.google.com.

jikamens avatar Jun 06 '18 17:06 jikamens