From f540d2433b452bcee63f242e5a3cfb69be1c8db0 Mon Sep 17 00:00:00 2001 From: Emil Vanherp Date: Fri, 21 Mar 2025 23:00:55 +0100 Subject: [PATCH] Preserve lap information in PathSimplifier Keep the first and last location of a lap so lap times and distances are preserved when the path is simplified. --- app/src/main/org/runnerup/db/PathSimplifier.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/org/runnerup/db/PathSimplifier.java b/app/src/main/org/runnerup/db/PathSimplifier.java index 76e3a3163..6d98db403 100644 --- a/app/src/main/org/runnerup/db/PathSimplifier.java +++ b/app/src/main/org/runnerup/db/PathSimplifier.java @@ -149,7 +149,7 @@ public ArrayList getNoisyLocationIDsAsStrings(SQLiteDatabase db, long ac // columns to query from the "LOCATION" table in database String[] pColumns = { "_id", Constants.DB.LOCATION.LATITUDE, Constants.DB.LOCATION.LONGITUDE, - Constants.DB.LOCATION.TYPE + Constants.DB.LOCATION.TYPE, Constants.DB.LOCATION.LAP }; @@ -164,13 +164,16 @@ public ArrayList getNoisyLocationIDsAsStrings(SQLiteDatabase db, long ac idsStr = new ArrayList<>(); // Location IDs to remove from the activity ArrayList simplifiedIDs = new ArrayList<>(); + int lap = 0; + int lap_prev = -1; if (c.moveToFirst()) { do { int lstate = c.getInt(3); + lap = c.getInt(4); // Only TYPE_GPS locations are considered for simplification - if (lstate == Constants.DB.LOCATION.TYPE_GPS) { + if (lstate == Constants.DB.LOCATION.TYPE_GPS && lap == lap_prev) { // save ID of the location entry Location l = new Location(String.format(Locale.US, "%d", c.getInt(0))); // get location's coordinates @@ -179,8 +182,10 @@ public ArrayList getNoisyLocationIDsAsStrings(SQLiteDatabase db, long ac idsStr.add(l.getProvider()); locations.add(l); - } else if ((lstate == Constants.DB.LOCATION.TYPE_PAUSE) - || (lstate == Constants.DB.LOCATION.TYPE_END)) { + } else if (((lstate == Constants.DB.LOCATION.TYPE_PAUSE) + || (lstate == Constants.DB.LOCATION.TYPE_END)) + // also keep first and last location of a lap to preserve lap information + || ((lstate == Constants.DB.LOCATION.TYPE_GPS) && lap != lap_prev)) { // this is the end of a segment // simplify current segment @@ -190,6 +195,8 @@ public ArrayList getNoisyLocationIDsAsStrings(SQLiteDatabase db, long ac simplifiedIDs.add(sl.getProvider()); } + lap_prev = lap; + // start new segment locations = new ArrayList<>(); }