Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions app/src/main/org/runnerup/db/PathSimplifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public ArrayList<String> 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
};


Expand All @@ -164,13 +164,16 @@ public ArrayList<String> getNoisyLocationIDsAsStrings(SQLiteDatabase db, long ac
idsStr = new ArrayList<>();
// Location IDs to remove from the activity
ArrayList<String> 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
Expand All @@ -179,8 +182,10 @@ public ArrayList<String> 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
Expand All @@ -190,6 +195,8 @@ public ArrayList<String> getNoisyLocationIDsAsStrings(SQLiteDatabase db, long ac
simplifiedIDs.add(sl.getProvider());
}

lap_prev = lap;

// start new segment
locations = new ArrayList<>();
}
Expand Down