mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-30 17:36:40 +00:00
added a first test case for WindWithConfidence averaging
This commit is contained in:
1 parent
5acebef1a1
commit
8d073b612b
4 files changed
+45
-2
No files matched your search
@@ -12,6 +12,7 @@ import java.util.Set;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sap.sailing.domain.base.PositionWithConfidence;
|
||||
import com.sap.sailing.domain.base.impl.KnotSpeedWithBearingImpl;
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.base.impl.PositionWithConfidenceImpl;
|
||||
import com.sap.sailing.domain.base.impl.ScalablePosition;
|
||||
@@ -28,6 +29,11 @@ import com.sap.sailing.domain.confidence.HasConfidenceAndIsScalable;
|
||||
import com.sap.sailing.domain.confidence.ScalableValue;
|
||||
import com.sap.sailing.domain.confidence.Weigher;
|
||||
import com.sap.sailing.domain.confidence.impl.ScalableDoubleWithConfidence;
|
||||
import com.sap.sailing.domain.tracking.Wind;
|
||||
import com.sap.sailing.domain.tracking.WindWithConfidence;
|
||||
import com.sap.sailing.domain.tracking.impl.ScalableWind;
|
||||
import com.sap.sailing.domain.tracking.impl.WindImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.WindWithConfidenceImpl;
|
||||
|
||||
public class ConfidenceTest {
|
||||
private static class ScalableBearing implements ScalableValue<ScalableBearing, Bearing> {
|
||||
@@ -137,6 +143,23 @@ public class ConfidenceTest {
|
||||
assertNull(average);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAveragingWithTwoWinds() {
|
||||
WindWithConfidence<TimePoint> d1 = new WindWithConfidenceImpl<TimePoint>(new WindImpl(new DegreePosition(0, 0), new MillisecondsTimePoint(0),
|
||||
new KnotSpeedWithBearingImpl(10, new DegreeBearingImpl(90))), /* confidence */ 0.5, /* relativeTo */ new MillisecondsTimePoint(0));
|
||||
WindWithConfidence<TimePoint> d2 = new WindWithConfidenceImpl<TimePoint>(new WindImpl(new DegreePosition(1, 0), new MillisecondsTimePoint(20),
|
||||
new KnotSpeedWithBearingImpl(20, new DegreeBearingImpl(180))), /* confidence */ 0.5, /* relativeTo */ new MillisecondsTimePoint(20));
|
||||
ConfidenceBasedAverager<ScalableWind, Wind, TimePoint> averager = ConfidenceFactory.INSTANCE
|
||||
.createAverager(ConfidenceFactory.INSTANCE.createLinearTimeDifferenceWeigher(1000));
|
||||
List<WindWithConfidence<TimePoint>> list = Arrays.asList(d1, d2);
|
||||
HasConfidence<ScalableWind, Wind, TimePoint> average = averager.getAverage(list, new MillisecondsTimePoint(10));
|
||||
assertEquals(0.5, average.getObject().getPosition().getLatDeg(), 0.00000001);
|
||||
assertEquals(0.0, average.getObject().getPosition().getLngDeg(), 0.00000001);
|
||||
assertEquals(10, average.getObject().getTimePoint().asMillis());
|
||||
assertEquals(15, average.getObject().getKnots(), 0.00000001);
|
||||
assertEquals(135, average.getObject().getBearing().getDegrees(), 0.00000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAveragingWithTwoDoubles() {
|
||||
ScalableDoubleWithConfidence<TimePoint> d1 = new ScalableDoubleWithConfidence<TimePoint>(1., 0.5, null);
|
||||
|
||||
+10
@@ -7,6 +7,16 @@ import com.sap.sailing.domain.common.impl.RadianBearingImpl;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
import com.sap.sailing.domain.confidence.ScalableValue;
|
||||
|
||||
/**
|
||||
* Separately scales speed and bearing. Instead of considering speed and bearing a single vector that can be scaled, the
|
||||
* bearing is scaled separately, and the speed is scaled as a scalar value independently of the bearing. This is
|
||||
* particularly useful for {@link Wind} scaling where it makes more sense to average the wind speed independently of the
|
||||
* wind direction / bearing than adding up the "wind vectors" and averaging, which would reduce the resulting wind speed
|
||||
* for constant wind speeds across all fixes with different directions.
|
||||
*
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public class ScalableSpeedWithBearing implements ScalableValue<Triple<Speed, Double, Double>, SpeedWithBearing> {
|
||||
private final Speed speed;
|
||||
private final double sin;
|
||||
|
||||
+5
-2
@@ -7,8 +7,11 @@ public interface ConfidenceFactory {
|
||||
ConfidenceFactory INSTANCE = new ConfidenceBasedAveragerFactoryImpl();
|
||||
|
||||
/**
|
||||
* @param weigher used to determine the confidence of the elements to be averaged, relative to the reference point given
|
||||
* as parameter to {@link ConfidenceBasedAverager#getAverage(Iterable, Object)}.
|
||||
* @param weigher
|
||||
* used to determine the confidence of the elements to be averaged, relative to the reference point given
|
||||
* as parameter to {@link ConfidenceBasedAverager#getAverage(Iterable, Object)}. If <code>null</code>,
|
||||
* 1.0 will be assumed as default confidence for all values provided, regardless the reference point
|
||||
* relative to which the average is to be computed
|
||||
*/
|
||||
<ValueType, BaseType, RelativeTo> ConfidenceBasedAverager<ValueType, BaseType, RelativeTo> createAverager(Weigher<RelativeTo> weigher);
|
||||
|
||||
|
||||
@@ -6,6 +6,13 @@ import com.sap.sailing.domain.base.impl.ScalableSpeedWithBearing;
|
||||
import com.sap.sailing.domain.confidence.ScalableValue;
|
||||
import com.sap.sailing.domain.tracking.Wind;
|
||||
|
||||
/**
|
||||
* Wind values are scaled by separately scaling their speed and bearing, and separately scaling their time point, and separately
|
||||
* scaling their position. For the separate speed/bearing scaling see also {@link ScalableSpeedWithBearing}.
|
||||
*
|
||||
* @author Axel Uhl (d043530)
|
||||
*
|
||||
*/
|
||||
public class ScalableWind implements ScalableValue<ScalableWind, Wind> {
|
||||
private final ScalablePosition scalablePosition;
|
||||
private final double scaledTimePointSumInMilliseconds;
|
||||
|
||||
Reference in new issue
Block a user