mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-20 19:20:04 +00:00
fix for bug 4399, fixing failing tests by using Pair<Distance, Long> for cache
Change-Id: I16a74d96f8dabfc390c092355fa46fc2f4f878b7
This commit is contained in:
1 parent
7a7696626f
commit
550a402d0e
1 file changed
+16
-13
+16
-13
@@ -21,6 +21,7 @@ import com.sap.sailing.domain.tracking.Track;
|
|||||||
import com.sap.sailing.domain.tracking.TrackedRace;
|
import com.sap.sailing.domain.tracking.TrackedRace;
|
||||||
import com.sap.sse.common.Duration;
|
import com.sap.sse.common.Duration;
|
||||||
import com.sap.sse.common.TimePoint;
|
import com.sap.sse.common.TimePoint;
|
||||||
|
import com.sap.sse.common.Util.Pair;
|
||||||
import com.sap.sse.common.WithID;
|
import com.sap.sse.common.WithID;
|
||||||
import com.sap.sse.common.scalablevalue.ScalableValue;
|
import com.sap.sse.common.scalablevalue.ScalableValue;
|
||||||
|
|
||||||
@@ -39,7 +40,11 @@ public class BravoFixTrackImpl<ItemType extends WithID & Serializable> extends S
|
|||||||
|
|
||||||
private transient TimeRangeCache<Distance> foilingDistanceCache;
|
private transient TimeRangeCache<Distance> foilingDistanceCache;
|
||||||
|
|
||||||
private transient TimeRangeCache<Distance> averageRideHeightCache;
|
/**
|
||||||
|
* Caches the sum of the ride height of all fixes in the interval, paired with the number of fixes
|
||||||
|
* that constituted the basis for the ride height sum.
|
||||||
|
*/
|
||||||
|
private transient TimeRangeCache<Pair<Distance, Long>> averageRideHeightCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a GPS track was provided at construction time, remember it non-transiently. It is needed when restoring
|
* If a GPS track was provided at construction time, remember it non-transiently. It is needed when restoring
|
||||||
@@ -112,7 +117,7 @@ public class BravoFixTrackImpl<ItemType extends WithID & Serializable> extends S
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeRangeCache<Distance> createAverageRideHeightCache(ItemType trackedItem) {
|
private TimeRangeCache<Pair<Distance, Long>> createAverageRideHeightCache(ItemType trackedItem) {
|
||||||
return createTimeRangeCache(trackedItem, "averageRideHeightCache");
|
return createTimeRangeCache(trackedItem, "averageRideHeightCache");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,13 +182,15 @@ public class BravoFixTrackImpl<ItemType extends WithID & Serializable> extends S
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Distance getAverageRideHeight(TimePoint from, TimePoint to) {
|
public Distance getAverageRideHeight(TimePoint from, TimePoint to) {
|
||||||
return getValueSum(from, to, /* nullElement */ Distance.NULL, Distance::add, averageRideHeightCache,
|
final Pair<Distance, Long> nullElement = new Pair<>(Distance.NULL, 0l);
|
||||||
/* valueCalculator */ new Track.TimeRangeValueCalculator<Distance>() {
|
Pair<Distance, Long> rideHeightSumAndCount = getValueSum(from, to, nullElement,
|
||||||
|
(a, b)->new Pair<>(a.getA().add(b.getA()), a.getB()+b.getB()),
|
||||||
|
averageRideHeightCache,
|
||||||
|
/* valueCalculator */ new Track.TimeRangeValueCalculator<Pair<Distance, Long>>() {
|
||||||
@Override
|
@Override
|
||||||
public Distance calculate(TimePoint from, TimePoint to) {
|
public Pair<Distance, Long> calculate(TimePoint from, TimePoint to) {
|
||||||
Distance result;
|
|
||||||
Distance sum = Distance.NULL;
|
Distance sum = Distance.NULL;
|
||||||
int count = 0;
|
long count = 0;
|
||||||
for (final BravoFix fix : getFixes(from, true, to, true)) {
|
for (final BravoFix fix : getFixes(from, true, to, true)) {
|
||||||
final Distance rideHeight = fix.getRideHeight();
|
final Distance rideHeight = fix.getRideHeight();
|
||||||
if (rideHeight != null) {
|
if (rideHeight != null) {
|
||||||
@@ -191,14 +198,10 @@ public class BravoFixTrackImpl<ItemType extends WithID & Serializable> extends S
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (count > 0) {
|
return new Pair<>(sum, count);
|
||||||
result = sum.scale(1./count);
|
|
||||||
} else {
|
|
||||||
result = null;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return rideHeightSumAndCount.getB() == 0l ? null : rideHeightSumAndCount.getA().scale(1./(double) rideHeightSumAndCount.getB());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isFoiling(BravoFix fix) {
|
private boolean isFoiling(BravoFix fix) {
|
||||||
|
|||||||
Reference in new issue
Block a user