Merge pull request #97 from voussoir/master

Replace 15s interval, 15m threshold with statistical formula.
master
y20k 2021-03-12 22:23:22 +01:00 committed by GitHub
commit 69828ee8e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 EMPTY_STRING_RESOURCE: Int = 0
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 STOP_OVER_THRESHOLD: Long = 300000L // 5 minutes in milliseconds
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.core.Track
import java.util.*
import kotlin.math.pow
/*
@ -179,17 +180,21 @@ object LocationHelper {
fun isDifferentEnough(previousLocation: Location?, location: Location): Boolean {
// check if previous location is (not) available
if (previousLocation == null) return true
// check if distance between is large enough
val distanceThreshold: Float
val averageAccuracy: Float = (previousLocation.accuracy + location.accuracy) / 2
// increase the distance threshold if one or both locations are
if (averageAccuracy > Keys.DEFAULT_THRESHOLD_DISTANCE) {
distanceThreshold = averageAccuracy
} else {
distanceThreshold = Keys.DEFAULT_THRESHOLD_DISTANCE
}
// location is different when far enough away from previous location
return calculateDistance(previousLocation, location) > distanceThreshold
// location.accuracy is given as 1 standard deviation, with a 68% chance
// that the true position is within a circle of this radius.
// These formulas determine if the difference between the last point and
// new point is statistically significant.
val accuracy = if (location.accuracy != 0.0f) location.accuracy else Keys.DEFAULT_THRESHOLD_DISTANCE
val previousAccuracy = if (previousLocation.accuracy != 0.0f) previousLocation.accuracy else Keys.DEFAULT_THRESHOLD_DISTANCE
val accuracyDelta = Math.sqrt((accuracy.pow(2) + previousAccuracy.pow(2)).toDouble())
val distance = calculateDistance(previousLocation, location)
// 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_app_version_summary">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_advanced_title">Advanced</string>
<string name="pref_delete_non_starred_summary">Delete all recordings in \"Tracks\" that are not starred.</string>