src/main/java/de/dennisguse/opentracks/stats/TrackStatistics.java
public void merge(TrackStatistics other) {
        if (startTime == null) {
            startTime = other.startTime;
        } else {
            startTime = startTime.isBefore(other.startTime) ? startTime : other.startTime;
        }
        if (stopTime == null) {
            stopTime = other.stopTime;
        } else {
            stopTime = stopTime.isAfter(other.stopTime) ? stopTime : other.stopTime;
        }

        if (avgHeartRate == null) {
            avgHeartRate = other.avgHeartRate;
        } else {
            if (other.avgHeartRate != null) {
                // Using total time as weights for the averaging.
                // Important to do this before total time is updated
                avgHeartRate = HeartRate.of(
                        (totalTime.getSeconds() * avgHeartRate.getBPM() + other.totalTime.getSeconds() * other.avgHeartRate.getBPM())
                                / (totalTime.getSeconds() + other.totalTime.getSeconds())
                );
            }
        }

        totalDistance = totalDistance.plus(other.totalDistance);
        totalTime = totalTime.plus(other.totalTime);
        movingTime = movingTime.plus(other.movingTime);
        maxSpeed = Speed.max(maxSpeed, other.maxSpeed);
        if (other.altitudeExtremities.hasData()) {
            altitudeExtremities.update(other.altitudeExtremities.getMin());
            altitudeExtremities.update(other.altitudeExtremities.getMax());
        }
        if (totalAltitudeGain_m == null) {
            if (other.totalAltitudeGain_m != null) {
                totalAltitudeGain_m = other.totalAltitudeGain_m;
            }
        } else {
            if (other.totalAltitudeGain_m != null) {
                totalAltitudeGain_m += other.totalAltitudeGain_m;
            }
        }
        if (totalAltitudeLoss_m == null) {
            if (other.totalAltitudeLoss_m != null) {
                totalAltitudeLoss_m = other.totalAltitudeLoss_m;
            }
        } else {
            if (other.totalAltitudeLoss_m != null) {
                totalAltitudeLoss_m += other.totalAltitudeLoss_m;
            }
        }
    }
/**
     * Combines these statistics with those from another object.
     * This assumes that the time periods covered by each do not intersect.
     *
     * @param other another statistics data object
     */
Combines these statistics with those from another object.
This assumes that the time periods covered by each do not intersect.

@param other another statistics data object
Combines these statistics with those from another object . This assumes that the time periods covered by each do not intersect . @param other another statistics data object
public void merge(TrackStatistics other) {
        if (startTime == null) {
            startTime = other.startTime;
        } else {
            startTime = startTime.isBefore(other.startTime) ? startTime : other.startTime;
        }
        if (stopTime == null) {
            stopTime = other.stopTime;
        } else {
            stopTime = stopTime.isAfter(other.stopTime) ? stopTime : other.stopTime;
        }
        if (avgHeartRate == null) {
            avgHeartRate = other.avgHeartRate;
        } else {
            if (other.avgHeartRate != null) {
                avgHeartRate = HeartRate.of(
                        (totalTime.getSeconds() * avgHeartRate.getBPM() + other.totalTime.getSeconds() * other.avgHeartRate.getBPM())
                                / (totalTime.getSeconds() + other.totalTime.getSeconds())
                );
            }
        }
        totalDistance = totalDistance.plus(other.totalDistance);
        totalTime = totalTime.plus(other.totalTime);
        movingTime = movingTime.plus(other.movingTime);
        maxSpeed = Speed.max(maxSpeed, other.maxSpeed);
        if (other.altitudeExtremities.hasData()) {
            altitudeExtremities.update(other.altitudeExtremities.getMin());
            altitudeExtremities.update(other.altitudeExtremities.getMax());
        }
        if (totalAltitudeGain_m == null) {
            if (other.totalAltitudeGain_m != null) {
                totalAltitudeGain_m = other.totalAltitudeGain_m;
            }
        } else {
            if (other.totalAltitudeGain_m != null) {
                totalAltitudeGain_m += other.totalAltitudeGain_m;
            }
        }
        if (totalAltitudeLoss_m == null) {
            if (other.totalAltitudeLoss_m != null) {
                totalAltitudeLoss_m = other.totalAltitudeLoss_m;
            }
        } else {
            if (other.totalAltitudeLoss_m != null) {
                totalAltitudeLoss_m += other.totalAltitudeLoss_m;
            }
        }
    }
public void merge ( TrackStatistics other ) { if ( startTime == null ) { startTime = other . startTime ; } else { startTime = startTime . isBefore ( other . startTime ) ? startTime : other . startTime ; } if ( stopTime == null ) { stopTime = other . stopTime ; } else { stopTime = stopTime . isAfter ( other . stopTime ) ? stopTime : other . stopTime ; } if ( avgHeartRate == null ) { avgHeartRate = other . avgHeartRate ; } else { if ( other . avgHeartRate != null ) { avgHeartRate = HeartRate . of ( ( totalTime . getSeconds ( ) * avgHeartRate . getBPM ( ) + other . totalTime . getSeconds ( ) * other . avgHeartRate . getBPM ( ) ) / ( totalTime . getSeconds ( ) + other . totalTime . getSeconds ( ) ) ) ; } } totalDistance = totalDistance . plus ( other . totalDistance ) ; totalTime = totalTime . plus ( other . totalTime ) ; movingTime = movingTime . plus ( other . movingTime ) ; maxSpeed = Speed . max ( maxSpeed , other . maxSpeed ) ; if ( other . altitudeExtremities . hasData ( ) ) { altitudeExtremities . update ( other . altitudeExtremities . getMin ( ) ) ; altitudeExtremities . update ( other . altitudeExtremities . getMax ( ) ) ; } if ( totalAltitudeGain_m == null ) { if ( other . totalAltitudeGain_m != null ) { totalAltitudeGain_m = other . totalAltitudeGain_m ; } } else { if ( other . totalAltitudeGain_m != null ) { totalAltitudeGain_m += other . totalAltitudeGain_m ; } } if ( totalAltitudeLoss_m == null ) { if ( other . totalAltitudeLoss_m != null ) { totalAltitudeLoss_m = other . totalAltitudeLoss_m ; } } else { if ( other . totalAltitudeLoss_m != null ) { totalAltitudeLoss_m += other . totalAltitudeLoss_m ; } } }
Combines these statistics with those from another object.
Combines these statistics with those from another object .
// Using total time as weights for the averaging. // Important to do this before total time is updated