Code clean up

This commit is contained in:
Daniel Lisunkin committed 2019-05-23 12:18:29 +02:00
1 parent 9fe5824d79
commit 2b5989d42a
4 files changed
+47 -52

No files matched your search

@@ -45,7 +45,6 @@ public class TestORCPerformanceCurve {
@Test
public void testLagrangeInterpolation() throws FunctionEvaluationException {
// Moqutio? Or use just a normal Certificate from Import?
Double accuracy = 0.21;
ORCCertificateImpl certificate = (ORCCertificateImpl) importer.getCertificate("GER 5549");
ORCPerformanceCurveImpl performanceCurve = (ORCPerformanceCurveImpl) certificate.getPerformanceCurve(course);
@@ -111,26 +110,4 @@ public class TestORCPerformanceCurve {
assertEquals(404.3, allowancesPerCourse.get(new KnotSpeedImpl(20)).asSeconds(), 0.1);
}
/*
@Test
public void testComplexConstructedCourse() throws FunctionEvaluationException {
ORCCertificateImpl certificate = importer.getCertificate("GER 5549");
ORCPerformanceCurveImpl performanceCurve = (ORCPerformanceCurveImpl) certificate.getPerformanceCurve();
assertNotNull(certificate);
assertNotNull(course);
assertNotNull(performanceCurve);
Map<Speed, Duration> allowancesPerCourse = performanceCurve.createAllowancesPerCourse(course);
assertNotNull(allowancesPerCourse);
assertEquals(446.8, allowancesPerCourse.get(new KnotSpeedImpl(20)).asSeconds(), 0.1);
assertEquals(778.4, allowancesPerCourse.get(new KnotSpeedImpl( 6)).asSeconds(), 0.1);
System.out.println(course.getTotalLength().getNauticalMiles());
System.out.println(performanceCurve.createAllowancesPerCourse(course));
}
*/
}
@@ -2,12 +2,10 @@ package com.sap.sailing.domain.orc.impl;
import java.util.Collections;
import java.util.HashMap;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.sap.sailing.domain.base.Competitor;
import com.sap.sailing.domain.common.impl.KnotSpeedImpl;
import com.sap.sailing.domain.orc.ORCCertificate;
import com.sap.sailing.domain.orc.ORCPerformanceCurve;
@@ -206,4 +204,16 @@ public class ORCCertificateImpl implements ORCCertificate {
// TODO Auto-generated method stub
return null;
}
public String getSailnumber() {
return sailnumber;
}
public String getBoatclass() {
return boatclass;
}
public Distance getLengthOverAll() {
return lengthOverAll;
}
}
@@ -1,6 +1,9 @@
package com.sap.sailing.domain.orc.impl;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -12,7 +15,6 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import com.sap.sailing.domain.common.impl.KnotSpeedImpl;
import com.sap.sailing.domain.common.impl.MeterDistance;
import com.sap.sailing.domain.orc.ORCCertificate;
import com.sap.sailing.domain.orc.ORCCertificateImporter;
@@ -37,7 +39,6 @@ import com.sap.sse.common.impl.DegreeBearingImpl;
public class ORCCertificateImporterJSON implements ORCCertificateImporter {
private Map<String, Object> data;
private static final int[] twsDistances = new int[] { 6, 8, 10, 12, 14, 16, 20 };
private static final String RUN = "Run";
private static final String BEAT = "Beat";
@@ -55,7 +55,7 @@ public class ORCPerformanceCurveImpl implements Serializable, ORCPerformanceCurv
*/
private transient Map<Speed, PolynomialFunctionLagrangeForm> lagrangePolynomialsPerTrueWindSpeed;
/*
/**
*
*/
private final ORCPerformanceCurveCourse course;
@@ -64,6 +64,11 @@ public class ORCPerformanceCurveImpl implements Serializable, ORCPerformanceCurv
* Accepts the simplified polar data, one "column" for each of the defined true wind speeds, where each column is a
* map from the true wind angle (here expressed as an object of type {@link Bearing}) and the {@link Duration} the
* boat is assumed to need at that true wind speed/angle for one nautical mile.
*
* @param twaAllowances
* @param beatAngles
* @param gybeAngles
* @param course
*/
public ORCPerformanceCurveImpl(Map<Speed, Map<Bearing, Duration>> twaAllowances, Map<Speed, Bearing> beatAngles,
Map<Speed, Bearing> gybeAngles, ORCPerformanceCurveCourse course) {
@@ -98,6 +103,11 @@ public class ORCPerformanceCurveImpl implements Serializable, ORCPerformanceCurv
return Collections.unmodifiableMap(writeableLagrange);
}
/**
*
* @return
* @throws FunctionEvaluationException
*/
public Map<Speed, Duration> createAllowancesPerCourse() throws FunctionEvaluationException {
Map<Speed, Duration> result = new HashMap<>();
Map<ORCPerformanceCurveLeg, Map<Speed, Duration>> allowancesPerLeg = new HashMap<>();
@@ -108,11 +118,9 @@ public class ORCPerformanceCurveImpl implements Serializable, ORCPerformanceCurv
for (Speed tws : ORCCertificateImpl.ALLOWANCES_TRUE_WIND_SPEEDS) {
Double allowancePerTws = 0.0;
for (Entry<ORCPerformanceCurveLeg, Map<Speed, Duration>> entry : allowancesPerLeg.entrySet()) {
allowancePerTws += Math.abs(entry.getValue().get(tws).asSeconds());
}
result.put(tws, Duration.ONE_SECOND.times(allowancePerTws));
}
@@ -169,35 +177,34 @@ public class ORCPerformanceCurveImpl implements Serializable, ORCPerformanceCurv
// LAGRANGE TEST BASE because of unusual implementation in ORC Pascal code
// public accessibility needed for tests, not part of the ORCPerformanceCurve contract
public Duration getLagrangeInterpolationPerTrueWindSpeedAndAngle(Speed trueWindSpeed, Bearing trueWindAngle) throws FunctionEvaluationException, IllegalArgumentException {
Duration result;
Bearing[] allowancesTrueWindAnglesWithBeatRun = (Bearing[]) ArrayUtils.addAll(new Bearing[] {beatAngles.get(trueWindSpeed)}, ArrayUtils.addAll(ORCCertificateImpl.ALLOWANCES_TRUE_WIND_ANGLES, new Bearing[] {gybeAngles.get(trueWindSpeed)}));
Bearing[] ALLOWANCES_TRUE_WIND_ANGLES = allowancesTrueWindAnglesWithBeatRun;
Bearing[] ALLOWANCES_TRUE_WIND_ANGLES = allowancesTrueWindAnglesWithBeatRun; //TODO Cleanup, after more information from ORC is available
Arrays.sort(ALLOWANCES_TRUE_WIND_ANGLES);
int j = -1;
for(int i = 0; i < ALLOWANCES_TRUE_WIND_ANGLES.length; i++) {
if(trueWindAngle.compareTo(ALLOWANCES_TRUE_WIND_ANGLES[i]) < 0) {
j = i;
int i = -1; //after the loop, i equals the next higher available polar data for the given TWA
for(int j = 0; j < ALLOWANCES_TRUE_WIND_ANGLES.length; j++) {
if(trueWindAngle.compareTo(ALLOWANCES_TRUE_WIND_ANGLES[j]) < 0) {
i = j;
break;
}
}
if (j < 0) {
return null;
if (i >= 0) {
int upperBound = Math.min(i + 1, ALLOWANCES_TRUE_WIND_ANGLES.length - 1);
int lowerBound = Math.max(i - 2, 0);
double[] xn = new double[upperBound - lowerBound + 1];
double[] yn = new double[upperBound - lowerBound + 1];
for (i = lowerBound; i <= upperBound; i++) {
xn[i-lowerBound] = ALLOWANCES_TRUE_WIND_ANGLES[i].getDegrees();
yn[i-lowerBound] = durationPerNauticalMileAtTrueWindAngleAndSpeed.get(trueWindSpeed).get(ALLOWANCES_TRUE_WIND_ANGLES[i]).asSeconds();
}
result = Duration.ONE_SECOND.times(new PolynomialFunctionLagrangeForm(xn, yn).value(trueWindAngle.getDegrees()));
} else {
result = null;
}
int ne = Math.min(j + 1, ALLOWANCES_TRUE_WIND_ANGLES.length - 1);
int ns = Math.max(j - 2, 0);
double[] xn = new double[ne - ns + 1];
double[] yn = new double[ne - ns + 1];
for (j = ns; j <= ne; j++) {
xn[j-ns] = ALLOWANCES_TRUE_WIND_ANGLES[j].getDegrees();
yn[j-ns] = durationPerNauticalMileAtTrueWindAngleAndSpeed.get(trueWindSpeed).get(ALLOWANCES_TRUE_WIND_ANGLES[j]).asSeconds();
}
return Duration.ONE_SECOND.times(new PolynomialFunctionLagrangeForm(xn, yn).value(trueWindAngle.getDegrees()));
return result;
}
// public accessibility needed for tests, not part of the ORCPerformanceCurve contract