mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-06 11:02:25 +00:00
first successful Barbados result import test that uses ScoreCorrectionProviderImpl
This commit is contained in:
1 parent
98d8e655c8
commit
9760c47430
4 files changed
+39
-360
No files matched your search
+38
-1
@@ -2,6 +2,9 @@ package com.sap.sailing.barbados.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;
|
||||
import java.io.FileInputStream;
|
||||
@@ -9,6 +12,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
@@ -19,6 +23,9 @@ import org.junit.Test;
|
||||
import com.sap.sailing.barbados.resultimport.impl.BarbadosResultSpreadsheet;
|
||||
import com.sap.sailing.barbados.resultimport.impl.ScoreCorrectionProviderImpl;
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.MaxPointsReason;
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections;
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections.ScoreCorrectionsForRace;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
@@ -60,11 +67,41 @@ public class BarbadosResultImportTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultsThroughScoreCorrectionProvider() throws Exception {
|
||||
public void testHasResultsThroughScoreCorrectionProvider() throws Exception {
|
||||
Map<String, Set<Pair<String, TimePoint>>> hasResultsFor = scp.getHasResultsForBoatClassFromDateByEventName();
|
||||
assertNotNull(hasResultsFor);
|
||||
assertEquals(1, hasResultsFor.size());
|
||||
Entry<String, Set<Pair<String, TimePoint>>> entry = hasResultsFor.entrySet().iterator().next();
|
||||
assertEquals("505", entry.getKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultsThroughScoreCorrectionProvider() throws Exception {
|
||||
Map<String, Set<Pair<String, TimePoint>>> hasResultsFor = scp.getHasResultsForBoatClassFromDateByEventName();
|
||||
String eventName = hasResultsFor.entrySet().iterator().next().getKey();
|
||||
String boatClassName = hasResultsFor.entrySet().iterator().next().getValue().iterator().next().getA();
|
||||
TimePoint timePoint = hasResultsFor.entrySet().iterator().next().getValue().iterator().next().getB();
|
||||
RegattaScoreCorrections result = scp.getScoreCorrections(eventName, boatClassName, timePoint);
|
||||
Iterator<ScoreCorrectionsForRace> scfr = result.getScoreCorrectionsForRaces().iterator();
|
||||
ScoreCorrectionsForRace scfr1 = scfr.next();
|
||||
ScoreCorrectionsForRace scfr2 = scfr.next();
|
||||
ScoreCorrectionsForRace scfr3 = scfr.next();
|
||||
assertTrue(scfr1.getSailIDs().contains("GER 9113"));
|
||||
assertTrue(scfr1.getSailIDs().contains("GER 9112"));
|
||||
assertTrue(scfr1.getSailIDs().contains("GER 9110"));
|
||||
assertEquals(3, scfr1.getScoreCorrectionForCompetitor("GER 9113").getPoints(), 0.0000000001);
|
||||
assertEquals(7, scfr2.getScoreCorrectionForCompetitor("GER 9113").getPoints(), 0.0000000001);
|
||||
assertEquals(78, scfr3.getScoreCorrectionForCompetitor("GER 9113").getPoints(), 0.0000000001);
|
||||
assertSame(MaxPointsReason.DNF, scfr3.getScoreCorrectionForCompetitor("GER 9113").getMaxPointsReason());
|
||||
|
||||
assertEquals(2, scfr1.getScoreCorrectionForCompetitor("GER 9112").getPoints(), 0.0000000001);
|
||||
assertEquals(9, scfr2.getScoreCorrectionForCompetitor("GER 9112").getPoints(), 0.0000000001);
|
||||
assertEquals(9, scfr3.getScoreCorrectionForCompetitor("GER 9112").getPoints(), 0.0000000001);
|
||||
assertNull(scfr3.getScoreCorrectionForCompetitor("GER 9112").getMaxPointsReason());
|
||||
|
||||
assertEquals(5, scfr1.getScoreCorrectionForCompetitor("GER 9110").getPoints(), 0.0000000001);
|
||||
assertEquals(7, scfr2.getScoreCorrectionForCompetitor("GER 9110").getPoints(), 0.0000000001);
|
||||
assertEquals(78, scfr3.getScoreCorrectionForCompetitor("GER 9110").getPoints(), 0.0000000001);
|
||||
assertSame(MaxPointsReason.OCS, scfr3.getScoreCorrectionForCompetitor("GER 9110").getMaxPointsReason());
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -49,7 +49,7 @@ public class BarbadosResultSpreadsheet {
|
||||
String iocCountryCode;
|
||||
while ((row=overallResultsSheet.getRow(rowIndex)) != null && (iocCountryCode = row.getCell(1).getStringCellValue()) != null && !iocCountryCode.isEmpty()) {
|
||||
Integer totalRank = row.getCell(0) == null ? null : (int) row.getCell(0).getNumericCellValue();
|
||||
String sailID = iocCountryCode + ((int) row.getCell(2).getNumericCellValue());
|
||||
String sailID = iocCountryCode.trim() + " " + ((int) row.getCell(2).getNumericCellValue());
|
||||
String helm = row.getCell(3).getStringCellValue();
|
||||
String crew = row.getCell(4).getStringCellValue();
|
||||
Iterable<String> names = Arrays.asList(new String[] { helm, crew });
|
||||
|
||||
-295
@@ -1,295 +0,0 @@
|
||||
package com.sap.sailing.barbados.resultimport.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sap.sailing.resultimport.CompetitorEntry;
|
||||
import com.sap.sailing.resultimport.CompetitorRow;
|
||||
import com.sap.sailing.resultimport.impl.DefaultCompetitorEntryImpl;
|
||||
|
||||
public class CompetitorRowImpl implements CompetitorRow {
|
||||
private Integer totalRank;
|
||||
private String country;
|
||||
private String sailNumber;
|
||||
private String teamMember1Name;
|
||||
private String teamMember1Club;
|
||||
private String teamMember1DSVNumber;
|
||||
private String teamMember2Name;
|
||||
private String teamMember2Club;
|
||||
private String teamMember2DSVNumber;
|
||||
private String teamMember3Name;
|
||||
private String teamMember3Club;
|
||||
private String teamMember3DSVNumber;
|
||||
private Map<Integer, String> ranks;
|
||||
private Map<Integer, String> scores;
|
||||
|
||||
private double totalScore;
|
||||
private int racesCount = 6;
|
||||
|
||||
public CompetitorRowImpl() {
|
||||
ranks = new LinkedHashMap<Integer, String>();
|
||||
scores = new LinkedHashMap<Integer, String>();
|
||||
}
|
||||
|
||||
public Object getResultKey() {
|
||||
return sailNumber;
|
||||
}
|
||||
|
||||
public Integer getTotalRank() {
|
||||
return totalRank;
|
||||
}
|
||||
|
||||
public void setTotalRank(Integer totalRank) {
|
||||
this.totalRank = totalRank;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getSailNumber() {
|
||||
return sailNumber;
|
||||
}
|
||||
|
||||
public void setSailNumber(String sailNumber) {
|
||||
this.sailNumber = sailNumber;
|
||||
}
|
||||
|
||||
public String getTeamMember1Name() {
|
||||
return teamMember1Name;
|
||||
}
|
||||
|
||||
public void setTeamMember1Name(String teamMember1Name) {
|
||||
this.teamMember1Name = teamMember1Name;
|
||||
}
|
||||
|
||||
public String getTeamMember1Club() {
|
||||
return teamMember1Club;
|
||||
}
|
||||
|
||||
public void setTeamMember1Club(String teamMember1Club) {
|
||||
this.teamMember1Club = teamMember1Club;
|
||||
}
|
||||
|
||||
public String getTeamMember1DSVNumber() {
|
||||
return teamMember1DSVNumber;
|
||||
}
|
||||
|
||||
public void setTeamMember1DSVNumber(String teamMember1DSVNumber) {
|
||||
this.teamMember1DSVNumber = teamMember1DSVNumber;
|
||||
}
|
||||
|
||||
public String getTeamMember2Name() {
|
||||
return teamMember2Name;
|
||||
}
|
||||
|
||||
public void setTeamMember2Name(String teamMember2Name) {
|
||||
this.teamMember2Name = teamMember2Name;
|
||||
}
|
||||
|
||||
public String getTeamMember2Club() {
|
||||
return teamMember2Club;
|
||||
}
|
||||
|
||||
public void setTeamMember2Club(String teamMember2Club) {
|
||||
this.teamMember2Club = teamMember2Club;
|
||||
}
|
||||
|
||||
public String getTeamMember2DSVNumber() {
|
||||
return teamMember2DSVNumber;
|
||||
}
|
||||
|
||||
public void setTeamMember2DSVNumber(String teamMember2DSVNumber) {
|
||||
this.teamMember2DSVNumber = teamMember2DSVNumber;
|
||||
}
|
||||
|
||||
public String getTeamMember3Name() {
|
||||
return teamMember3Name;
|
||||
}
|
||||
|
||||
public void setTeamMember3Name(String teamMember3Name) {
|
||||
this.teamMember3Name = teamMember3Name;
|
||||
}
|
||||
|
||||
public String getTeamMember3Club() {
|
||||
return teamMember3Club;
|
||||
}
|
||||
|
||||
public void setTeamMember3Club(String teamMember3Club) {
|
||||
this.teamMember3Club = teamMember3Club;
|
||||
}
|
||||
|
||||
public String getTeamMember3DSVNumber() {
|
||||
return teamMember3DSVNumber;
|
||||
}
|
||||
|
||||
public void setTeamMember3DSVNumber(String teamMember3DSVNumber) {
|
||||
this.teamMember3DSVNumber = teamMember3DSVNumber;
|
||||
}
|
||||
|
||||
public void setRace1Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(1, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace1Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(1, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace2Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(2, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace2Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(2, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace3Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(3, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace3Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(3, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace4Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(4, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace4Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(4, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace5Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(5, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace5Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(5, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace6Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(6, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace6Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(6, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public double getTotalScore() {
|
||||
return totalScore;
|
||||
}
|
||||
|
||||
public void setTotalScore(double totalScore) {
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<CompetitorEntry> getRankAndMaxPointsReasonAndPointsAndDiscarded() {
|
||||
List<CompetitorEntry> competitorEntries = new ArrayList<CompetitorEntry>();
|
||||
for (int i = 1; i <= racesCount; i++) {
|
||||
if (scores.containsKey(i)) {
|
||||
boolean discarded = false;
|
||||
Integer rank = null;
|
||||
String maxPointsReason;
|
||||
|
||||
if (ranks.containsKey(i)) {
|
||||
String rankAsString = ranks.get(i);
|
||||
if (rankAsString.startsWith("(") && rankAsString.endsWith(")")) {
|
||||
rankAsString = rankAsString.substring(1, rankAsString.length() - 1);
|
||||
discarded = true;
|
||||
}
|
||||
try {
|
||||
rank = Integer.valueOf(rankAsString);
|
||||
} catch (NumberFormatException nfe) {
|
||||
rank = null;
|
||||
}
|
||||
}
|
||||
|
||||
String scoreAsString = scores.get(i);
|
||||
if (scoreAsString.startsWith("(") && scoreAsString.endsWith(")")) {
|
||||
scoreAsString = scoreAsString.substring(1, scoreAsString.length() - 1);
|
||||
discarded = true;
|
||||
}
|
||||
|
||||
Double score;
|
||||
try {
|
||||
score = Double.valueOf(scoreAsString);
|
||||
maxPointsReason = null;
|
||||
} catch (NumberFormatException nfe) {
|
||||
// must have been a disqualification / max-points-reason
|
||||
score = null;
|
||||
maxPointsReason = scoreAsString;
|
||||
}
|
||||
|
||||
competitorEntries.add(new DefaultCompetitorEntryImpl(rank, maxPointsReason, score, discarded));
|
||||
}
|
||||
}
|
||||
|
||||
return competitorEntries;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getNetPointsBeforeDiscarding() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getScoreAfterDiscarding() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> getNames() {
|
||||
List<String> names = new ArrayList<String>();
|
||||
if (teamMember1Name != null) {
|
||||
names.add(teamMember1Name);
|
||||
}
|
||||
if (teamMember2Name != null) {
|
||||
names.add(teamMember2Name);
|
||||
}
|
||||
if (teamMember3Name != null) {
|
||||
names.add(teamMember3Name);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCompetitorName() {
|
||||
return teamMember1Name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSailID() {
|
||||
return country.trim() + sailNumber.trim();
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package com.sap.sailing.barbados.resultimport.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class RegattaInfo {
|
||||
private String eventName;
|
||||
private String boatClass;
|
||||
private String date;
|
||||
|
||||
public String getEventName() {
|
||||
return eventName;
|
||||
}
|
||||
|
||||
public void setEventName(String eventName) {
|
||||
String prefix = "Veranstaltung: ";
|
||||
if(eventName.startsWith(prefix)) {
|
||||
this.eventName = eventName.substring(prefix.length(), eventName.length());
|
||||
} else {
|
||||
this.eventName = eventName;
|
||||
}
|
||||
}
|
||||
|
||||
public String getBoatClass() {
|
||||
return boatClass;
|
||||
}
|
||||
|
||||
public void setBoatClass(String boatClass) {
|
||||
String prefix = "Klasse: ";
|
||||
if(boatClass.startsWith(prefix)) {
|
||||
this.boatClass = boatClass.substring(prefix.length(), boatClass.length());
|
||||
} else {
|
||||
this.boatClass = boatClass;
|
||||
}
|
||||
}
|
||||
|
||||
public String getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(String date) {
|
||||
String prefix = "Datum: ";
|
||||
if(date.startsWith(prefix)) {
|
||||
this.date = date.substring(prefix.length(), date.length());
|
||||
} else {
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, String> toMap() {
|
||||
Map<String, String> dataAsMap = new HashMap<String, String>();
|
||||
if(eventName != null) {
|
||||
dataAsMap.put("eventName", eventName);
|
||||
}
|
||||
if(boatClass != null) {
|
||||
dataAsMap.put("boatClass", boatClass);
|
||||
}
|
||||
if(date != null) {
|
||||
dataAsMap.put("date", date);
|
||||
}
|
||||
return dataAsMap;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user