Replace 15s interval, 15m threshold with statistical formula.

These changes increase the rate at which points are recorded to
the track without decreasing track quality. Users with fine-grained
GPS units should see much more accurate tracks.
This commit is contained in:
voussoir 2021-03-12 11:53:33 -08:00
parent fa43dde017
commit d0f33b202a
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
3 changed files with 18 additions and 13 deletions

View file

@ -96,7 +96,7 @@ object Keys {
const val ONE_HOUR_IN_MILLISECONDS: Int = 3600000 const val ONE_HOUR_IN_MILLISECONDS: Int = 3600000
const val EMPTY_STRING_RESOURCE: Int = 0 const val EMPTY_STRING_RESOURCE: Int = 0
const val REQUEST_CURRENT_LOCATION_INTERVAL: Long = 1000L // 1 second in milliseconds const val REQUEST_CURRENT_LOCATION_INTERVAL: Long = 1000L // 1 second in milliseconds
const val ADD_WAYPOINT_TO_TRACK_INTERVAL: Long = 15000L // 15 seconds in milliseconds const val ADD_WAYPOINT_TO_TRACK_INTERVAL: Long = 1000L // 1 second in milliseconds
const val SIGNIFICANT_TIME_DIFFERENCE: Long = 120000L // 2 minutes in milliseconds const val SIGNIFICANT_TIME_DIFFERENCE: Long = 120000L // 2 minutes in milliseconds
const val STOP_OVER_THRESHOLD: Long = 300000L // 5 minutes in milliseconds const val STOP_OVER_THRESHOLD: Long = 300000L // 5 minutes in milliseconds
const val IMPLAUSIBLE_TRACK_START_SPEED: Double = 250.0 // 250 km/h const val IMPLAUSIBLE_TRACK_START_SPEED: Double = 250.0 // 250 km/h

View file

@ -27,6 +27,7 @@ import androidx.core.content.ContextCompat
import org.y20k.trackbook.Keys import org.y20k.trackbook.Keys
import org.y20k.trackbook.core.Track import org.y20k.trackbook.core.Track
import java.util.* import java.util.*
import kotlin.math.pow
/* /*
@ -179,17 +180,21 @@ object LocationHelper {
fun isDifferentEnough(previousLocation: Location?, location: Location): Boolean { fun isDifferentEnough(previousLocation: Location?, location: Location): Boolean {
// check if previous location is (not) available // check if previous location is (not) available
if (previousLocation == null) return true if (previousLocation == null) return true
// check if distance between is large enough
val distanceThreshold: Float // location.accuracy is given as 1 standard deviation, with a 68% chance
val averageAccuracy: Float = (previousLocation.accuracy + location.accuracy) / 2 // that the true position is within a circle of this radius.
// increase the distance threshold if one or both locations are // These formulas determine if the difference between the last point and
if (averageAccuracy > Keys.DEFAULT_THRESHOLD_DISTANCE) { // new point is statistically significant.
distanceThreshold = averageAccuracy val accuracy = if (location.accuracy != 0.0f) location.accuracy else Keys.DEFAULT_THRESHOLD_DISTANCE
} else { val previousAccuracy = if (previousLocation.accuracy != 0.0f) previousLocation.accuracy else Keys.DEFAULT_THRESHOLD_DISTANCE
distanceThreshold = Keys.DEFAULT_THRESHOLD_DISTANCE val accuracyDelta = Math.sqrt((accuracy.pow(2) + previousAccuracy.pow(2)).toDouble())
}
// location is different when far enough away from previous location val distance = calculateDistance(previousLocation, location)
return calculateDistance(previousLocation, location) > distanceThreshold
// With 1*accuracyDelta we have 68% confidence that the points are
// different. We can multiply this number to increase confidence but
// decrease point recording frequency if needed.
return distance > accuracyDelta
} }

View file

@ -76,7 +76,7 @@
<string name="pref_about_title">About</string> <string name="pref_about_title">About</string>
<string name="pref_app_version_summary">Version</string> <string name="pref_app_version_summary">Version</string>
<string name="pref_app_version_title">App Version</string> <string name="pref_app_version_title">App Version</string>
<string name="pref_accuracy_threshold_summary">Discard location fixes with an accuracy larger than:</string> <string name="pref_accuracy_threshold_summary">Discard location fixes with an accuracy larger than (meters):</string>
<string name="pref_accuracy_threshold_title">Accuracy Threshold</string> <string name="pref_accuracy_threshold_title">Accuracy Threshold</string>
<string name="pref_advanced_title">Advanced</string> <string name="pref_advanced_title">Advanced</string>
<string name="pref_delete_non_starred_summary">Delete all recordings in \"Tracks\" that are not starred.</string> <string name="pref_delete_non_starred_summary">Delete all recordings in \"Tracks\" that are not starred.</string>