jonasoreland / runnerup

A open source run tracker
GNU General Public License v3.0
739 stars 275 forks source link

Run timings for intervals have become out of sync with those on the map after latest update #1138

Closed PhilArmstrong closed 1 year ago

PhilArmstrong commented 1 year ago

After the most recent update about 10 minutes into a run RunnerUp starts announcing that each kilometer takes about half the real wall clock time. On finishing the run, the laps recorded in the Laps tab of the history entry for the run after the first two are wrong but the lap markers on the Map tab have the correct times.

The time where the error starts to occur matches the point where the timeout is set on the phone to turn off the screen automatically. RunnerUp is marked as being allowed to use unrestricted battery when in the background in the App Settings.

This is happening on both mine & my partner’s phones. I’ve tried wiping the App data & caches but it hasn’t made any difference.

Any suggestions? Happy to contribute logs etc.

Phone: Pixel 4a, Android version 13.

gerhardol commented 1 year ago

Is the time in .tcx/.gpx correct? The time saved in the lap table is the activity time (from GPS or phone) minus the start time for the lap, so no extra counting.

A change in 2.5 is that the time on points uses system time rather than the GPS time (Some Samsungs had incorrect GPS time). If you set "Time from GPS" in sensors, do you get the same?

conceivably commented 1 year ago

I haven't had a chance to check the .tcx/.gpx time or setting "Time from GPS" yet (hoping to give that a try this weekend), but as another data point I'm experiencing the same issue on my Pixel 4a, Android 13.

nealcox commented 1 year ago

I have a similar problem with v2.5.0.7 with the timing of autolaps in Basic workouts: the time for each lap is too low (and the total time on the history page is too low - presumably the sum of the incorrect lap times). As above, the times on the map display look correct.

The times can be corrected by doing "Recompute activity". I won't attach a >30k line tcx file, but: `

grep -E "Lap StartTime|TotalTimeSeconds" RunnerUp_2023-03-19-15-40-09_Running.tcx ` gives

      <Lap StartTime="2023-03-19T15:41:09Z">
        <TotalTimeSeconds>317</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T15:47:27Z">
        <TotalTimeSeconds>318</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T15:53:15Z">
        <TotalTimeSeconds>203</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T15:58:47Z">
        <TotalTimeSeconds>174</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T16:04:21Z">
        <TotalTimeSeconds>153</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T16:09:49Z">
        <TotalTimeSeconds>214</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T16:15:14Z">
        <TotalTimeSeconds>199</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T16:20:46Z">
        <TotalTimeSeconds>196</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T16:26:08Z">
        <TotalTimeSeconds>231</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T16:31:47Z">
        <TotalTimeSeconds>254</TotalTimeSeconds>
      <Lap StartTime="2023-03-19T16:36:58Z">
        <TotalTimeSeconds>112</TotalTimeSeconds>

and after recomputing, diff RunnerUp_2023-03-19-15-40-09_Running.tcx RunnerUp_2023-03-19-15-40-09_Running_recomputed.tcx gives ` 7c7 < 317

>         <TotalTimeSeconds>377</TotalTimeSeconds>
3373c3373
<         <TotalTimeSeconds>318</TotalTimeSeconds>
---
>         <TotalTimeSeconds>349</TotalTimeSeconds>
6415c6415
<         <TotalTimeSeconds>203</TotalTimeSeconds>
---
>         <TotalTimeSeconds>332</TotalTimeSeconds>
9295c9295
<         <TotalTimeSeconds>174</TotalTimeSeconds>
---
>         <TotalTimeSeconds>334</TotalTimeSeconds>
12139c12139
<         <TotalTimeSeconds>153</TotalTimeSeconds>
---
>         <TotalTimeSeconds>328</TotalTimeSeconds>
15019c15019
<         <TotalTimeSeconds>214</TotalTimeSeconds>
---
>         <TotalTimeSeconds>325</TotalTimeSeconds>
17800c17800
<         <TotalTimeSeconds>199</TotalTimeSeconds>
---
>         <TotalTimeSeconds>332</TotalTimeSeconds>
20653c20653
<         <TotalTimeSeconds>196</TotalTimeSeconds>
---
>         <TotalTimeSeconds>322</TotalTimeSeconds>
23515c23515
<         <TotalTimeSeconds>231</TotalTimeSeconds>
---
>         <TotalTimeSeconds>339</TotalTimeSeconds>
26449c26449
<         <TotalTimeSeconds>254</TotalTimeSeconds>
---
>         <TotalTimeSeconds>311</TotalTimeSeconds>
29167,29168c29167,29168
<         <TotalTimeSeconds>112</TotalTimeSeconds>
<         <DistanceMeters>427.0</DistanceMeters>
---
>         <TotalTimeSeconds>128</TotalTimeSeconds>
>         <DistanceMeters>427.48270002007484</DistanceMeters>

`

I'll try setting "Time from GPS" and see if that makes a difference.

gerhardol commented 1 year ago

Is autopause enabled?

PhilArmstrong commented 1 year ago

Nope!

PhilArmstrong commented 1 year ago

The timestamps in the .gpx & .tcx files are fine.

But the TotalTimeSeconds entries in the .tcx file are completely wrong after the point where the phone goes to sleep.

 <Lap StartTime="2023-03-11T11:38:46Z">
    <TotalTimeSeconds>141</TotalTimeSeconds>
    <DistanceMeters>1000.9113420844078</DistanceMeters>
    <Calories>0</Calories>
    <Intensity>Active</Intensity>
    <TriggerMethod>Manual</TriggerMethod>
    <Track>
      <Trackpoint>
        <Time>2023-03-11T11:38:46Z</Time>
        <Position>
          <LatitudeDegrees>51</LatitudeDegrees>
          <LongitudeDegrees>-1</LongitudeDegrees>
        </Position>
        <AltitudeMeters>100</AltitudeMeters>
        <DistanceMeters>3001.35548878368</DistanceMeters>
        <Extensions>
          <ns3:TPX>
            <ns3:RunCadence>79</ns3:RunCadence>
          </ns3:TPX>
        </Extensions>
      </Trackpoint>
 ...
      <Trackpoint>
        <Time>2023-03-11T11:44:47Z</Time>
        <Position>
          <LatitudeDegrees>51</LatitudeDegrees>
          <LongitudeDegrees>-1</LongitudeDegrees>
        </Position>
        <AltitudeMeters>100</AltitudeMeters>
        <DistanceMeters>3999.250709957443</DistanceMeters>
        <Extensions>
          <ns3:TPX>
            <ns3:RunCadence>79</ns3:RunCadence>
          </ns3:TPX>
        </Extensions>
      </Trackpoint>
    </Track>
  </Lap>

So the TotalTimeSeconds measured for this km are completely wrong - whilst the GPS timestamps are good. (GPS locations edited to hide exact locations.)

PhilArmstrong commented 1 year ago

I’ll try setting “Time from GPS points” on my next run & see if it helps.

PhilArmstrong commented 1 year ago

Presumably the problem is occurring somewhere in this code from Tracker.java:

private void onLocationChangedImpl(Location arg0, boolean internal) {
        if (!mTimeFromGpsPoints || internal) {
            // Set internal time also if mBug23937Checked is not set
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                long now = System.nanoTime();
                arg0.setElapsedRealtimeNanos(now - mSystemToGpsDiffTimeNanos);
            } else {
                long now = System.currentTimeMillis();
                arg0.setTime(now - mSystemToGpsDiffTimeNanos / NANO_IN_MILLI);
            }

We shouldn’t be using System.nanoTime() for this purpose, the documention @ https://developer.android.com/reference/java/lang/System#nanoTime() says:

“The value returned by this method does not account for elapsed time during deep sleep. For timekeeping facilities available on Android see SystemClock.“

We probably want either [elapsedRealTime()](https://developer.android.com/reference/android/os/SystemClock#elapsedRealtime()) or [elapsedRealTimeNanos()](https://developer.android.com/reference/android/os/SystemClock#elapsedRealtimeNanos()) both of which measure time correctly across device sleep cycles.

PhilArmstrong commented 1 year ago

Totally untested patch: #1139

Upo commented 1 year ago

Just wanted to post an issue, but it is somehow solving. I recorded the same activity with 2.5.0.7 play (lower) and 2.4.5.0 F-Droid (upper) in a split screen session. I have both tcx files if needed. Screenshot_2023-03-17-18-55-44-577_org runnerup free

nealcox commented 1 year ago

I have done a run this morning, which I recorded in two parts. For the first part I set "Time from GPS" and the timings were correct. I went back to having "Time from GPS" unset for the second part and the timings were incorrect.

gerhardol commented 1 year ago

This is included in the open beta for the app in Play. Will roll out to all users when this is confirmed

PhilArmstrong commented 1 year ago

Will give it a try.

gerhardol commented 1 year ago

Any feedback on the Play update, time to release?

nealcox commented 1 year ago

I've been using it - all seems good with the timings.

gerhardol commented 1 year ago

Promoted in play, it can take a day or two until rolled out.

mmuehlenhoff commented 1 year ago

JFTR; I ran into this issue as well on the Fairphone 3+ and I can confirm that the update pushed to Beta resolves it. Thanks a lot!