Question

I'm trying to calculate the time interval for a given CMMotionActivity.
A CMMotionActivity is a CMLogItem subclass, and as such - has a the property: @property(readonly, nonatomic) NSTimeInterval timestamp.
This time stamp is defined as:

The time stamp is the amount of time in seconds since the phone booted.

CMMotionActivity also has the property @property(readonly, nonatomic) NSDate *startDate.
I'm trying to figure out what is the interval for a given activity, aiming to come up with how much time the user was running or walking.
I'm using historical data (not reading events in real time).
I tried calculating the difference between motion events, but that seems wrong as I'm getting events in 5 second intervals but sometimes in much larger intervals.
Is there a way to calculate the "endDate" for a given CMMotionActivity?
I can't seem to find a way to do that in a reliable method either by observing a single event or a chain of events.

Was it helpful?

Solution

I believe a CMMotionActivity is generated every time the state of motion changes. Assuming this, given two CMMMotionActivity objects you can calculate the duration between the two events thereby determining how long the activity of stationary/walking/running/driving/uknowning was.

OTHER TIPS

At least as of iOS 14, each CMMotionActivity appears to cover a period that is ended by the next CMMotionActivity record's .startDate.

Sometimes that next record will be another record with an indicated activity classification. At other times, especially if the classifier can't decide what the next activity is but knows the preceding activity has ended it will be a record with none of the activity bits set that only serves to end the preceding record.

For instance, record #1's stationary period below is ended by the unclassified record #2, whereas record #3's walking period is ended by record #4's stationary period starting:

CMMotionActivity <startDate,2021-02-22 12:01:22 +0000,confidence,2,unknown,0,stationary,1,walking,0,running,0,automotive,0,cycling,0>
CMMotionActivity <startDate,2021-02-22 12:51:17 +0000,confidence,2,unknown,0,stationary,0,walking,0,running,0,automotive,0,cycling,0>
CMMotionActivity <startDate,2021-02-22 12:51:24 +0000,confidence,2,unknown,0,stationary,0,walking,1,running,0,automotive,0,cycling,0>
CMMotionActivity <startDate,2021-02-22 12:52:08 +0000,confidence,2,unknown,0,stationary,1,walking,0,running,0,automotive,0,cycling,0>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top