Skip to content
This repository was archived by the owner on Aug 24, 2025. It is now read-only.

VERY EXPERIMENTAL: refactoring storage of pause and resume#553

Merged
dennisguse merged 18 commits into
mainfrom
pauseResume#316
Jan 24, 2021
Merged

VERY EXPERIMENTAL: refactoring storage of pause and resume#553
dennisguse merged 18 commits into
mainfrom
pauseResume#316

Conversation

@dennisguse
Copy link
Copy Markdown
Member

@dennisguse dennisguse commented Dec 22, 2020

For be able to recreate the TrackStatistics (export/import), we need to store some additional TrackPoints (aka track started, track ended) and these need to use the same base for timestamps (here device time; NOT GPS-provided time).

  • pause/resume TrackPoint type is stored in separate column (DB version 30)
  • (to be decided) downgrading from DB version 30 to 29 restores data correctly
  • automatic pause TrackPoints migrated to SEGMENT_END_AUTOMATIC (attached to next trackpoints)
  • device-time is used (instead of GPS time), but existing data is not updated
  • (only new tracks) add track start TrackPoint (type SEGMENT_START_MANUAL)
  • (only new tracks) add track start TrackPoint (type SEGMENT_END_MANUAL) on pressing pause/stop
  • export all SEGMENT_START_MANUAL (has no coordinates)
  • import all SEGMENT_START_MANUAL (the first location of a segment; if no coordinates are present otherwise SEGMENT_START_AUTOMATIC)
  • update OSMDashboard to use TrackPoint.type (as well as old interface; if not present for now)
  • finally: write documentation of internal data structures
  • TrackStatistics are now computed only using TrackPoints
  • Check using data set (@dennisguse)
  • Export only xml structures for data (e.g., speed) if it contains not only null

Cleanup:

  • gpsStatus.onLocationChanged(trackPoint); is called for each TrackPoint

Upgrade strategy:

  1. Release new version of OSMDashboard (Dashboard API changes w/ versioning)
  2. Release new version containing database upgrade/downgrade code only (first commit in this branch; version v3.14.2)
  3. Release new version with all changes (version v3.15.0)
    Add in release notes:
    • that this upgrade may be harmful and tracks should be exported first
    • that OSMDashboard needs to be upgraded to v2.9.0

@dennisguse dennisguse added the maintenance Required maintenance work label Dec 22, 2020
@dennisguse dennisguse force-pushed the pauseResume#316 branch 2 times, most recently from 0b59ea9 to dea0185 Compare December 25, 2020 18:32
@dennisguse dennisguse changed the title DO NOT MERGE: refactoring storage of pause and resume VERY EXPERIMENTAL: refactoring storage of pause and resume Dec 25, 2020
@dennisguse dennisguse force-pushed the pauseResume#316 branch 7 times, most recently from aeb5bd1 to bdf9c3d Compare January 1, 2021 19:04
@dennisguse dennisguse marked this pull request as ready for review January 1, 2021 19:06
@dennisguse
Copy link
Copy Markdown
Member Author

@rgmf @pstorch
Happy new year ;)

If you have some time (and data to lose), here is a first version to change the internal storage of TrackPoints, so that we can restore the TrackStatistics completely (export/import).
So, if you tests this using a real database, please get a backup first.
Hope nothing burns....

PS: Downgrading from DB version 30 to version 29 does not restore deleted RESUME trackpoints.
So, upgrade->downgrade will result in changed data.
Don't know if this is really worth doing it.

Anyhow: 🤞, but keep a 🧯 handy 😎

@pstorch
Copy link
Copy Markdown
Member

pstorch commented Jan 2, 2021

I think the update of the trackpoints table doesn't work. The latitude column is an integer not a double, so the where clause with 100.0 or 200.0 doesn't find anything.
When I look into the SQLite DB I see the type is still 0:

Screenshot from 2021-01-02 18-53-22
Screenshot from 2021-01-02 18-53-45

@dennisguse
Copy link
Copy Markdown
Member Author

@pstorch Thx; one of those face palm moments ;)

db.execSQL("ALTER TABLE trackpoints ADD COLUMN type TEXT CHECK(type IN (-2, -1, 0, 1))");
db.execSQL("UPDATE trackpoints SET type = -2, latitude = NULL, longitude = NULL WHERE latitude = 200.0");
db.execSQL("UPDATE trackpoints SET type = 1, latitude = NULL, longitude = NULL WHERE latitude = 100.0");
db.execSQL("UPDATE trackpoints SET type = -2, latitude = NULL, longitude = NULL WHERE latitude = 200");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not gonna work either. It should be 200 * 1E6 😉

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grummel ;)

@pstorch
Copy link
Copy Markdown
Member

pstorch commented Jan 3, 2021

PS: Downgrading from DB version 30 to version 29 does not restore deleted RESUME trackpoints.

I still don't get that "Downgrading". In which situation does this work? When I install the version from main branch (DB version 29), then the downgrade code from 30 to 29 is missing and the App is crashing. When I install the version from this branch it knows DB version 30 and doesn't downgrade either.

@dennisguse
Copy link
Copy Markdown
Member Author

@pstorch Valid point, for a downgrade we would need to release a new version with version=29 that has the downgrade code for version 30. Then we could allow a real downgrade for a latter version.
So, technically we never allowed downgrades (with db changes) so far...
Thanks for pointing that out! Did not occur to me until know.

@pstorch
Copy link
Copy Markdown
Member

pstorch commented Jan 4, 2021

The db migration to version 30 works now.

I did some tests with my 318 tracks in my OpenTracks (debug).

Before I started:

image

  • 246 trackpoints with latitude 200
  • 248 trackpoints with latitude 100
  • 738161 "normal" trackpoints

Then I stumbled upon the migration bug, so I started over with the old version reimporting the 318 tracks in a clean db. Interestingly it was a bit different now:

image

  • 219 trackpoints with latitude 200
  • 219 trackpoints with latitude 100
  • 738156 "normal" trackpoints

So I guess this export/reimport "cleaned" something up.

I installed the pauseResume branch and let the database migrate.

After that I got the same overall statistics:

image

and the trackpoints looked good:

  • 219 of type 1
  • 219 of type -2
  • 738156 "normal" trackpoints.

I exported the 318 track after the migration.

Then I cleaned up the data and started over with importing the 318 files before the migration:

image

Now I got:

  • 551 of type -1
  • 737605 of type 0

🤔 what happened here?

The last test was reimporting the migrated files back to a clean database.

Looks like something bad happening here:

image

  • 219 of type -2
  • 219 of type 1
  • 46127 of type 0

The pause/resume trackpoints match the initial values, but why are so many regular trackpoints lost?

@pstorch
Copy link
Copy Markdown
Member

pstorch commented Jan 4, 2021

I've started a similar branch on the OSMDashboard https://github.com/OpenTracksApp/OSMDashboard/tree/pauseResume to read this new column.

Unfortunately the ContentProvider PROJECTION isn't backward compatible with older OT versions. As soon as I add the new type column I don't get any trackpoints from the old OT anymore. So I had to set the PROJECTION to null for the time being.

We could add a version attribute into the API (as an Intent extra), so that the OSMDashboard can decide which PROJECTION to use.

@dennisguse
Copy link
Copy Markdown
Member Author

@pstorch Thanks for the test.
The migration does not update the trackstatistics (nor deletes tracks), so the migration in itself is only visible in the number of trackpoints and thus the aggregated stats will remain the same.
But there is an issue - I guess in the exporter; let me check.

About OSMDashboard integration: do you need to send a projection (i.e., non null)?
If yes, we can add a version attribute to the URI - no problem.

@pstorch
Copy link
Copy Markdown
Member

pstorch commented Jan 4, 2021

About OSMDashboard integration: do you need to send a projection (i.e., non null)?

No, it's not needed. It works with null. The only drawback is that then all columns are transferred, more than needed. Don't know if this has a performance/memory impact.

@dennisguse
Copy link
Copy Markdown
Member Author

@pstorch Adding a version as extra sounds good!

About the data import->export->import:
I checked the exporter and it looks fine.
And I am not really sure, how to proceed as in my simple test cases it is working as expected and with the original data, the imports look fine.
So, it must be some weird "feature" of export+import together and I am not sure, how to figure that one out.
Can you provide some test data?

@pstorch
Copy link
Copy Markdown
Member

pstorch commented Jan 5, 2021

Very strange: I tried to reproduce the last testcase (reimporting the migrated and exported tracks). Now it worked and the aggregated stats and the db trackpoints had the correct values.

Sorry for the confusion.

@rgmf
Copy link
Copy Markdown
Member

rgmf commented Jan 5, 2021

I get this error in 40 of my 161 tracks. I've not checked all the 40 files but the error is triggered in the files where there is a pause/restart:

Parser error: org.xml.sax.SAXException: Parsing error at line: 4380 column: 0.
Invalid location detected: time=1583051351000 (type=SEGMENT_START_AUTOMATIC(-1)): lat=100.0 lng=0.0

Here is the line when the error is triggered (with the context):

<trkpt  lat="100" lon="0">
<time>2020-03-01T08:29:11Z</time>
</trkpt>
<trkpt  lat="200" lon="0">
<time>2020-03-01T08:33:49.166Z</time>
</trkpt>

To reproduce:

  1. Install this branch.
  2. Export all tracks to GPX format.
  3. Import all tracks.
  4. Get this error.

Also, when you are recording then the intervals doesn't work. Maybe it needs to be refactored because intervals uses TrackPoints directly.

@dennisguse
Copy link
Copy Markdown
Member Author

@pstorch If you can reproduce it again (or some other weird behavior), let me know.

@rgmf Those trackpoints should not actually not have been exported - they should have become segment open/close. We can now either ignore these - or try to restore the segment. But those trackpoints have device time while the rest has GPS time.

@rgmf
Copy link
Copy Markdown
Member

rgmf commented Jan 7, 2021

@rgmf Those trackpoints should not actually not have been exported - they should have become segment open/close. We can now either ignore these - or try to restore the segment. But those trackpoints have device time while the rest has GPS time.

I see.

I guess it's not that important for now but I'd try to restore segments altough stats are not the same: better that than end up with errors.

I'll test import/export from this branch then ;)

@dennisguse dennisguse merged commit 376887c into main Jan 24, 2021
@dennisguse dennisguse deleted the pauseResume#316 branch January 24, 2021 20:37
pstorch added a commit to OpenTracksApp/OSMDashboard that referenced this pull request Jan 24, 2021
- read protocol version and choose right projection

OpenTracksApp/OpenTracks#553
@dennisguse dennisguse restored the pauseResume#316 branch January 24, 2021 20:54
@dennisguse
Copy link
Copy Markdown
Member Author

I missed to include the elevation_loss column in the db upgrade/downgrade for version 29/30.

@dennisguse
Copy link
Copy Markdown
Member Author

I fixed this and:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

maintenance Required maintenance work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants