mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Add weoght parameter in TripStatisticsUpdater.addLocation() method.
This commit is contained in:
@@ -438,7 +438,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
double power = Double.NaN;
|
||||
|
||||
if (tripStatisticsUpdater != null) {
|
||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
|
||||
.getInt(getActivity(), R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
TripStatistics tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
if (chartByDistance) {
|
||||
double distance = tripStatistics.getTotalDistance() * UnitConversions.M_TO_KM;
|
||||
|
||||
@@ -247,8 +247,12 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
// No more track points. Ignore the rest of the waypoints.
|
||||
return;
|
||||
}
|
||||
trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval);
|
||||
markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval);
|
||||
trackTripStatisticstrackUpdater.addLocation(trackPoint, recordingDistanceInterval,
|
||||
PreferencesUtils.getInt(context, R.string.stats_weight_key,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
markerTripStatisticsUpdater.addLocation(trackPoint, recordingDistanceInterval,
|
||||
PreferencesUtils.getInt(context, R.string.stats_weight_key,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
}
|
||||
if (waypoint.getLocation().getTime() > trackPoint.getTime()) {
|
||||
trackPoint = null;
|
||||
@@ -534,7 +538,9 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
trackData.tripStatisticsUpdater = new TripStatisticsUpdater(
|
||||
location.getTime() != -1L ? location.getTime() : trackData.importTime);
|
||||
}
|
||||
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
trackData.tripStatisticsUpdater.addLocation(location, recordingDistanceInterval,
|
||||
PreferencesUtils.getInt(context, R.string.stats_weight_key,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
|
||||
trackData.bufferedLocations[trackData.numBufferedLocations] = location;
|
||||
trackData.numBufferedLocations++;
|
||||
|
||||
@@ -277,7 +277,8 @@ public class SendMapsAsyncTask extends AbstractSendAsyncTask {
|
||||
sentStartMarker = true;
|
||||
}
|
||||
|
||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
|
||||
.getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
if (i % elevationSamplingFrequency == 0) {
|
||||
distances.add(tripStatisticsUpdater.getTripStatistics().getTotalDistance());
|
||||
elevations.add(tripStatisticsUpdater.getSmoothedElevation());
|
||||
|
||||
@@ -659,9 +659,13 @@ public class TrackRecordingService extends Service {
|
||||
if (cursor.moveToLast()) {
|
||||
do {
|
||||
Location location = myTracksProviderUtils.createTrackPoint(cursor);
|
||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval,
|
||||
PreferencesUtils.getInt(context, R.string.stats_weight_key,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
if (location.getTime() > markerStartTime) {
|
||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval,
|
||||
PreferencesUtils.getInt(context, R.string.stats_weight_key,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
}
|
||||
} while (cursor.moveToPrevious());
|
||||
}
|
||||
@@ -1001,8 +1005,10 @@ public class TrackRecordingService extends Service {
|
||||
try {
|
||||
Uri uri = myTracksProviderUtils.insertTrackPoint(location, track.getId());
|
||||
long trackPointId = Long.parseLong(uri.getLastPathSegment());
|
||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||
trackTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
|
||||
.getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
markerTripStatisticsUpdater.addLocation(location, recordingDistanceInterval, PreferencesUtils
|
||||
.getInt(context, R.string.stats_weight_key, PreferencesUtils.STATS_WEIGHT_DEFAULT));
|
||||
updateRecordingTrack(track, trackPointId, LocationUtils.isValidLocation(location));
|
||||
} catch (SQLiteException e) {
|
||||
/*
|
||||
|
||||
@@ -142,8 +142,8 @@ public class StatsSettingsActivity extends AbstractSettingsActivity {
|
||||
weightInput.setSelectAllOnFocus(true);
|
||||
dialog = (new AlertDialog.Builder(this))
|
||||
.setMessage(R.string.settings_stats_calorie_weight_description)
|
||||
.setNegativeButton(getString(R.string.generic_cancel), null)
|
||||
.setPositiveButton(getString(R.string.generic_ok),
|
||||
.setNegativeButton(R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.generic_ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialogInterface, int number) {
|
||||
storeWeightValue(weightInput.getText().toString());
|
||||
|
||||
@@ -23,7 +23,6 @@ import static com.google.android.apps.mytracks.services.TrackRecordingService.PA
|
||||
import com.google.android.apps.mytracks.util.CalorieUtils;
|
||||
import com.google.android.apps.mytracks.util.CalorieUtils.ActivityType;
|
||||
import com.google.android.apps.mytracks.util.LocationUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
|
||||
import android.location.Location;
|
||||
@@ -126,7 +125,7 @@ public class TripStatisticsUpdater {
|
||||
* @param location the location
|
||||
* @param minRecordingDistance the min recording distance
|
||||
*/
|
||||
public void addLocation(Location location, int minRecordingDistance) {
|
||||
public void addLocation(Location location, int minRecordingDistance, int weight) {
|
||||
// Always update time
|
||||
updateTime(location.getTime());
|
||||
|
||||
@@ -196,7 +195,7 @@ public class TripStatisticsUpdater {
|
||||
|
||||
// Update calorie
|
||||
double calorie = CalorieUtils.getCalorie(lastMovingLocation, location,
|
||||
gradeBuffer.getAverage(), PreferencesUtils.STATS_WEIGHT_DEFAULT, ActivityType.FOOT);
|
||||
gradeBuffer.getAverage(), weight, ActivityType.FOOT);
|
||||
currentSegment.addCalorie(calorie);
|
||||
|
||||
lastLocation = location;
|
||||
|
||||
+9
-6
@@ -223,8 +223,9 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
// Each time slice is 10 seconds.
|
||||
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, MOVING_SPEED,
|
||||
startTime + (timeOffset + i) * TEN_SECONDS);
|
||||
tripStatisticsUpdater.addLocation(
|
||||
location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||
tripStatisticsUpdater.addLocation(location,
|
||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
|
||||
assertEquals((timeOffset + i) * TEN_SECONDS, tripStatistics.getTotalTime());
|
||||
@@ -269,8 +270,9 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
for (int i = 0; i < points; i++) {
|
||||
Location location = getLocation(
|
||||
locationOffset, locationOffset * .001, 0, startTime + (i + timeOffset) * TEN_SECONDS);
|
||||
tripStatisticsUpdater.addLocation(
|
||||
location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||
tripStatisticsUpdater.addLocation(location,
|
||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
||||
|
||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
assertEquals((i + timeOffset) * TEN_SECONDS, tripStatistics.getTotalTime());
|
||||
@@ -306,8 +308,9 @@ public class TripStatisticsUpdaterTest extends TestCase {
|
||||
// 99999 means a speed should bigger than given speed.
|
||||
Location location = getLocation(i + locationOffset, (i + locationOffset) * .001, 99999,
|
||||
startTime + (timeOffset + i) * TEN_SECONDS);
|
||||
tripStatisticsUpdater.addLocation(
|
||||
location, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||
tripStatisticsUpdater.addLocation(location,
|
||||
PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT,
|
||||
PreferencesUtils.STATS_WEIGHT_DEFAULT);
|
||||
tripStatistics = tripStatisticsUpdater.getTripStatistics();
|
||||
|
||||
assertTrue(tripStatistics.getMovingTime() <= tripStatistics.getTotalTime());
|
||||
|
||||
Reference in New Issue
Block a user