mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 14:20:55 +00:00
added test for DSQ in results, also for total points and result
This commit is contained in:
1 parent
8d0c230dab
commit
96428f6df7
4 files changed
+87
-12
No files matched your search
+36
-12
@@ -2,6 +2,8 @@ package com.sap.sailing.odf.resultimport.test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
@@ -22,6 +24,8 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.sap.sailing.domain.common.CountryCodeFactory;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
@@ -32,6 +36,7 @@ import com.sap.sailing.odf.resultimport.CumulativeResultDocumentProvider;
|
||||
import com.sap.sailing.odf.resultimport.OdfBody;
|
||||
import com.sap.sailing.odf.resultimport.OdfBodyParser;
|
||||
import com.sap.sailing.odf.resultimport.ParserFactory;
|
||||
import com.sap.sailing.odf.resultimport.PointsResult;
|
||||
import com.sap.sailing.odf.resultimport.Skipper;
|
||||
import com.sap.sailing.odf.resultimport.impl.ScoreCorrectionProviderImpl;
|
||||
|
||||
@@ -75,7 +80,7 @@ public class ParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyStatus() throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
|
||||
public void testParserForLaserRegatta() throws FileNotFoundException, SAXException, IOException, ParserConfigurationException {
|
||||
OdfBodyParser parser = ParserFactory.INSTANCE.createOdfBodyParser();
|
||||
OdfBody body = parser.parse(getSampleInputStream(), SAMPLE_INPUT_NAME);
|
||||
assertNotNull(body);
|
||||
@@ -87,17 +92,36 @@ public class ParserTest {
|
||||
results.put(cumulativeResult.getCompetitorCode(), cumulativeResult);
|
||||
}
|
||||
}
|
||||
assertTrue(results.containsKey("1094919"));
|
||||
CumulativeResult resultsFor1094919 = results.get("1094919");
|
||||
assertEquals(1, Util.size(resultsFor1094919.getAthletes()));
|
||||
assertEquals("SLINGSBY Tom", resultsFor1094919.getAthletes().iterator().next().getName());
|
||||
assertEquals(Gender.M, resultsFor1094919.getAthletes().iterator().next().getGender());
|
||||
assertTrue(resultsFor1094919.getAthletes().iterator().next() instanceof Skipper);
|
||||
assertTrue(results.containsKey("262797"));
|
||||
CumulativeResult resultsFor262797 = results.get("262797");
|
||||
assertEquals(1, Util.size(resultsFor262797.getAthletes()));
|
||||
assertEquals("IGNATEV Ilia", resultsFor262797.getAthletes().iterator().next().getName());
|
||||
assertEquals(Gender.M, resultsFor262797.getAthletes().iterator().next().getGender());
|
||||
{
|
||||
assertTrue(results.containsKey("1094919"));
|
||||
CumulativeResult resultsFor1094919 = results.get("1094919");
|
||||
assertEquals(1, Util.size(resultsFor1094919.getAthletes()));
|
||||
assertEquals("SLINGSBY Tom", resultsFor1094919.getAthletes().iterator().next().getName());
|
||||
assertEquals(Gender.M, resultsFor1094919.getAthletes().iterator().next().getGender());
|
||||
assertTrue(resultsFor1094919.getAthletes().iterator().next() instanceof Skipper);
|
||||
assertEquals(18, resultsFor1094919.getPointsInMedalRace(), 0.00000001);
|
||||
assertSame(CountryCodeFactory.INSTANCE.getFromThreeLetterIOCName("AUS"), resultsFor1094919.getCountryCode());
|
||||
assertEquals(57, resultsFor1094919.getTotalPoints(), 0.00000001);
|
||||
assertEquals(43, ((PointsResult) resultsFor1094919.getResult()).getPoints(), 0.00000001);
|
||||
}
|
||||
{
|
||||
assertTrue(results.containsKey("262797"));
|
||||
CumulativeResult resultsFor262797 = results.get("262797");
|
||||
assertEquals(1, Util.size(resultsFor262797.getAthletes()));
|
||||
assertEquals("IGNATEV Ilia", resultsFor262797.getAthletes().iterator().next().getName());
|
||||
assertEquals(Gender.M, resultsFor262797.getAthletes().iterator().next().getGender());
|
||||
assertNull(resultsFor262797.getPointsInMedalRace());
|
||||
assertSame(CountryCodeFactory.INSTANCE.getFromThreeLetterIOCName("KGZ"), resultsFor262797.getCountryCode());
|
||||
assertEquals(471, resultsFor262797.getTotalPoints(), 0.00000001);
|
||||
assertEquals(422, ((PointsResult) resultsFor262797.getResult()).getPoints(), 0.00000001);
|
||||
}
|
||||
{
|
||||
assertTrue(results.containsKey("1060133"));
|
||||
CumulativeResult resultsFor1060133 = results.get("1060133");
|
||||
assertSame(MaxPointsReason.DSQ, Util.get(resultsFor1060133.getPointsAndRanksAfterEachRace(), 6).getC());
|
||||
assertEquals(50, Util.get(resultsFor1060133.getPointsAndRanksAfterEachRace(), 6).getA(), 0.0000001);
|
||||
assertEquals(Integer.valueOf(48), Util.get(resultsFor1060133.getPointsAndRanksAfterEachRace(), 6).getB());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
@@ -9,6 +9,9 @@ public interface CumulativeResult {
|
||||
|
||||
int getRank();
|
||||
|
||||
/**
|
||||
* Net result, after applying discards
|
||||
*/
|
||||
Result getResult();
|
||||
|
||||
int getSortOrder();
|
||||
@@ -32,4 +35,9 @@ public interface CumulativeResult {
|
||||
* with a {@link Skipper} and {@link Crewmember}s otherwise.
|
||||
*/
|
||||
Iterable<Athlete> getAthletes();
|
||||
|
||||
/**
|
||||
* Total points, before applying discards
|
||||
*/
|
||||
Double getTotalPoints();
|
||||
}
|
||||
+13
@@ -2,6 +2,7 @@ package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -91,5 +92,17 @@ public class CumulativeResultImpl extends AbstractNodeWrapper implements Cumulat
|
||||
+", race results: "+getPointsAndRanksAfterEachRace()+", medal race results: "+getPointsInMedalRace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getTotalPoints() {
|
||||
TreeMap<Integer, String> totalPoints = getExtendedResults("ER_SA").get("SA_TOTAL_POINTS");
|
||||
final Double result;
|
||||
if (totalPoints == null) {
|
||||
result = null;
|
||||
} else {
|
||||
result = Double.valueOf(totalPoints.firstEntry().getValue());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+30
@@ -2,6 +2,12 @@ package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.PointsResult;
|
||||
|
||||
/**
|
||||
* A point result is a net result, after applying discards. Two points results are euqal if their points are equal.
|
||||
*
|
||||
* @author Axel Uhl (D043530)
|
||||
*
|
||||
*/
|
||||
public class PointsResultImpl implements PointsResult {
|
||||
private final double points;
|
||||
|
||||
@@ -19,4 +25,28 @@ public class PointsResultImpl implements PointsResult {
|
||||
public String toString() {
|
||||
return ""+getPoints()+" points";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(points);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
PointsResultImpl other = (PointsResultImpl) obj;
|
||||
if (Double.doubleToLongBits(points) != Double.doubleToLongBits(other.points))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user