Altitude correction of workout samples

This commit is contained in:
jannis 2020-03-07 19:48:23 +01:00
parent a26d6a748b
commit 3a22c97018
4 changed files with 65446 additions and 2 deletions

View File

@ -49,6 +49,30 @@
See the License for the specific language governing permissions and
limitations under the License.
<https://github.com/vectorstofinal/geoid_heights>
The MIT License (MIT)
Copyright (c) 2015 vectorstofinal
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
<https://github.com/westnordost/osmapi>
© 2016-2019 Tobias Zwick. This library is released under the terms of the GNU Lesser General Public License (LGPL).

View File

@ -23,12 +23,14 @@ import android.content.Context;
import android.hardware.SensorManager;
import android.util.Log;
import java.io.IOException;
import java.util.List;
import de.tadris.fitness.Instance;
import de.tadris.fitness.data.AppDatabase;
import de.tadris.fitness.data.Workout;
import de.tadris.fitness.data.WorkoutSample;
import de.tadris.fitness.util.AltitudeCorrection;
import de.tadris.fitness.util.CalorieCalculator;
class WorkoutSaver {
@ -51,7 +53,7 @@ class WorkoutSaver {
setSimpleValues();
setTopSpeed();
setRealElevation();
setElevation();
setAscentAndDescent();
setCalories();
@ -101,7 +103,27 @@ class WorkoutSaver {
workout.topSpeed= topSpeed;
}
private void setRealElevation(){
private void setElevation() {
setCorrectedElevation();
setPressureElevation();
}
private void setCorrectedElevation() {
// Please see the AltitudeCorrection.java for the reason of this
try {
int lat = (int) Math.round(samples.get(0).lat);
int lon = (int) Math.round(samples.get(0).lon);
AltitudeCorrection correction = new AltitudeCorrection(context, lat, lon);
for (WorkoutSample sample : samples) {
sample.elevation = correction.getHeightOverSeaLevel(sample.elevation);
}
} catch (IOException e) {
// If we can't read the file, we cannot correct the values
e.printStackTrace();
}
}
private void setPressureElevation() {
boolean pressureDataAvailable= samples.get(0).tmpPressure != -1;
if(!pressureDataAvailable){

View File

@ -0,0 +1,57 @@
package de.tadris.fitness.util;
import android.content.Context;
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import de.tadris.fitness.R;
/**
* This class has the task to correct the altitude.
* <p>
* In Germany or UK for example the GPS height differs
* roughly 50m from the real elevation over sea level.
* <p>
* The altitude given by GPS is the altitude over the WGS84 reference ellipsoid
* but we want the height over the sea level. That's why we have to correct the height.
* Luckily I found a file containing the corrections for all places around the world.
* <p>
* The geoids.csv is from https://github.com/vectorstofinal/geoid_heights licensed under MIT
*/
public class AltitudeCorrection {
private Context context;
private int latitude, longitude;
private double offset; // Basically how much higher the sea-level than the ellipsoid is
public AltitudeCorrection(Context context, int latitude, int longitude) throws IOException {
this.context = context;
this.latitude = latitude;
this.longitude = longitude;
findOffset();
}
private void findOffset() throws IOException {
InputStream inputStream = context.getResources().openRawResource(R.raw.geoids);
List<String> list = IOUtils.readLines(inputStream, StandardCharsets.UTF_8);
for (String line : list) {
String[] data = line.split(",");
int lat = Integer.parseInt(data[0]);
int lon = Integer.parseInt(data[1]);
double offset = Integer.parseInt(data[2]);
if (lat == this.latitude && lon == this.longitude) {
this.offset = offset;
return;
}
}
}
public double getHeightOverSeaLevel(double heightOverEllipsoid) {
return heightOverEllipsoid - offset;
}
}

File diff suppressed because it is too large Load Diff