Skip to content

Commit

Permalink
Group 1 (#46)
Browse files Browse the repository at this point in the history
[Creating a pull request to merge group 1's changes into the main
branch.](#44)
  • Loading branch information
Reva-B98 authored Feb 17, 2024
2 parents 702866c + b088d99 commit bdec9f1
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 90 deletions.
10 changes: 0 additions & 10 deletions .idea/migrations.xml

This file was deleted.

1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,3 @@ dependencies {

androidTestUtil 'androidx.test:orchestrator:1.4.2'
}

Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void addTrackPoint_TestingTrack() {

assertEquals(2.5, statistics.getMinAltitude(), 0.01);
assertEquals(32.5, statistics.getMaxAltitude(), 0.01);
assertEquals(36, 0.01, statistics.getTotalAltitudeGain());
assertEquals(36, statistics.getTotalAltitudeGain(), 0.01);
assertEquals(36, statistics.getTotalAltitudeLoss(), 0.01);

assertEquals(11.85, statistics.getMaxSpeed().toMPS(), 0.01);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

public class ImportExportSettingsFragment extends PreferenceFragmentCompat {

private static final String TAG = ImportExportSettingsFragment.class.getSimpleName();

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ private void onUpgrade() {
switch (i) {
case 1 -> upgradeFrom0to1();
case 2 -> upgradeFrom1to2();
default -> throw new RuntimeException("Not implemented: upgrade to " + version);
default -> throw new UnsupportedOperationException("Upgrade to version " + version + " not implemented");

}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class SensorsSettingsFragment extends PreferenceFragmentCompat {

private final static String TAG = SensorsSettingsFragment.class.getSimpleName();
private static final String TAG = SensorsSettingsFragment.class.getSimpleName();

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class SettingsCustomLayoutEditActivity extends AbstractActivity implement

public static final String EXTRA_LAYOUT = "extraLayout";
private ActivitySettingsCustomLayoutBinding viewBinding;
private GridLayoutManager gridLayoutManager;
private SettingsCustomLayoutEditAdapter adapterFieldsVisible;
private SettingsCustomLayoutEditAdapter adapterFieldsHidden;
private String profile;
Expand All @@ -36,7 +35,8 @@ public class SettingsCustomLayoutEditActivity extends AbstractActivity implement
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

GridLayoutManager gridLayoutManager;

// Recycler view with visible stats.
RecordingLayout recordingLayout = getIntent().getParcelableExtra(EXTRA_LAYOUT);
profile = recordingLayout.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public int getPreferenceId() {
return preferenceIdentifier;
}

/**
* @deprecated (when, why, etc...)
*/
@Deprecated //TODO used to initialize before loading from preferences; should be loaded first
public static UnitSystem defaultUnitSystem() {
return METRIC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public abstract class BluetoothLeSensorPreference extends DialogPreference {

private static final int SENSOR_INTERNAL_RESOURCEID = R.string.value_internal_sensor;

public BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
protected BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

public BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr) {
protected BluetoothLeSensorPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public BluetoothLeSensorPreference(Context context, AttributeSet attrs) {
protected BluetoothLeSensorPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}

public BluetoothLeSensorPreference(Context context) {
protected BluetoothLeSensorPreference(Context context) {
super(context);
}

Expand Down
80 changes: 36 additions & 44 deletions src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class TrackStatistics {
private Duration movingTime;
// The maximum speed (meters/second) that we believe is valid.
private Speed maxSpeed;
private Float totalAltitudeGainMeters = null;
private Float totalAltitudeLossMeters = null;
private Float totalAltitudeGain_m = null;
private Float totalAltitudeLoss_m = null;
// The average heart rate seen on this track
private HeartRate avgHeartRate = null;

Expand All @@ -80,22 +80,22 @@ public TrackStatistics(TrackStatistics other) {
movingTime = other.movingTime;
maxSpeed = other.maxSpeed;
altitudeExtremities.set(other.altitudeExtremities.getMin(), other.altitudeExtremities.getMax());
totalAltitudeGainMeters = other.totalAltitudeGainMeters;
totalAltitudeLossMeters = other.totalAltitudeLossMeters;
totalAltitudeGain_m = other.totalAltitudeGain_m;
totalAltitudeLoss_m = other.totalAltitudeLoss_m;
avgHeartRate = other.avgHeartRate;
isIdle = other.isIdle;
}

@VisibleForTesting
public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGainMeters, Float totalAltitudeLossMeters) {
public TrackStatistics(String startTime, String stopTime, double totalDistance_m, int totalTime_s, int movingTime_s, float maxSpeed_mps, Float totalAltitudeGain_m, Float totalAltitudeLoss_m) {
this.startTime = Instant.parse(startTime);
this.stopTime = Instant.parse(stopTime);
this.totalDistance = Distance.of(totalDistance_m);
this.totalTime = Duration.ofSeconds(totalTime_s);
this.movingTime = Duration.ofSeconds(movingTime_s);
this.maxSpeed = Speed.of(maxSpeed_mps);
this.totalAltitudeGainMeters = totalAltitudeGainMeters;
this.totalAltitudeLossMeters = totalAltitudeLossMeters;
this.totalAltitudeGain_m = totalAltitudeGain_m;
this.totalAltitudeLoss_m = totalAltitudeLoss_m;
}

/**
Expand Down Expand Up @@ -137,22 +137,22 @@ public void merge(TrackStatistics other) {
altitudeExtremities.update(other.altitudeExtremities.getMin());
altitudeExtremities.update(other.altitudeExtremities.getMax());
}
if (totalAltitudeGainMeters == null) {
if (other.totalAltitudeGainMeters != null) {
totalAltitudeGainMeters = other.totalAltitudeGainMeters;
if (totalAltitudeGain_m == null) {
if (other.totalAltitudeGain_m != null) {
totalAltitudeGain_m = other.totalAltitudeGain_m;
}
} else {
if (other.totalAltitudeGainMeters != null) {
totalAltitudeGainMeters += other.totalAltitudeGainMeters;
if (other.totalAltitudeGain_m != null) {
totalAltitudeGain_m += other.totalAltitudeGain_m;
}
}
if (totalAltitudeLossMeters == null) {
if (other.totalAltitudeLossMeters != null) {
totalAltitudeLossMeters = other.totalAltitudeLossMeters;
if (totalAltitudeLoss_m == null) {
if (other.totalAltitudeLoss_m != null) {
totalAltitudeLoss_m = other.totalAltitudeLoss_m;
}
} else {
if (other.totalAltitudeLossMeters != null) {
totalAltitudeLossMeters += other.totalAltitudeLossMeters;
if (other.totalAltitudeLoss_m != null) {
totalAltitudeLoss_m += other.totalAltitudeLoss_m;
}
}
}
Expand Down Expand Up @@ -301,8 +301,8 @@ public double getMinAltitude() {
return altitudeExtremities.getMin();
}

public void setMinAltitude(double altitudeMeter) {
altitudeExtremities.setMin(altitudeMeter);
public void setMinAltitude(double altitude_m) {
altitudeExtremities.setMin(altitude_m);
}

public boolean hasAltitudeMax() {
Expand All @@ -317,8 +317,8 @@ public double getMaxAltitude() {
return altitudeExtremities.getMax();
}

public void setMaxAltitude(double altitudeMeter) {
altitudeExtremities.setMax(altitudeMeter);
public void setMaxAltitude(double altitude_m) {
altitudeExtremities.setMax(altitude_m);
}

public void updateAltitudeExtremities(Altitude altitude) {
Expand All @@ -334,45 +334,45 @@ public void setAverageHeartRate(HeartRate heartRate) {
}

public boolean hasTotalAltitudeGain() {
return totalAltitudeGainMeters != null;
return totalAltitudeGain_m != null;
}

@Nullable
public Float getTotalAltitudeGain() {
return totalAltitudeGainMeters;
return totalAltitudeGain_m;
}

public void setTotalAltitudeGain(Float totalAltitudeGainMeters) {
this.totalAltitudeGainMeters = totalAltitudeGainMeters;
public void setTotalAltitudeGain(Float totalAltitudeGain_m) {
this.totalAltitudeGain_m = totalAltitudeGain_m;
}

@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void addTotalAltitudeGain(float gain_m) {
if (totalAltitudeGainMeters == null) {
totalAltitudeGainMeters = 0f;
if (totalAltitudeGain_m == null) {
totalAltitudeGain_m = 0f;
}
totalAltitudeGainMeters += gain_m;
totalAltitudeGain_m += gain_m;
}

public boolean hasTotalAltitudeLoss() {
return totalAltitudeLossMeters != null;
return totalAltitudeLoss_m != null;
}

@Nullable
public Float getTotalAltitudeLoss() {
return totalAltitudeLossMeters;
return totalAltitudeLoss_m;
}

public void setTotalAltitudeLoss(Float totalAltitudeLossMeters) {
this.totalAltitudeLossMeters = totalAltitudeLossMeters;
public void setTotalAltitudeLoss(Float totalAltitudeLoss_m) {
this.totalAltitudeLoss_m = totalAltitudeLoss_m;
}

@VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
public void addTotalAltitudeLoss(float lossM) {
if (totalAltitudeLossMeters == null) {
totalAltitudeLossMeters = 0f;
public void addTotalAltitudeLoss(float loss_m) {
if (totalAltitudeLoss_m == null) {
totalAltitudeLoss_m = 0f;
}
totalAltitudeLossMeters += lossM;
totalAltitudeLoss_m += loss_m;
}

@Override
Expand All @@ -383,14 +383,6 @@ public boolean equals(Object o) {
return toString().equals(o.toString());
}

@Override
public int hashCode() {
final int primeNumber = 31;
int result = 1;
result = result * primeNumber + (startTime == null ? 0 : startTime.hashCode());
return result;
}

@NonNull
@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,36 @@ public void addTrackPoint(TrackPoint trackPoint) {
currentSegment.setAverageHeartRate(HeartRate.of(averageHeartRateBPM));
}

updateDistanceAndSpeed(trackPoint);
{
// Update total distance
Distance movingDistance = null;
if (trackPoint.hasSensorDistance()) {
movingDistance = trackPoint.getSensorDistance();
} else if (lastTrackPoint != null
&& lastTrackPoint.hasLocation()
&& trackPoint.hasLocation()) {
// GPS-based distance/speed
movingDistance = trackPoint.distanceToPrevious(lastTrackPoint);
}
if (movingDistance != null) {
currentSegment.setIdle(false);
currentSegment.addTotalDistance(movingDistance);
}

if (!currentSegment.isIdle() && !trackPoint.isSegmentManualStart()) {
if (lastTrackPoint != null) {
currentSegment.addMovingTime(trackPoint, lastTrackPoint);
}
}

if (trackPoint.getType() == TrackPoint.Type.IDLE) {
currentSegment.setIdle(true);
}

if (trackPoint.hasSpeed()) {
updateSpeed(trackPoint);
}
}

if (trackPoint.isSegmentManualEnd()) {
reset(trackPoint);
Expand All @@ -135,30 +164,6 @@ public void addTrackPoint(TrackPoint trackPoint) {
lastTrackPoint = trackPoint;
}

// Extracted method for updating total distance and speed
private void updateDistanceAndSpeed(TrackPoint trackPoint) {
Distance movingDistance = null;
if (trackPoint.hasSensorDistance()) {
movingDistance = trackPoint.getSensorDistance();
} else if (lastTrackPoint != null && lastTrackPoint.hasLocation() && trackPoint.hasLocation()) {
// GPS-based distance/speed
movingDistance = trackPoint.distanceToPrevious(lastTrackPoint);
}
if (movingDistance != null) {
currentSegment.setIdle(false);
currentSegment.addTotalDistance(movingDistance);
}
if (!currentSegment.isIdle() && !trackPoint.isSegmentManualStart() && lastTrackPoint != null) {
currentSegment.addMovingTime(trackPoint, lastTrackPoint);
}
if (trackPoint.getType() == TrackPoint.Type.IDLE) {
currentSegment.setIdle(true);
}
if (trackPoint.hasSpeed()) {
updateSpeed(trackPoint);
}
}

private void reset(TrackPoint trackPoint) {
if (currentSegment.isInitialized()) {
trackStatistics.merge(currentSegment);
Expand Down

0 comments on commit bdec9f1

Please sign in to comment.