0

I'm building an iOS app in which I need to save the timestamp of each step that the user makes. Im using CoreMotion CMPedometer, but the method startUpdates only outputs the total number of steps that the user did from a start time to a end time.

The workaround I am using is: in every block of returned steps I use the startDate and endDate, and calculate the number of seconds per step, and them set the timestamp of each step in a linear way using the seconds per step. Then, I set the next startDate equal to the endDate of the previous block. But this is not near precise, since no blocks are returned when there is no activity, resulting in wrong results.

Is there anyway I can get the exact step times? Or at least a more precise way?

pkamb
  • 33,281
  • 23
  • 160
  • 191
Johny Boy
  • 99
  • 8
  • I don't see how you could make this work with pedometerUpdates. There's a history API (https://developer.apple.com/documentation/coremotion/cmpedometer/1613946-querypedometerdatafromdate?language=objc) that lets you query past time intervals, you could try breaking the time period you're looking at into small chunks (like every 10 seconds?) and asking how many steps happened in that time period. Not sure if that is precise enough for you? – FeichengMaike Jun 10 '21 at 10:17

1 Answers1

1

This sounds like the classic "fencepost problem"

Let's say I am a very slow walker. From 9 am to 10 am I do 4 steps, then nothing between 10am and 11, then from 11 to 12 I do another 4 steps

From 9 to 10:

9       10
|1|2|3|4|

What would it mean for a step to have an instantaneous timestamp?

Step 1 is from 9am to 9:15am, or you could say 9:07.5 is when the leg is vertical? Or are we interested in the exact time when the foot first touches the floor, or when you are at an average point in your step when the leg is vertical? Or do we say step 1 was from 9:00 to 9:15, or more generally that I made 4 steps in 1 hour? And doing that also has the advantage that these time periods are computed properties and not stored Dates that don't add any information over the 'n steps in time interval' representation.

Why would you set the next startDate equal to the endDate of the previous block - people aren't always making steps... I didn't start my first step from 11 to 12 at 10 am, I started it at 11am, and it was finished at 11:15.

Shadowrun
  • 3,572
  • 1
  • 15
  • 13
  • I understand what you are saying, but I need it to be more precise. I set the new start date to the previous end date so I can have more precise values. The "default" start date is the moment you start running the listener so it never changes. For example, lets say I start the listener at 10:00. I would know that, for example, between 10:00 and 12:00 I gave 40 steps. But If I save the end date of each block, I could know in a better way how the user gave their steps. For example, if between 10-11 they gave 30 steps, by saving the end date I would know that between 11-12 was 10 steps. – Johny Boy Mar 09 '21 at 18:07
  • Ah OK I see. If you query healthkit for steps between 10:00 and 10:01 and it says you did 4 steps in that minute, that's different information from querying between 10:00 and 11:00 and getting 100 steps in the hour. A statistics/sampling/math problem of how to combine this information together... I don't know the answer – Shadowrun Mar 10 '21 at 09:07