fjlopezs / mytracks

Automatically exported from code.google.com/p/mytracks
0 stars 0 forks source link

Chart view shows repeated data #290

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Start recording
2. Look at the chart, close phone.
3. Look at the chart later.

What is the expected output?
A nice clean chart.

What do you see instead?
A chart where the initial data is repeated several times.

Please use labels and text to provide additional information.

Original issue reported on code.google.com by sandordo...@google.com on 1 Feb 2011 at 10:15

GoogleCodeExporter commented 9 years ago
I think I found the error.  You can see what I think will fix it here:
http://code.google.com/r/sandordornbush-bugfix-mac/source/detail?r=a48c8ca991f06
ea4d6b3f92c0df51756cf972f73

What I think was happening was this:
1. The chart would start loading all points.
2. As that happened new points would come in.  That would trigger a new thread 
to start reading the points again.  That would start at the current progress of 
the first thread.  
3. Thread one posts all of the data.
4. Thread two posts some subset of the data repeated.

My somewhat hacky solution is to synchronize the methods.  This should be a 
temporary fix until we use a proper iterator.

Please review asap.

Original comment by sandordo...@google.com on 4 Feb 2011 at 6:45

GoogleCodeExporter commented 9 years ago
I addressed the comments and came up with a new solution.  I unified all of the 
code so it is harder to make mistakes.  The issue I now believe has to do with 
ascending vs descending queries.

http://code.google.com/r/sandordornbush-bugfix-mac/source/detail?r=7175c1d9a61e5
921e27b425fe644c4e0bae74bc9

This is a log snippet that lead me to this solution.  Notice that the first 
query is:

_id>=1879

Followed by the query for:
_id<=2436

02-04 16:57:28.187 W/MyTracks( 8517): ChartActivity.onCreate
02-04 16:57:28.324 D/dalvikvm( 8517): GC_EXTERNAL_ALLOC freed 958K, 56% free 
3356K/7623K, external 3413K/3418K, paused 62ms
02-04 16:57:28.343 D/MyTracks( 8517): ChartActivity: ContentObserver.onChange
02-04 16:57:28.343 D/MyTracks( 8517): MyTracksMap: ContentObserver.onChange 
waypoints
02-04 16:57:28.343 D/MyTracks( 8517): Build query: SELECT * FROM tracks WHERE 
(_id=13) ORDER BY _id
02-04 16:57:28.347 D/MyTracks( 8517): Build query: SELECT * FROM trackpoints 
WHERE (trackid=13 AND _id>=1879) ORDER BY _id ASC LIMIT 1024
02-04 16:57:28.347 D/MyTracks( 8517): Build query: SELECT * FROM waypoints 
WHERE (trackid=13) ORDER BY _id ASC LIMIT 10000
02-04 16:57:28.593 D/MyTracks( 8517): ChartView.setDataPoints: 556
02-04 16:57:28.593 D/MyTracks( 8517): ChartView.addDataPoints: 0 + 556
02-04 16:57:28.609 D/MyTracks( 8517): Build query: SELECT * FROM waypoints 
WHERE (trackid=13) ORDER BY _id ASC LIMIT 10000
02-04 16:57:28.628 D/twcCurrentConditions(32241): updateLoc:94303
02-04 16:57:28.628 D/twcCurrentConditions(32241): Load:94303
02-04 16:57:28.640 D/twcCurrentConditions(32241): LoadingOldDataFromDB:94303
02-04 16:57:28.664 I/MyTracks( 8517): MyTracks: Updating chart last seen: 2435
02-04 16:57:28.664 D/MyTracks( 8517): Build query: SELECT * FROM tracks WHERE 
(_id=13) ORDER BY _id
02-04 16:57:28.675 D/MyTracks( 8517): Build query: SELECT * FROM trackpoints 
WHERE (trackid=13 AND _id<=2436) ORDER BY _id DESC LIMIT 9444
02-04 16:57:28.863 D/MyTracks( 8517): ChartView.addDataPoints: 556 + 557
02-04 16:57:28.878 I/MyTracks( 8517): MyTracks: Updated chart last seen: 2435

Original comment by sandordo...@google.com on 7 Feb 2011 at 4:08

GoogleCodeExporter commented 9 years ago
Sandor, thanks for digging into this bug.  The real issue was related to a 
regression I introduced a while back, when I started refactoring of iterator 
code.

The issue is in MyTracksProviderUtilsImpl.java in getLocationsCursor in the 
following fragment:
"descending ? "<=" : ">=", minTrackPointId);".

See the full code fragment below:

@Override
  public Cursor getLocationsCursor(long trackId, long minTrackPointId,
      int maxLocations, boolean descending) {
    String selection; 
    if (minTrackPointId >= 0) {
      selection = String.format("%s=%d AND %s%s%d",
          TrackPointsColumns.TRACKID, trackId, TrackPointsColumns._ID,
          descending ? "<=" : ">=", minTrackPointId);
    } else {
      selection = String.format("%s=%d", TrackPointsColumns.TRACKID, trackId);
    }

    String sortOrder = "_id " + (descending ? "DESC" : "ASC");
    if (maxLocations > 0) {
      sortOrder += " LIMIT " + maxLocations;
    }

    return contentResolver.query(TrackPointsColumns.CONTENT_URI, null, selection, null, sortOrder);
  }

Original comment by ba...@google.com on 7 Feb 2011 at 7:13

GoogleCodeExporter commented 9 years ago
My change actually had a bug.  I addressed the comments and fixed the chart 
scaling issue here:
http://code.google.com/r/sandordornbush-bugfix-mac/source/detail?r=424b2ad2ec1eb
6b0d0e129130ef54027956f4396

Original comment by sandordo...@google.com on 8 Feb 2011 at 5:55

GoogleCodeExporter commented 9 years ago

Original comment by sandordo...@google.com on 9 Feb 2011 at 4:16