Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bespoke Swim App

Instead of giving out about the Swim App, I am wondering if I can write my own.

I'm really just looking for a data logger while in the pool which sends on the recorded sensor samples over to a companion which can then be analysed post-workout (in Excel?)

I understand the reservations about getting HR data in the pool but by Inspire HR does a pretty good job of tracking HR while swimming (if the strap is tight enough) but I can only use it to get real-time readings and I can't get a profile - especially if it auto-detects Swim activity.

So I'm thinking of upgrading to a Versa 3 and writing an app:

  • Logging HR data if available at a set sample rate
  • Logging accelerometer data at a set sample rate
  • Transferring the data to a companion and on to somewhere it can be imported and analysed.

The big issue for me with swim apps is dealing with intervals: so I typically swim a short rep (eg 100m) then take a short rest (eg 10s) and then repeat.  If I can use the movement data to detect rest intervals, I'd like to be able to time the rep (time between resting period, whole seconds is enough) and if I can sync to HR data then that would be idea (HR max/average during rep, HR profile during rest interval).

So initially I'd like to just log movement and HR data and analyse post-workout.  Potentially this could develop to display 'last rep time' & HR profiling / zoning if I get in to this.

At this stage I'm looking for general advice, experience and encouragement before I upgrade my fitbit.

It looks like I should log to a file on the fitbit and transfer the data with the file transfer API?

Is it worth chunking the data or just wait til the end (up to 60 mins) and send it in one go?

Is the Versa 3 a good choice for this?

 

Best Answer
0 Votes
6 REPLIES 6

This would be an interesting but difficult project. I've been toying with similar ideas.

I've looked at heart rate data collected while swimming, and I agree that it looks usable.

Data storage, communications and access would require careful thought. I recommend doing some rough calculations on file sizes and transfer times to verify that your proposed approach is realistic. Some considerations:

  • The watch would need to store the data internally during a swim, and internal storage is limited. You should be okay up to about 10MB.
  • File transfers between watch and companion are fairly slow (around 1 kB/sec). It can take longer to transmit data than it does to record it. Perhaps because of this, it's best to break up transfers into smallish files. Sending data in binary with limited precision can speed things up dramatically.
  • Getting the data out of the companion (phone) is tricky because you can't store the file to the phone's file system. You have to use fetch() to send it to a web server (which could be a separate app running on your phone, or internet-hosted).
  • Depending on what you do for a server, an additional step might be required to get the data from the server to your Excel machine.
  • If you format the data into .CSV (which is easy enough), Excel can open it.

You can get heart rate data from the Web API, which is easier (except for OAuth), but you can't get accelerometer therefrom.

 

Accelerometer data can be tricky to interpret, because it always includes gravity (so reads 1g when at rest). Moreover, Versa 3 doesn't know which way up it is, so you can't easily just subtract 1g. Sense (and some older devices) also have an orientation sensor, but the co-ordinate system used may not provide enough information to allow g to be removed. If you're only interested in accelerometer patterns rather than absolute accelerations in earth-oriented directions, this may not matter.

Peter McLennan
Gondwana Software
Best Answer
0 Votes
Hi, thanks for your fab answer. It's helped a lot.
So I reckon that, worst case, the watch saves the timestamp, HR sample and
x,y,z accelerometer samples as CSV, you're looking at under 200kB of text
data in an hour session @ 1 sample per second. (I mocked up a CSV in Excel)
You could optimise this by pushing more of the 'is resting' logic to the
watch. Saving as a binary file and getting the companion to convert to CSV
will bring it down to about 20kB or less.
I have a decent enough web hosting package for my business so I think
setting up a sub-domain for the code to do the fetch() would be OK (with
some help). It would be nice to set up a Google Site to do it and access
the CSV direct in Sheets.
For the accelerometer data, my first guess would be that I can set up a
threshold on x-squared +y-squared + z-squard (maybe for two/three
consecutive samples) to detect rest periods. It might need something more
sophisticated but the initial plan would be to capture raw data and compare
how a couple of methods perform (knowing what actually happened during the
session).
I looked into the Web API for the Inspire HR and it seemed that you could
only pull the real-time HR if the device was actively connected to the App,
rather than pulling historical samples off the device? Am I wrong here?
Or is it different with the fitbit OS devices?
Either way it looks like I'm in the market for a new Versa 3 - worst case I
end up with a nice new smart watch!
Thanks again
Best Answer
0 Votes

I agree that it's probably viable.


I've got a spreadsheet of my own that does similar calculations. It probably raises more questions than it answers, but if interested, holler.


I'm mostly finished an Android app for capturing fetch() files from companion. I'll commit it here when it's cooked (ignore what's there at the moment). But since you've got a server, it would probably be easier to use php on that to do it.


This API might be helpful for analysing the accelerometer data. I think it was used in this app. The gent who wrote that is active in the Fitbit dev discord and may be willing to offer advice. But as you said originally, the first step is to get some data and see what it tells you.


I don't think the web API is going to give you real-time data at all; it's only updated after the watch syncs (ie, every 20 minutes or so on a good day). For your purpose, that's probably fine. The think the Web API behaves the same across devices, except that it has difficulty providing data that your watch doesn't collect. 🙂

 

I think it would be interesting to provide data on strokes per lap, stroke frequency, and the variation of those over time. It might even be possible to draw conclusions about smoothness of arm entry into water, elbow position, and other stroke shape characteristics. Getting good data for comparison would be a challenge.

Peter McLennan
Gondwana Software
Best Answer
0 Votes
Thanks for all that useful info. I'll take a look through the API you
referenced.
I can see lots of potential for the accelerometer data if you could sample
it frequently enough - and even more if you could analyse it in real time.
I think you'd be pushed to analyse stroke 'quality' numerically with the
individual variations in technique. A good coach will tell you what's
going on - and what to fix first - by eye.
As a 'more mature' swimmer, it would be interesting to measure stroke
degradation with fatigue - in terms of variation from your personal
baseline, or even just the start of the set - to warn against pushing the
stroke to breaking point, both in terms of loss of efficiency but also
injury risk.
I'll start with baby steps and see if I can get the data and make it
available off-line first.
WIth 5 months out of the water, I want to make sure I'm not over-doing it
(HR too high too early) and to be able to track progress week-on-week (rep
times)


Virus-free.
www.avg.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
Best Answer

What what it's worth, I just managed to capture and download a few laps of accelerometer data while swimming. I recorded at about 30 Hz. It's pretty easy to tell by eyeball when I finished each lap, and individual strokes are also easy to see. Finding mathematical expressions to pick out such features could be... interesting.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

For anyone still interested: we have just released an update to our Swim Trainer app for Versa 3 and Sense which now has an open water option. It includes open water tracking based on GPS:

https://swim-trainer.online/

Best Answer
0 Votes