mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-10 14:20:55 +00:00
a first basic version of an ODF parser that doesn't yet adapt to ScoreCorrectionProvider
This commit is contained in:
1 parent
b82eabad19
commit
f2fdafa26d
32 files changed
+369
-589
No files matched your search
+5
@@ -64,4 +64,9 @@ public class CountryCodeImpl implements CountryCode {
|
||||
public String getITUCallPrefix() {
|
||||
return ituCallPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getThreeLetterIOCCode();
|
||||
}
|
||||
}
|
||||
+8
@@ -16,6 +16,8 @@ import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Competition;
|
||||
import com.sap.sailing.odf.resultimport.CumulativeResult;
|
||||
import com.sap.sailing.odf.resultimport.OdfBody;
|
||||
import com.sap.sailing.odf.resultimport.OdfBodyParser;
|
||||
import com.sap.sailing.odf.resultimport.ParserFactory;
|
||||
@@ -50,6 +52,12 @@ public class ParserTest {
|
||||
OdfBodyParser parser = ParserFactory.INSTANCE.createOdfBodyParser();
|
||||
OdfBody body = parser.parse(getSampleInputStream(), SAMPLE_INPUT_NAME);
|
||||
assertNotNull(body);
|
||||
Iterable<Competition> competitions = body.getCompetitions();
|
||||
for (Competition competition : competitions) {
|
||||
for (CumulativeResult cumulativeResult : competition.getCumulativeResults()) {
|
||||
System.out.println(cumulativeResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
public interface Person extends Named {
|
||||
public interface Athlete extends Named {
|
||||
public static enum Gender { M, F };
|
||||
|
||||
Gender getGender();
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
public interface Competition {
|
||||
Iterable<CumulativeResult> getCumulativeResults();
|
||||
}
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
import com.sap.sailing.domain.common.CountryCode;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
import com.sap.sailing.odf.resultimport.CumulativeResult.CompetitorType;
|
||||
|
||||
public interface Competitor {
|
||||
|
||||
CompetitorType getCompetitorType();
|
||||
|
||||
CountryCode getCountryCode();
|
||||
|
||||
Double getPointsInMedalRace();
|
||||
|
||||
Iterable<Triple<Double, Integer, MaxPointsReason>> getPointsAndRanksAndMaxPointsAfterEachRace();
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
public interface Crewmember extends Person {
|
||||
public interface Crewmember extends Athlete {
|
||||
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
import com.sap.sailing.domain.common.CountryCode;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
|
||||
public interface CumulativeResult {
|
||||
public static enum CompetitorType { A /* athlete */ , T /* team */ };
|
||||
|
||||
int getRank();
|
||||
|
||||
Result getResult();
|
||||
|
||||
int getSortOrder();
|
||||
|
||||
CompetitorType getCompetitorType();
|
||||
|
||||
CountryCode getCountryCode();
|
||||
|
||||
Iterable<Triple<Double, Integer, MaxPointsReason>> getPointsAndRanksAfterEachRace();
|
||||
|
||||
Double getPointsInMedalRace();
|
||||
|
||||
/**
|
||||
* Can be expected to return a single person in case the {@link #getCompetitorType() competitor type} is {@link CompetitorType#A}, or a list
|
||||
* with a {@link Skipper} and {@link Crewmember}s otherwise.
|
||||
*/
|
||||
Iterable<Athlete> getAthletes();
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
public interface OdfBody {
|
||||
|
||||
Iterable<Competition> getCompetitions();
|
||||
}
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
public interface PointsResult extends Result {
|
||||
double getPoints();
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
public interface Result {
|
||||
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
|
||||
public interface ResultList {
|
||||
String getLegend();
|
||||
|
||||
String getImagePath();
|
||||
|
||||
String getStatus();
|
||||
|
||||
String getBoatClassName();
|
||||
|
||||
String getEvent();
|
||||
|
||||
String getTime();
|
||||
|
||||
String getDate();
|
||||
|
||||
/**
|
||||
* Point in time when this result list was published
|
||||
*/
|
||||
TimePoint getTimePointPublished();
|
||||
|
||||
Iterable<Boat> getBoats();
|
||||
|
||||
/**
|
||||
* Matches <code>sailID</code> with {@link Boat#getSailingNumber()}
|
||||
*
|
||||
* @return <code>null</code> if no such {@link Boat} is found in {@link #getBoats}, or the boat found otherwise.
|
||||
*/
|
||||
Boat getBoatBySailID(String sailID);
|
||||
|
||||
String getSourceName();
|
||||
|
||||
Iterable<Integer> getRaceNumbers();
|
||||
}
|
||||
-12
@@ -1,12 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public interface ResultListParser {
|
||||
ResultList parse(InputStream inputStream, String sourceName) throws SAXException, IOException, ParserConfigurationException;
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
|
||||
public interface Skipper extends Person {
|
||||
public interface Skipper extends Athlete {
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
|
||||
public interface Start {
|
||||
String getBoatClass();
|
||||
|
||||
Integer getRaceNumber();
|
||||
|
||||
String getFleetName();
|
||||
|
||||
String getCourseName();
|
||||
|
||||
String getStartTimeAsString();
|
||||
|
||||
TimePoint getTimePoint() throws ParseException;
|
||||
|
||||
String getStartFlag();
|
||||
|
||||
String getComment();
|
||||
|
||||
Boolean isDoubleScore();
|
||||
|
||||
Boolean isDiscardable();
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport;
|
||||
|
||||
import java.text.ParseException;
|
||||
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
|
||||
public interface StartReport {
|
||||
String getDateAsString();
|
||||
|
||||
TimePoint getTimePoint() throws ParseException;
|
||||
|
||||
String getCourseAreaName();
|
||||
|
||||
String getStartBearingAsString();
|
||||
|
||||
String getWindSpeedAsString();
|
||||
|
||||
String getWindDirectionAsString();
|
||||
|
||||
Iterable<Start> getStarts();
|
||||
|
||||
String getSourceName();
|
||||
}
|
||||
+34
-12
@@ -1,7 +1,7 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
@@ -21,19 +21,41 @@ public class AbstractNodeWrapper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtains the node's <code>ExtendedResults</code> element and reads the <code>ExtendedResult</code> elements inside whose <code>Type</code>
|
||||
* attribute equals <code>type</code>. The result is a map whose keys are the <code>Code</code> and whose values are the <code>Value</code> field
|
||||
* of the <code>ExtendedResult</code> element.
|
||||
* Obtains the node's <code>ExtendedResults</code> element and reads the <code>ExtendedResult</code> elements inside
|
||||
* whose <code>Type</code> attribute equals <code>type</code>. The result is a map whose keys are the
|
||||
* <code>Code</code> and whose values are iterables containing the one or more <code>Value</code> fields of the
|
||||
* <code>ExtendedResult</code> elements with the key code. If there is a <code>Pos</code> field set, the iteration
|
||||
* order will be in incrementing order of the <code>Pos</code> attribute value.
|
||||
*/
|
||||
protected Map<String, String> getExtendedResults(String type) {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
protected Map<String, TreeMap<Integer, String>> getExtendedResults(String type) {
|
||||
Map<String, TreeMap<Integer, String>> orderedMap = new TreeMap<>();
|
||||
Element element = (Element) getNode();
|
||||
NodeList extendedResults = element.getElementsByTagName("ExtendedResults");
|
||||
for (int i=0; i<extendedResults.getLength(); i++) {
|
||||
Node extendedResult = extendedResults.item(i);
|
||||
NamedNodeMap attributes = extendedResult.getAttributes();
|
||||
System.out.println(attributes);
|
||||
NodeList extendedResultsNodes = element.getElementsByTagName("ExtendedResults");
|
||||
int defaultPos = 0;
|
||||
for (int i=0; i<extendedResultsNodes.getLength(); i++) {
|
||||
Node extendedResultsNode = extendedResultsNodes.item(i);
|
||||
NodeList extendedResults = ((Element) extendedResultsNode).getElementsByTagName("ExtendedResult");
|
||||
for (int j = 0; j < extendedResults.getLength(); j++) {
|
||||
Node extendedResult = extendedResults.item(j);
|
||||
final NamedNodeMap attributes = extendedResult.getAttributes();
|
||||
final int pos;
|
||||
Node nodeType = attributes.getNamedItem("Type");
|
||||
if (nodeType == null || type.equals(nodeType.getNodeValue())) {
|
||||
if (attributes.getNamedItem("Pos") != null) {
|
||||
pos = Integer.valueOf(attributes.getNamedItem("Pos").getNodeValue());
|
||||
} else {
|
||||
pos = defaultPos++;
|
||||
}
|
||||
final String key = attributes.getNamedItem("Code").getNodeValue();
|
||||
TreeMap<Integer, String> entry = orderedMap.get(key);
|
||||
if (entry == null) {
|
||||
entry = new TreeMap<>();
|
||||
orderedMap.put(key, entry);
|
||||
}
|
||||
entry.put(pos, attributes.getNamedItem("Value").getNodeValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return orderedMap;
|
||||
}
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Athlete;
|
||||
|
||||
public class AthleteImpl extends NamedImpl implements Athlete {
|
||||
|
||||
public AthleteImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Gender getGender() {
|
||||
return Gender.valueOf(getExtendedResults("ER_SA").get("SA_GENDER").firstEntry().getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName()+" ("+getGender()+")";
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Boat;
|
||||
import com.sap.sailing.odf.resultimport.BoatResultInRace;
|
||||
import com.sap.sailing.odf.resultimport.Crew;
|
||||
|
||||
public class BoatImpl extends NamedImpl implements Boat {
|
||||
|
||||
public BoatImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSailingNumber() {
|
||||
return getNode().getAttributes().getNamedItem("sailingnumber").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRank() {
|
||||
return Integer.valueOf(getNode().getAttributes().getNamedItem("position").getNodeValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrice() {
|
||||
return getNode().getAttributes().getNamedItem("preis").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Crew getCrew() {
|
||||
final NodeList crew = ((Element) getNode()).getElementsByTagName("Crew");
|
||||
return new CrewImpl(crew.item(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getTotalPoints() {
|
||||
return Double.valueOf(((Element) getNode()).getElementsByTagName("Races").item(0).getAttributes()
|
||||
.getNamedItem("totalpoints").getNodeValue().replace(',', '.'));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<BoatResultInRace> getResultsInRaces() {
|
||||
List<BoatResultInRace> result = new ArrayList<BoatResultInRace>();
|
||||
final NodeList races = ((Element) ((Element) getNode()).getElementsByTagName("Races").item(0)).getElementsByTagName("Race");
|
||||
for (int i=0; i<races.getLength(); i++) {
|
||||
result.add(new BoatResultsInRaceImpl(races.item(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BoatResultInRace getResultsInRace(int raceNumberOneBased) {
|
||||
for (BoatResultInRace race : getResultsInRaces()) {
|
||||
if (race.getRaceNumber() == raceNumberOneBased) {
|
||||
return race;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getSailingNumber();
|
||||
}
|
||||
}
|
||||
-80
@@ -1,80 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.odf.resultimport.BoatResultInRace;
|
||||
|
||||
public class BoatResultsInRaceImpl extends AbstractNodeWrapper implements BoatResultInRace {
|
||||
private static final Logger logger = Logger.getLogger(BoatResultsInRaceImpl.class.getName());
|
||||
private static final Pattern leadingPercentagePattern = Pattern.compile("^[0-9][0-9]*%.*$");
|
||||
private static final Pattern pointsPattern = Pattern.compile("[0-9]*(,[0-9]*)");
|
||||
|
||||
public BoatResultsInRaceImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscarded() {
|
||||
final String pointsAsString = getNode().getAttributes().getNamedItem("points").getNodeValue().trim();
|
||||
return pointsAsString.startsWith("(") && pointsAsString.endsWith(")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getPoints() {
|
||||
Matcher m = pointsPattern.matcher(getNode().getAttributes().getNamedItem("points").getNodeValue());
|
||||
Double result = null;
|
||||
if (m.find()) {
|
||||
final String pointsAsString = m.group().replace(',', '.').trim();
|
||||
if (!pointsAsString.trim().equals("-")) {
|
||||
try {
|
||||
result = Double.valueOf(pointsAsString);
|
||||
} catch (NumberFormatException nfe) {
|
||||
logger.throwing(BoatResultsInRaceImpl.class.getName(), "getPoints", nfe);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRaceNumber() {
|
||||
return Integer.valueOf(getNode().getAttributes().getNamedItem("number").getNodeValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
final Node namedItem = getNode().getAttributes().getNamedItem("status");
|
||||
return namedItem == null || namedItem.getNodeValue() == null || namedItem.getNodeValue().trim().length() == 0 ? null
|
||||
: namedItem.getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaxPointsReason getMaxPointsReason() {
|
||||
MaxPointsReason result;
|
||||
String status = getStatus();
|
||||
if (status != null) {
|
||||
if (startsWithPercentage(status)) {
|
||||
result = MaxPointsReason.ZFP;
|
||||
} else {
|
||||
result = MaxPointsReason.valueOf(status.substring(0, 3));
|
||||
}
|
||||
} else {
|
||||
result = MaxPointsReason.NONE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean startsWithPercentage(String status) {
|
||||
return leadingPercentagePattern.matcher(status).matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + getRaceNumber() + ": " + getMaxPointsReason() + ", " + getPoints() + (isDiscarded()?", discarded":"")+"}";
|
||||
}
|
||||
}
|
||||
java/com.sap.sailing.odf.resultimport/src/com/sap/sailing/odf/resultimport/impl/CompetitionImpl.java
Executable
+30
@@ -0,0 +1,30 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Competition;
|
||||
import com.sap.sailing.odf.resultimport.CumulativeResult;
|
||||
|
||||
public class CompetitionImpl extends AbstractNodeWrapper implements Competition {
|
||||
|
||||
public CompetitionImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<CumulativeResult> getCumulativeResults() {
|
||||
List<CumulativeResult> result = new ArrayList<>();
|
||||
Element element = (Element) getNode();
|
||||
NodeList cumulativeResults = element.getElementsByTagName("CumulativeResult");
|
||||
for (int i=0; i<cumulativeResults.getLength(); i++) {
|
||||
result.add(new CumulativeResultImpl(cumulativeResults.item(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Executable
+62
@@ -0,0 +1,62 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.sap.sailing.domain.common.CountryCode;
|
||||
import com.sap.sailing.domain.common.CountryCodeFactory;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
import com.sap.sailing.odf.resultimport.Competitor;
|
||||
import com.sap.sailing.odf.resultimport.CumulativeResult.CompetitorType;
|
||||
|
||||
public class CompetitorImpl extends AbstractNodeWrapper implements Competitor {
|
||||
|
||||
public CompetitorImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitorType getCompetitorType() {
|
||||
return CompetitorType.valueOf(((Element) getNode()).getAttribute("Type"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountryCode getCountryCode() {
|
||||
return CountryCodeFactory.INSTANCE.getFromThreeLetterIOCName((((Element) getNode()).getAttribute("Bib")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getPointsInMedalRace() {
|
||||
final TreeMap<Integer, String> pointsInMedalRace = getExtendedResults("ER_SA").get("SA_POINTS_IN_MEDAL_RACE");
|
||||
String medalPoints = pointsInMedalRace == null ? null : pointsInMedalRace.firstEntry().getValue();
|
||||
return medalPoints == null ? null : Double.valueOf(medalPoints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Triple<Double, Integer, MaxPointsReason>> getPointsAndRanksAndMaxPointsAfterEachRace() {
|
||||
List<Triple<Double, Integer, MaxPointsReason>> result = new ArrayList<>();
|
||||
TreeMap<Integer, String> points = getExtendedResults("ER_SA").get("SA_POINTS_IN_RACE");
|
||||
TreeMap<Integer, String> ranks = getExtendedResults("ER_SA").get("SA_RANK_AFTER_RACE");
|
||||
TreeMap<Integer, String> irmStatus = getExtendedResults("ER_SA").get("SA_IRM_STATUS_IN_RACE");
|
||||
Iterator<Entry<Integer, String>> pointsIter = points.entrySet().iterator();
|
||||
Iterator<Entry<Integer, String>> ranksIter = ranks.entrySet().iterator();
|
||||
while (pointsIter.hasNext() && ranksIter.hasNext()) {
|
||||
final Entry<Integer, String> pointsEntry = pointsIter.next();
|
||||
final Entry<Integer, String> ranksEntry = ranksIter.next();
|
||||
final String maxPointsReasonAsString = irmStatus == null ? null : irmStatus.get(pointsEntry.getKey());
|
||||
final MaxPointsReason maxPointsReason = maxPointsReasonAsString == null ? MaxPointsReason.NONE :
|
||||
MaxPointsReason.valueOf(maxPointsReasonAsString);
|
||||
result.add(new Triple<Double, Integer, MaxPointsReason>(
|
||||
Double.valueOf(pointsEntry.getValue()), Integer.valueOf(ranksEntry.getValue()),
|
||||
maxPointsReason));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
+6
-1
@@ -4,10 +4,15 @@ import org.w3c.dom.Node;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Crewmember;
|
||||
|
||||
public class CrewmemberImpl extends PersonImpl implements Crewmember {
|
||||
public class CrewmemberImpl extends AthleteImpl implements Crewmember {
|
||||
|
||||
public CrewmemberImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString()+" (Crew)";
|
||||
}
|
||||
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.sap.sailing.domain.common.CountryCode;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
import com.sap.sailing.odf.resultimport.Athlete;
|
||||
import com.sap.sailing.odf.resultimport.Competitor;
|
||||
import com.sap.sailing.odf.resultimport.CumulativeResult;
|
||||
import com.sap.sailing.odf.resultimport.Result;
|
||||
|
||||
public class CumulativeResultImpl extends AbstractNodeWrapper implements CumulativeResult {
|
||||
private final Competitor competitor;
|
||||
|
||||
public CumulativeResultImpl(Node node) {
|
||||
super(node);
|
||||
this.competitor = new CompetitorImpl(((Element) getNode()).getElementsByTagName("Competitor").item(0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRank() {
|
||||
return Integer.valueOf(getNode().getAttributes().getNamedItem("Rank").getNodeValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result getResult() {
|
||||
final String resultType = getNode().getAttributes().getNamedItem("ResultType").getNodeValue();
|
||||
if ("POINTS".equals(resultType)) {
|
||||
return new PointsResultImpl(Double.valueOf(getNode().getAttributes().getNamedItem("Result").getNodeValue()));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Don't know yet how to deal with result type "+resultType);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSortOrder() {
|
||||
return Integer.valueOf(getNode().getAttributes().getNamedItem("SortOrder").getNodeValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompetitorType getCompetitorType() {
|
||||
return competitor.getCompetitorType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountryCode getCountryCode() {
|
||||
return competitor.getCountryCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Triple<Double, Integer, MaxPointsReason>> getPointsAndRanksAfterEachRace() {
|
||||
return competitor.getPointsAndRanksAndMaxPointsAfterEachRace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getPointsInMedalRace() {
|
||||
return competitor.getPointsInMedalRace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Athlete> getAthletes() {
|
||||
List<Athlete> result = new ArrayList<>();
|
||||
Node composition = ((Element) getNode()).getElementsByTagName("Composition").item(0);
|
||||
NodeList athletes = ((Element) composition).getElementsByTagName("Athlete");
|
||||
for (int i=0; i<athletes.getLength(); i++) {
|
||||
final Node athleteNode = athletes.item(i);
|
||||
AthleteImpl athlete = new AthleteImpl(athleteNode);
|
||||
if ("Skipper".equals(athlete.getExtendedResults("ER_SA").get("SA_POSITION"))) {
|
||||
result.add(new SkipperImpl(athleteNode));
|
||||
} else {
|
||||
result.add(new CrewmemberImpl(athleteNode));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Cumulative Results for "+getAthletes()+" ("+getCountryCode()+"): Rank: "+getRank()+", Result: "+getResult()+", sort order "+getSortOrder()
|
||||
+", race results: "+getPointsAndRanksAfterEachRace()+", medal race results: "+getPointsInMedalRace();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ public class NamedImpl extends AbstractNodeWrapper implements Named {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getNode().getAttributes().getNamedItem("name").getNodeValue();
|
||||
return getExtendedResults("ER_SA").get("SA_NAME").firstEntry().getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+17
-1
@@ -1,7 +1,13 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Competition;
|
||||
import com.sap.sailing.odf.resultimport.OdfBody;
|
||||
|
||||
public class OdfBodyImpl extends AbstractNodeWrapper implements OdfBody {
|
||||
@@ -9,4 +15,14 @@ public class OdfBodyImpl extends AbstractNodeWrapper implements OdfBody {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Competition> getCompetitions() {
|
||||
List<Competition> result = new ArrayList<>();
|
||||
Element element = (Element) getNode();
|
||||
NodeList cumulativeResults = element.getElementsByTagName("Competition");
|
||||
for (int i=0; i<cumulativeResults.getLength(); i++) {
|
||||
result.add(new CompetitionImpl(cumulativeResults.item(i)));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Person;
|
||||
|
||||
public class PersonImpl extends NamedImpl implements Person {
|
||||
|
||||
public PersonImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Gender getGender() {
|
||||
return Gender.valueOf(getNode().getAttributes().getNamedItem("name").getNodeValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.PointsResult;
|
||||
|
||||
public class PointsResultImpl implements PointsResult {
|
||||
private final double points;
|
||||
|
||||
public PointsResultImpl(double points) {
|
||||
super();
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ""+getPoints()+" points";
|
||||
}
|
||||
}
|
||||
-120
@@ -1,120 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.odf.resultimport.Boat;
|
||||
import com.sap.sailing.odf.resultimport.BoatResultInRace;
|
||||
import com.sap.sailing.odf.resultimport.ResultList;
|
||||
|
||||
public class ResultListImpl extends AbstractNodeWrapper implements ResultList {
|
||||
private static final Logger logger = Logger.getLogger(ResultListImpl.class.getName());
|
||||
|
||||
private final String sourceName;
|
||||
|
||||
private static final SimpleDateFormat df = new SimpleDateFormat("dd. MMM yyyy HH:mm", Locale.GERMAN);
|
||||
|
||||
public ResultListImpl(Node node, String sourceName) {
|
||||
super(node);
|
||||
this.sourceName = sourceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLegend() {
|
||||
return getNode().getAttributes().getNamedItem("legende").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImagePath() {
|
||||
return getNode().getAttributes().getNamedItem("imagePfad").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatus() {
|
||||
return getNode().getAttributes().getNamedItem("status").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBoatClassName() {
|
||||
return getNode().getAttributes().getNamedItem("class").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEvent() {
|
||||
return getNode().getAttributes().getNamedItem("event").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTime() {
|
||||
return getNode().getAttributes().getNamedItem("time").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDate() {
|
||||
return getNode().getAttributes().getNamedItem("date").getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimePoint getTimePointPublished() {
|
||||
TimePoint result = null;
|
||||
String dateTime = getDate()+" "+getTime();
|
||||
try {
|
||||
Date d = df.parse(dateTime);
|
||||
result = new MillisecondsTimePoint(d);
|
||||
} catch (ParseException e) {
|
||||
logger.info("Failed to parse result list date/time "+dateTime);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Boat> getBoats() {
|
||||
List<Boat> result = new ArrayList<Boat>();
|
||||
final NodeList verteilung = ((Element) getNode()).getElementsByTagName("Verteilung");
|
||||
for (int i = 0; i < verteilung.getLength(); i++) {
|
||||
final NodeList boats = ((Element) verteilung.item(i)).getElementsByTagName("Boat");
|
||||
for (int j = 0; j < boats.getLength(); j++) {
|
||||
result.add(new BoatImpl(boats.item(j)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boat getBoatBySailID(String sailID) {
|
||||
for (Boat boat : getBoats()) {
|
||||
if (sailID.equals(boat.getSailingNumber())) {
|
||||
return boat;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Integer> getRaceNumbers() {
|
||||
LinkedHashSet<Integer> result = new LinkedHashSet<Integer>();
|
||||
for (Boat boat : getBoats()) {
|
||||
for (BoatResultInRace results : boat.getResultsInRaces()) {
|
||||
result.add(results.getRaceNumber());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.ResultList;
|
||||
import com.sap.sailing.odf.resultimport.ResultListParser;
|
||||
|
||||
public class ResultListParserImpl implements ResultListParser {
|
||||
private Document parseDocument(InputStream inputStream) throws SAXException, IOException, ParserConfigurationException {
|
||||
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultList parse(InputStream inputStream, String sourceName) throws SAXException, IOException, ParserConfigurationException {
|
||||
Document doc = parseDocument(inputStream);
|
||||
ResultList result = new ResultListImpl(doc.getElementsByTagName("ResultList").item(0), sourceName);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
+6
-1
@@ -4,8 +4,13 @@ import org.w3c.dom.Node;
|
||||
|
||||
import com.sap.sailing.odf.resultimport.Skipper;
|
||||
|
||||
public class SkipperImpl extends PersonImpl implements Skipper {
|
||||
public class SkipperImpl extends AthleteImpl implements Skipper {
|
||||
public SkipperImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString()+" (Skipper)";
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.odf.resultimport.Start;
|
||||
|
||||
public class StartImpl extends AbstractNodeWrapper implements Start {
|
||||
private static final DateFormat df = new SimpleDateFormat("yyyy-MM-ddX");
|
||||
|
||||
public StartImpl(Node node) {
|
||||
super(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBoatClass() {
|
||||
final Node item = ((Element) getNode()).getElementsByTagName("bootsklasse").item(0);
|
||||
return item == null ? null : item.getFirstChild().getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getRaceNumber() {
|
||||
return Integer.valueOf(((Element) getNode()).getElementsByTagName("wettfahrt").item(0).getFirstChild().getNodeValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFleetName() {
|
||||
return ((Element) getNode()).getElementsByTagName("startgruppe").item(0).getFirstChild().getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCourseName() {
|
||||
return ((Element) getNode()).getElementsByTagName("kurs").item(0).getFirstChild().getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStartTimeAsString() {
|
||||
return ((Element) getNode()).getElementsByTagName("startzeit").item(0).getFirstChild().getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimePoint getTimePoint() throws ParseException {
|
||||
return new MillisecondsTimePoint(df.parse(getStartTimeAsString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStartFlag() {
|
||||
return ((Element) getNode()).getElementsByTagName("startflagge").item(0).getFirstChild().getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComment() {
|
||||
return ((Element) getNode()).getElementsByTagName("bemerkung").item(0).getFirstChild().getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isDoubleScore() {
|
||||
return Boolean.valueOf(((Element) getNode()).getElementsByTagName("doppelte_Wertung").item(0).getFirstChild().getNodeValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isDiscardable() {
|
||||
return Boolean.valueOf(((Element) getNode()).getElementsByTagName("streichbar").item(0).getFirstChild().getNodeValue());
|
||||
}
|
||||
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
package com.sap.sailing.odf.resultimport.impl;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.odf.resultimport.Start;
|
||||
import com.sap.sailing.odf.resultimport.StartReport;
|
||||
|
||||
public class StartReportImpl extends AbstractNodeWrapper implements StartReport {
|
||||
private static final DateFormat df = new SimpleDateFormat("yyyy-MM-ddX");
|
||||
|
||||
private final String sourceName;
|
||||
|
||||
public StartReportImpl(Node node, String sourceName) {
|
||||
super(node);
|
||||
this.sourceName = sourceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSourceName() {
|
||||
return sourceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDateAsString() {
|
||||
return ((Element) getNode()).getElementsByTagName("datum").item(0).getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TimePoint getTimePoint() throws ParseException {
|
||||
String datum = getDateAsString();
|
||||
return datum == null || datum.trim().length() == 0 ? null : new MillisecondsTimePoint(df.parse(datum));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCourseAreaName() {
|
||||
return ((Element) getNode()).getElementsByTagName("regattabahn").item(0).getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStartBearingAsString() {
|
||||
return ((Element) getNode()).getElementsByTagName("kompasskurs").item(0).getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWindSpeedAsString() {
|
||||
return ((Element) getNode()).getElementsByTagName("windstaerke").item(0).getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWindDirectionAsString() {
|
||||
return ((Element) getNode()).getElementsByTagName("windrichtung").item(0).getNodeValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Start> getStarts() {
|
||||
List<Start> result = new ArrayList<Start>();
|
||||
final NodeList starts = ((Element) getNode()).getElementsByTagName("start");
|
||||
for (int i=0; i<starts.getLength(); i++) {
|
||||
final Element startNode = (Element) starts.item(i);
|
||||
final StartImpl start = new StartImpl(startNode);
|
||||
if (start.getBoatClass() != null) {
|
||||
result.add(start);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user