mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-11-06 11:02:25 +00:00
working towards further refactoring of URL/file-based result importers
This commit is contained in:
1 parent
f4a622d011
commit
a1c1739244
13 files changed
+343
-333
No files matched your search
+25
-4
@@ -5,28 +5,32 @@ import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections;
|
||||
import com.sap.sailing.domain.common.ScoreCorrectionProvider;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.resultimport.UrlResultProvider;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
import com.sap.sailing.resultimport.RegattaResults;
|
||||
import com.sap.sailing.resultimport.ResultDocumentProvider;
|
||||
import com.sap.sailing.resultimport.UrlResultProvider;
|
||||
import com.sap.sailing.resultimport.impl.AbstractDocumentBasedScoreCorrectionProvider;
|
||||
import com.sap.sailing.resultimport.impl.RegattaScoreCorrectionsImpl;
|
||||
|
||||
public class ScoreCorrectionProviderImpl implements ScoreCorrectionProvider, UrlResultProvider {
|
||||
public class ScoreCorrectionProviderImpl extends AbstractDocumentBasedScoreCorrectionProvider implements UrlResultProvider {
|
||||
private static final long serialVersionUID = 5853404150107387702L;
|
||||
|
||||
private final Set<URL> allUrls;
|
||||
|
||||
public ScoreCorrectionProviderImpl() throws MalformedURLException {
|
||||
allUrls = new HashSet<URL>();
|
||||
this(new HashSet<URL>());
|
||||
/*
|
||||
* For testing, consider using the following URLs:
|
||||
* allUrls.add(new URL("http://www.axel-uhl.de/freg/freg_html_export_sample.html"));
|
||||
@@ -34,6 +38,23 @@ public class ScoreCorrectionProviderImpl implements ScoreCorrectionProvider, Url
|
||||
*/
|
||||
}
|
||||
|
||||
private ScoreCorrectionProviderImpl(final Set<URL> allUrls) {
|
||||
super(new ResultDocumentProvider() {
|
||||
@Override
|
||||
public Iterable<Triple<InputStream, String, TimePoint>> getDocumentsAndNamesAndLastModified() throws IOException {
|
||||
List<Triple<InputStream, String, TimePoint>> result = new ArrayList<>();
|
||||
for (URL url : allUrls) {
|
||||
URLConnection conn;
|
||||
conn = url.openConnection();
|
||||
result.add(new Triple<InputStream, String, TimePoint>((InputStream) conn.getContent(), url.toString(),
|
||||
new MillisecondsTimePoint(conn.getLastModified())));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
this.allUrls = allUrls;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "FREG HTML Score Importer";
|
||||
|
||||
+2
-1
@@ -17,6 +17,7 @@ import org.xml.sax.SAXException;
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections;
|
||||
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;
|
||||
import com.sap.sailing.kiworesultimport.ParserFactory;
|
||||
import com.sap.sailing.kiworesultimport.RegattaSummary;
|
||||
import com.sap.sailing.kiworesultimport.ZipFile;
|
||||
@@ -57,7 +58,7 @@ public class ScoreCorrectionProviderImpl extends AbstractFileBasedScoreCorrectio
|
||||
private Iterable<RegattaSummary> getAllRegattaSummaries() throws IOException, SAXException, ParserConfigurationException {
|
||||
List<RegattaSummary> result = new ArrayList<RegattaSummary>();
|
||||
ZipFileParser zipFileParser = ParserFactory.INSTANCE.createZipFileParser();
|
||||
for (Pair<InputStream, String> streamAndName : getResultDocumentProvider().getDocumentsAndNames()) {
|
||||
for (Triple<InputStream, String, TimePoint> streamAndName : getResultDocumentProvider().getDocumentsAndNamesAndLastModified()) {
|
||||
if (streamAndName.getB().toLowerCase().endsWith(".zip")) {
|
||||
ZipFile zipFile = zipFileParser.parse(streamAndName.getA());
|
||||
for (RegattaSummary regattaSummary : zipFile.getRegattaSummaries()) {
|
||||
|
||||
@@ -8,6 +8,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Export-Package: com.sap.sailing.resultimport,
|
||||
com.sap.sailing.resultimport.impl
|
||||
Import-Package: com.sap.sailing.domain.common,
|
||||
Import-Package: com.sap.sailing.domain.base.impl,
|
||||
com.sap.sailing.domain.common,
|
||||
com.sap.sailing.domain.common.impl
|
||||
Require-Bundle: org.eclipse.osgi;bundle-version="3.7.1"
|
||||
+4
-3
@@ -1,10 +1,11 @@
|
||||
package com.sap.sailing.resultimport;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
|
||||
public interface ResultDocumentProvider {
|
||||
Iterable<Pair<InputStream, String>> getDocumentsAndNames() throws FileNotFoundException;
|
||||
Iterable<Triple<InputStream, String, TimePoint>> getDocumentsAndNamesAndLastModified() throws IOException;
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.sap.sailing.resultimport.impl;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections;
|
||||
import com.sap.sailing.domain.common.ScoreCorrectionProvider;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.resultimport.ResultDocumentProvider;
|
||||
|
||||
public abstract class AbstractDocumentBasedScoreCorrectionProvider implements ScoreCorrectionProvider {
|
||||
private static final long serialVersionUID = -207867446958976110L;
|
||||
private final ResultDocumentProvider resultDocumentProvider;
|
||||
|
||||
public AbstractDocumentBasedScoreCorrectionProvider(ResultDocumentProvider resultDocumentProvider) {
|
||||
this.resultDocumentProvider = resultDocumentProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Set<Pair<String, TimePoint>>> getHasResultsForBoatClassFromDateByEventName() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegattaScoreCorrections getScoreCorrections(String eventName, String boatClassName, TimePoint timePoint)
|
||||
throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
protected ResultDocumentProvider getResultDocumentProvider() {
|
||||
return resultDocumentProvider;
|
||||
}
|
||||
}
|
||||
+2
-16
@@ -2,30 +2,16 @@ package com.sap.sailing.resultimport.impl;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.sap.sailing.domain.common.ScoreCorrectionProvider;
|
||||
import com.sap.sailing.resultimport.ResultDocumentProvider;
|
||||
|
||||
public abstract class AbstractFileBasedScoreCorrectionProvider implements ScoreCorrectionProvider {
|
||||
public abstract class AbstractFileBasedScoreCorrectionProvider extends AbstractDocumentBasedScoreCorrectionProvider {
|
||||
private static final long serialVersionUID = -4596215011753860781L;
|
||||
|
||||
private final ResultDocumentProvider resultDocumentProvider;
|
||||
|
||||
public AbstractFileBasedScoreCorrectionProvider(File scanDir) {
|
||||
super();
|
||||
super(new FileBasedResultDocumentProvider(scanDir));
|
||||
if (!scanDir.exists()) {
|
||||
scanDir.mkdirs();
|
||||
}
|
||||
if (!scanDir.isDirectory()) {
|
||||
throw new IllegalArgumentException("scanDir " + scanDir + " must be a directory");
|
||||
}
|
||||
this.resultDocumentProvider = new FileBasedResultDocumentProvider(scanDir);
|
||||
}
|
||||
|
||||
public AbstractFileBasedScoreCorrectionProvider(ResultDocumentProvider resultDocumentProvider) {
|
||||
this.resultDocumentProvider = resultDocumentProvider;
|
||||
}
|
||||
|
||||
protected ResultDocumentProvider getResultDocumentProvider() {
|
||||
return resultDocumentProvider;
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -8,7 +8,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
import com.sap.sailing.resultimport.ResultDocumentProvider;
|
||||
|
||||
public class FileBasedResultDocumentProvider implements ResultDocumentProvider {
|
||||
@@ -21,14 +23,15 @@ public class FileBasedResultDocumentProvider implements ResultDocumentProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Pair<InputStream, String>> getDocumentsAndNames() throws FileNotFoundException {
|
||||
List<Pair<InputStream, String>> result = new ArrayList<>();
|
||||
public Iterable<Triple<InputStream, String, TimePoint>> getDocumentsAndNamesAndLastModified() throws FileNotFoundException {
|
||||
List<Triple<InputStream, String, TimePoint>> result = new ArrayList<>();
|
||||
final File[] fileList = scanDir.listFiles();
|
||||
if (fileList != null) {
|
||||
for (File file : fileList) {
|
||||
if (file.isFile()) {
|
||||
logger.fine("adding " + file + " to result import list");
|
||||
result.add(new Pair<InputStream, String>(new FileInputStream(file), file.toString()));
|
||||
result.add(new Triple<InputStream, String, TimePoint>(new FileInputStream(file), file.toString(),
|
||||
new MillisecondsTimePoint(file.lastModified())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-15
@@ -1,26 +1,21 @@
|
||||
package com.sap.sailing.winregatta.resultimport.impl;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.osgi.framework.BundleActivator;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import java.io.File;
|
||||
|
||||
import com.sap.sailing.domain.common.ScoreCorrectionProvider;
|
||||
import com.sap.sailing.resultimport.impl.AbstractFileBasedScoreCorrectionProviderActivator;
|
||||
import com.sap.sailing.resultimport.impl.FileBasedResultDocumentProvider;
|
||||
|
||||
public class Activator implements BundleActivator {
|
||||
public class Activator extends AbstractFileBasedScoreCorrectionProviderActivator {
|
||||
private static final String SCAN_DIR_PATH_PROPERTY_NAME = "barbados.results";
|
||||
private static final String DEFAULT_SCAN_DIR = "barbados";
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Activator.class.getName());
|
||||
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
|
||||
final ScoreCorrectionProviderImpl service = new ScoreCorrectionProviderImpl();
|
||||
context.registerService(ScoreCorrectionProvider.class,
|
||||
service, /* properties */ null);
|
||||
logger.info("Scanning for official result lists of "+service.getName());
|
||||
public Activator() {
|
||||
super(SCAN_DIR_PATH_PROPERTY_NAME, DEFAULT_SCAN_DIR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
protected ScoreCorrectionProvider create(File scanDir) {
|
||||
return new ScoreCorrectionProviderImpl(new FileBasedResultDocumentProvider(scanDir));
|
||||
}
|
||||
}
|
||||
+236
-237
@@ -9,288 +9,287 @@ 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 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;
|
||||
|
||||
public Object getResultKey() {
|
||||
return sailNumber;
|
||||
}
|
||||
private double totalScore;
|
||||
private int racesCount = 6;
|
||||
|
||||
public Integer getTotalRank() {
|
||||
return totalRank;
|
||||
}
|
||||
public CompetitorRowImpl() {
|
||||
ranks = new LinkedHashMap<Integer, String>();
|
||||
scores = new LinkedHashMap<Integer, String>();
|
||||
}
|
||||
|
||||
public void setTotalRank(Integer totalRank) {
|
||||
this.totalRank = totalRank;
|
||||
}
|
||||
public Object getResultKey() {
|
||||
return sailNumber;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
public Integer getTotalRank() {
|
||||
return totalRank;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
public void setTotalRank(Integer totalRank) {
|
||||
this.totalRank = totalRank;
|
||||
}
|
||||
|
||||
public String getSailNumber() {
|
||||
return sailNumber;
|
||||
}
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setSailNumber(String sailNumber) {
|
||||
this.sailNumber = sailNumber;
|
||||
}
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public String getTeamMember1Name() {
|
||||
return teamMember1Name;
|
||||
}
|
||||
public String getSailNumber() {
|
||||
return sailNumber;
|
||||
}
|
||||
|
||||
public void setTeamMember1Name(String teamMember1Name) {
|
||||
this.teamMember1Name = teamMember1Name;
|
||||
}
|
||||
public void setSailNumber(String sailNumber) {
|
||||
this.sailNumber = sailNumber;
|
||||
}
|
||||
|
||||
public String getTeamMember1Club() {
|
||||
return teamMember1Club;
|
||||
}
|
||||
public String getTeamMember1Name() {
|
||||
return teamMember1Name;
|
||||
}
|
||||
|
||||
public void setTeamMember1Club(String teamMember1Club) {
|
||||
this.teamMember1Club = teamMember1Club;
|
||||
}
|
||||
public void setTeamMember1Name(String teamMember1Name) {
|
||||
this.teamMember1Name = teamMember1Name;
|
||||
}
|
||||
|
||||
public String getTeamMember1DSVNumber() {
|
||||
return teamMember1DSVNumber;
|
||||
}
|
||||
public String getTeamMember1Club() {
|
||||
return teamMember1Club;
|
||||
}
|
||||
|
||||
public void setTeamMember1DSVNumber(String teamMember1DSVNumber) {
|
||||
this.teamMember1DSVNumber = teamMember1DSVNumber;
|
||||
}
|
||||
public void setTeamMember1Club(String teamMember1Club) {
|
||||
this.teamMember1Club = teamMember1Club;
|
||||
}
|
||||
|
||||
public String getTeamMember2Name() {
|
||||
return teamMember2Name;
|
||||
}
|
||||
public String getTeamMember1DSVNumber() {
|
||||
return teamMember1DSVNumber;
|
||||
}
|
||||
|
||||
public void setTeamMember2Name(String teamMember2Name) {
|
||||
this.teamMember2Name = teamMember2Name;
|
||||
}
|
||||
public void setTeamMember1DSVNumber(String teamMember1DSVNumber) {
|
||||
this.teamMember1DSVNumber = teamMember1DSVNumber;
|
||||
}
|
||||
|
||||
public String getTeamMember2Club() {
|
||||
return teamMember2Club;
|
||||
}
|
||||
public String getTeamMember2Name() {
|
||||
return teamMember2Name;
|
||||
}
|
||||
|
||||
public void setTeamMember2Club(String teamMember2Club) {
|
||||
this.teamMember2Club = teamMember2Club;
|
||||
}
|
||||
public void setTeamMember2Name(String teamMember2Name) {
|
||||
this.teamMember2Name = teamMember2Name;
|
||||
}
|
||||
|
||||
public String getTeamMember2DSVNumber() {
|
||||
return teamMember2DSVNumber;
|
||||
}
|
||||
public String getTeamMember2Club() {
|
||||
return teamMember2Club;
|
||||
}
|
||||
|
||||
public void setTeamMember2DSVNumber(String teamMember2DSVNumber) {
|
||||
this.teamMember2DSVNumber = teamMember2DSVNumber;
|
||||
}
|
||||
public void setTeamMember2Club(String teamMember2Club) {
|
||||
this.teamMember2Club = teamMember2Club;
|
||||
}
|
||||
|
||||
public String getTeamMember3Name() {
|
||||
return teamMember3Name;
|
||||
}
|
||||
public String getTeamMember2DSVNumber() {
|
||||
return teamMember2DSVNumber;
|
||||
}
|
||||
|
||||
public void setTeamMember3Name(String teamMember3Name) {
|
||||
this.teamMember3Name = teamMember3Name;
|
||||
}
|
||||
public void setTeamMember2DSVNumber(String teamMember2DSVNumber) {
|
||||
this.teamMember2DSVNumber = teamMember2DSVNumber;
|
||||
}
|
||||
|
||||
public String getTeamMember3Club() {
|
||||
return teamMember3Club;
|
||||
}
|
||||
public String getTeamMember3Name() {
|
||||
return teamMember3Name;
|
||||
}
|
||||
|
||||
public void setTeamMember3Club(String teamMember3Club) {
|
||||
this.teamMember3Club = teamMember3Club;
|
||||
}
|
||||
public void setTeamMember3Name(String teamMember3Name) {
|
||||
this.teamMember3Name = teamMember3Name;
|
||||
}
|
||||
|
||||
public String getTeamMember3DSVNumber() {
|
||||
return teamMember3DSVNumber;
|
||||
}
|
||||
public String getTeamMember3Club() {
|
||||
return teamMember3Club;
|
||||
}
|
||||
|
||||
public void setTeamMember3DSVNumber(String teamMember3DSVNumber) {
|
||||
this.teamMember3DSVNumber = teamMember3DSVNumber;
|
||||
}
|
||||
public void setTeamMember3Club(String teamMember3Club) {
|
||||
this.teamMember3Club = teamMember3Club;
|
||||
}
|
||||
|
||||
public void setRace1Rank(String raceRank) {
|
||||
if(raceRank != null) {
|
||||
ranks.put(1, raceRank);
|
||||
}
|
||||
}
|
||||
public String getTeamMember3DSVNumber() {
|
||||
return teamMember3DSVNumber;
|
||||
}
|
||||
|
||||
public void setRace1Score(String raceScore) {
|
||||
if(raceScore != null) {
|
||||
scores.put(1, raceScore);
|
||||
}
|
||||
}
|
||||
public void setTeamMember3DSVNumber(String teamMember3DSVNumber) {
|
||||
this.teamMember3DSVNumber = teamMember3DSVNumber;
|
||||
}
|
||||
|
||||
public void setRace2Rank(String raceRank) {
|
||||
if(raceRank != null) {
|
||||
ranks.put(2, raceRank);
|
||||
}
|
||||
}
|
||||
public void setRace1Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(1, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace2Score(String raceScore) {
|
||||
if(raceScore != null) {
|
||||
scores.put(2, raceScore);
|
||||
}
|
||||
}
|
||||
public void setRace1Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(1, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace3Rank(String raceRank) {
|
||||
if(raceRank != null) {
|
||||
ranks.put(3, raceRank);
|
||||
}
|
||||
}
|
||||
public void setRace2Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(2, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace3Score(String raceScore) {
|
||||
if(raceScore != null) {
|
||||
scores.put(3, raceScore);
|
||||
}
|
||||
}
|
||||
public void setRace2Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(2, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace4Rank(String raceRank) {
|
||||
if(raceRank != null) {
|
||||
ranks.put(4, raceRank);
|
||||
}
|
||||
}
|
||||
public void setRace3Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(3, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace4Score(String raceScore) {
|
||||
if(raceScore != null) {
|
||||
scores.put(4, raceScore);
|
||||
}
|
||||
}
|
||||
public void setRace3Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(3, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace5Rank(String raceRank) {
|
||||
if(raceRank != null) {
|
||||
ranks.put(5, raceRank);
|
||||
}
|
||||
}
|
||||
public void setRace4Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(4, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace5Score(String raceScore) {
|
||||
if(raceScore != null) {
|
||||
scores.put(5, raceScore);
|
||||
}
|
||||
}
|
||||
public void setRace4Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(4, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace6Rank(String raceRank) {
|
||||
if(raceRank != null) {
|
||||
ranks.put(6, raceRank);
|
||||
}
|
||||
}
|
||||
public void setRace5Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(5, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setRace6Score(String raceScore) {
|
||||
if(raceScore != null) {
|
||||
scores.put(6, raceScore);
|
||||
}
|
||||
}
|
||||
public void setRace5Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(5, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
public double getTotalScore() {
|
||||
return totalScore;
|
||||
}
|
||||
public void setRace6Rank(String raceRank) {
|
||||
if (raceRank != null) {
|
||||
ranks.put(6, raceRank);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTotalScore(double totalScore) {
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
public void setRace6Score(String raceScore) {
|
||||
if (raceScore != null) {
|
||||
scores.put(6, raceScore);
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
public double getTotalScore() {
|
||||
return totalScore;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
public void setTotalScore(double totalScore) {
|
||||
this.totalScore = totalScore;
|
||||
}
|
||||
|
||||
return competitorEntries;
|
||||
}
|
||||
@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;
|
||||
|
||||
@Override
|
||||
public Double getNetPointsBeforeDiscarding() {
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getScoreAfterDiscarding() {
|
||||
return null;
|
||||
}
|
||||
String scoreAsString = scores.get(i);
|
||||
if (scoreAsString.startsWith("(") && scoreAsString.endsWith(")")) {
|
||||
scoreAsString = scoreAsString.substring(1, scoreAsString.length() - 1);
|
||||
discarded = true;
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
Double score;
|
||||
try {
|
||||
score = Double.valueOf(scoreAsString);
|
||||
maxPointsReason = null;
|
||||
} catch (NumberFormatException nfe) {
|
||||
// must have been a disqualification / max-points-reason
|
||||
score = null;
|
||||
maxPointsReason = scoreAsString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCompetitorName() {
|
||||
return teamMember1Name;
|
||||
}
|
||||
competitorEntries.add(new DefaultCompetitorEntryImpl(rank, maxPointsReason, score, discarded));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSailID() {
|
||||
return country.trim() + sailNumber.trim();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.sap.sailing.winregatta.resultimport.impl;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
|
||||
public class ExcelDateFormatterUtil {
|
||||
String valueAsString;
|
||||
Date valueAsDate;
|
||||
|
||||
public ExcelDateFormatterUtil(String importedDate) {
|
||||
if (importedDate != null && !importedDate.isEmpty()) {
|
||||
// the format is in excel time format (number between 0 and 1)
|
||||
try {
|
||||
Double value = Double.parseDouble(importedDate) * 86400;
|
||||
Long valueInSeconds = value.longValue();
|
||||
|
||||
this.valueAsDate = new Date(valueInSeconds * 1000);
|
||||
this.valueAsString = String
|
||||
.format("%02d:%02d:%02d", valueInSeconds / 3600,
|
||||
(valueInSeconds % 3600) / 60,
|
||||
(valueInSeconds % 60));
|
||||
} catch (NumberFormatException e) {
|
||||
this.valueAsString = "Invalid format: " + importedDate;
|
||||
}
|
||||
} else {
|
||||
valueAsString = importedDate;
|
||||
valueAsDate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-13
@@ -1,35 +1,29 @@
|
||||
package com.sap.sailing.winregatta.resultimport.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections;
|
||||
import com.sap.sailing.domain.common.ScoreCorrectionProvider;
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.resultimport.RegattaResults;
|
||||
import com.sap.sailing.resultimport.UrlResultProvider;
|
||||
import com.sap.sailing.resultimport.ResultDocumentProvider;
|
||||
import com.sap.sailing.resultimport.impl.AbstractDocumentBasedScoreCorrectionProvider;
|
||||
import com.sap.sailing.resultimport.impl.RegattaScoreCorrectionsImpl;
|
||||
|
||||
public class ScoreCorrectionProviderImpl implements ScoreCorrectionProvider, UrlResultProvider {
|
||||
private static final long serialVersionUID = -5501186796881875686L;
|
||||
public class ScoreCorrectionProviderImpl extends AbstractDocumentBasedScoreCorrectionProvider {
|
||||
private static final long serialVersionUID = -5501186796881875686L;
|
||||
|
||||
private static final String name = "'WinRegatta Plus' XLS Score Importer";
|
||||
private static final String name = "Barbados 2013 505 Worlds Excel Result Importer";
|
||||
|
||||
private final Set<URL> allUrls;
|
||||
|
||||
private String sheetName = "Erg_Drachen";
|
||||
|
||||
public ScoreCorrectionProviderImpl() throws MalformedURLException {
|
||||
allUrls = new HashSet<URL>();
|
||||
public ScoreCorrectionProviderImpl(ResultDocumentProvider resultDocumentProvider) {
|
||||
super(resultDocumentProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+8
-6
@@ -33,6 +33,7 @@ import com.sap.sailing.domain.common.RegattaScoreCorrections.ScoreCorrectionsFor
|
||||
import com.sap.sailing.domain.common.TimePoint;
|
||||
import com.sap.sailing.domain.common.impl.Util;
|
||||
import com.sap.sailing.domain.common.impl.Util.Pair;
|
||||
import com.sap.sailing.domain.common.impl.Util.Triple;
|
||||
import com.sap.sailing.resultimport.ResultDocumentProvider;
|
||||
import com.sap.sailing.xrr.resultimport.ParserFactory;
|
||||
import com.sap.sailing.xrr.resultimport.impl.ScoreCorrectionProviderImpl;
|
||||
@@ -56,13 +57,14 @@ public class ParserTest {
|
||||
private ResultDocumentProvider getTestDocumentProvider() {
|
||||
return new ResultDocumentProvider() {
|
||||
@Override
|
||||
public Iterable<Pair<InputStream, String>> getDocumentsAndNames() throws FileNotFoundException {
|
||||
public Iterable<Triple<InputStream, String, TimePoint>> getDocumentsAndNamesAndLastModified() throws FileNotFoundException {
|
||||
try {
|
||||
List<Pair<InputStream, String>> result = new ArrayList<>();
|
||||
result.add(new Pair<InputStream, String>(getInputStream(SAMPLE_INPUT_NAME_LASER), SAMPLE_INPUT_NAME_LASER));
|
||||
result.add(new Pair<InputStream, String>(getInputStream(SAMPLE_INPUT_NAME_STAR), SAMPLE_INPUT_NAME_STAR));
|
||||
result.add(new Pair<InputStream, String>(getInputStream(SAMPLE_INPUT_NAME_MELBOURNE), SAMPLE_INPUT_NAME_MELBOURNE));
|
||||
result.add(new Pair<InputStream, String>(getInputStream(SAMPLE_INPUT_NAME_SPLIT_FLEET), SAMPLE_INPUT_NAME_SPLIT_FLEET));
|
||||
List<Triple<InputStream, String, TimePoint>> result = new ArrayList<>();
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
result.add(new Triple<InputStream, String, TimePoint>(getInputStream(SAMPLE_INPUT_NAME_LASER), SAMPLE_INPUT_NAME_LASER, now));
|
||||
result.add(new Triple<InputStream, String, TimePoint>(getInputStream(SAMPLE_INPUT_NAME_STAR), SAMPLE_INPUT_NAME_STAR, now));
|
||||
result.add(new Triple<InputStream, String, TimePoint>(getInputStream(SAMPLE_INPUT_NAME_MELBOURNE), SAMPLE_INPUT_NAME_MELBOURNE, now));
|
||||
result.add(new Triple<InputStream, String, TimePoint>(getInputStream(SAMPLE_INPUT_NAME_SPLIT_FLEET), SAMPLE_INPUT_NAME_SPLIT_FLEET, now));
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
+4
-3
@@ -20,15 +20,16 @@ import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
|
||||
import com.sap.sailing.domain.common.RegattaScoreCorrections;
|
||||
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;
|
||||
import com.sap.sailing.resultimport.ResultDocumentProvider;
|
||||
import com.sap.sailing.resultimport.impl.AbstractFileBasedScoreCorrectionProvider;
|
||||
import com.sap.sailing.resultimport.impl.AbstractDocumentBasedScoreCorrectionProvider;
|
||||
import com.sap.sailing.xrr.resultimport.Parser;
|
||||
import com.sap.sailing.xrr.resultimport.ParserFactory;
|
||||
import com.sap.sailing.xrr.resultimport.schema.Division;
|
||||
import com.sap.sailing.xrr.resultimport.schema.Event;
|
||||
import com.sap.sailing.xrr.resultimport.schema.RegattaResults;
|
||||
|
||||
public class ScoreCorrectionProviderImpl extends AbstractFileBasedScoreCorrectionProvider {
|
||||
public class ScoreCorrectionProviderImpl extends AbstractDocumentBasedScoreCorrectionProvider {
|
||||
private static final Logger logger = Logger.getLogger(ScoreCorrectionProviderImpl.class.getName());
|
||||
private static final long serialVersionUID = -4596215011753860781L;
|
||||
|
||||
@@ -128,7 +129,7 @@ public class ScoreCorrectionProviderImpl extends AbstractFileBasedScoreCorrectio
|
||||
private Iterable<Parser> getAllRegattaResults() throws SAXException, IOException,
|
||||
ParserConfigurationException {
|
||||
List<Parser> result = new ArrayList<>();
|
||||
for (Pair<InputStream, String> is : getResultDocumentProvider().getDocumentsAndNames()) {
|
||||
for (Triple<InputStream, String, TimePoint> is : getResultDocumentProvider().getDocumentsAndNamesAndLastModified()) {
|
||||
Parser parser = parserFactory.createParser(is.getA(), is.getB());
|
||||
result.add(parser);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user