added two new bundles for Extreme Sailing Series result import

This commit is contained in:
Axel Uhl committed 2012-07-08 00:58:00 +02:00
1 parent 81cef75cfc
commit 70a053b219
17 files changed
+334

No files matched your search

@@ -21,5 +21,16 @@ public interface ScoreCorrectionProvider extends Named {
*/
public Map<String, Set<Pair<String, TimePoint>>> getHasResultsForBoatClassFromDateByEventName() throws Exception;
/**
* @param eventName
* as provided by the keys of the result map returned by
* {@link #getHasResultsForBoatClassFromDateByEventName()}
* @param boatClassName
* as provided by the {@link Pair#getA()} method on the values of the map returned by
* {@link #getHasResultsForBoatClassFromDateByEventName()}
* @param millisecondsTimePoint
* a time point as returned in the {@link Pair#getB()} component of the values in the map returned by
* {@link #getHasResultsForBoatClassFromDateByEventName()}.
*/
public RegattaScoreCorrections getScoreCorrections(String eventName, String boatClassName, TimePoint millisecondsTimePoint) throws Exception;
}
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.sap.sailing.ess40.resultimport.test</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
pluginProject.extensions=false
resolve.requirebundle=false
@@ -0,0 +1,12 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test
Bundle-SymbolicName: com.sap.sailing.ess40.resultimport.test
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: SAP
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-ActivationPolicy: lazy
Require-Bundle: com.sap.sailing.ess40.resultimport,
org.junit4;bundle-version="4.8.2",
com.sap.sailing.domain.common
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,34 @@
package com.sap.sailing.ess40.resultimport.test;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
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.ess40.resultimport.impl.ScoreCorrectionProviderImpl;
public class SimpleESS40ResultImportTest {
@Test
public void testProviderFound() throws Exception {
ScoreCorrectionProvider scp = new ScoreCorrectionProviderImpl();
Map<String, Set<Pair<String, TimePoint>>> hasResult = scp.getHasResultsForBoatClassFromDateByEventName();
assertTrue(hasResult.containsKey("qingdao"));
}
@Test
public void testQingdaoResults() throws Exception {
ScoreCorrectionProvider scp = new ScoreCorrectionProviderImpl();
Map<String, Set<Pair<String, TimePoint>>> hasResult = scp.getHasResultsForBoatClassFromDateByEventName();
RegattaScoreCorrections qingdaoResults = scp.getScoreCorrections("qingdao", "extreme 40", hasResult.get("qingdao").iterator().next().getB());
assertNotNull(qingdaoResults);
// TODO continue here and require results to match what we see in the CSV
}
}
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.sap.sailing.ess40.resultimport</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,7 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
@@ -0,0 +1,3 @@
eclipse.preferences.version=1
pluginProject.extensions=false
resolve.requirebundle=false
@@ -0,0 +1,14 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Resultimport
Bundle-SymbolicName: com.sap.sailing.ess40.resultimport
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: com.sap.sailing.ess40.resultimport.Activator
Bundle-Vendor: SAP
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Import-Package: org.osgi.framework;version="1.3.0"
Bundle-ActivationPolicy: lazy
Require-Bundle: com.sap.sailing.domain,
com.sap.sailing.domain.common
Export-Package: com.sap.sailing.ess40.resultimport,
com.sap.sailing.ess40.resultimport.impl;x-friends:="com.sap.sailing.ess40.resultimport.test"
+4
View File
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
@@ -0,0 +1,36 @@
package com.sap.sailing.ess40.resultimport;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import com.sap.sailing.domain.common.ScoreCorrectionProvider;
import com.sap.sailing.ess40.resultimport.impl.ScoreCorrectionProviderImpl;
public class Activator implements BundleActivator {
private static BundleContext context;
static BundleContext getContext() {
return context;
}
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext bundleContext) throws Exception {
Activator.context = bundleContext;
final ScoreCorrectionProviderImpl service = new ScoreCorrectionProviderImpl();
context.registerService(ScoreCorrectionProvider.class, service, /* properties */null);
}
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext bundleContext) throws Exception {
Activator.context = null;
}
}
@@ -0,0 +1,36 @@
package com.sap.sailing.ess40.resultimport.impl;
import java.util.List;
import java.util.Map;
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;
public class RegattaScoreCorrectionsImpl implements RegattaScoreCorrections {
private final ScoreCorrectionProviderImpl provider;
public RegattaScoreCorrectionsImpl(ScoreCorrectionProviderImpl scoreCorrectionProviderImpl,
Pair<TimePoint, Map<String, List<Pair<String, Integer>>>> actResults) {
this.provider = scoreCorrectionProviderImpl;
}
@Override
public ScoreCorrectionProvider getProvider() {
return provider;
}
@Override
public String getRegattaName() {
// TODO Auto-generated method stub
return null;
}
@Override
public Iterable<ScoreCorrectionsForRace> getScoreCorrectionsForRaces() {
// TODO Auto-generated method stub
return null;
}
}
@@ -0,0 +1,93 @@
package com.sap.sailing.ess40.resultimport.impl;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
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;
public class ScoreCorrectionProviderImpl implements ScoreCorrectionProvider {
private static final long serialVersionUID = -4870646572106575667L;
private static final String[] ACT_NAMES = { "muscat", "qingdao", "istanbul", "porto" /*, "cardiff" */};
private static final String EXTREME_40_CLASS_NAME = "extreme 40";
@Override
public String getName() {
return "Extreme Sailing Series 40 Scores from SailRacer.org";
}
private List<URL> getCsvUrls(String... actNames) throws MalformedURLException {
List<URL> result = new ArrayList<URL>();
for (String actName : actNames) {
result.add(new URL("http://www.extremesailingseries.com/app/results/csv_uploads/"+actName+".csv"));
}
return result;
}
/**
* @return A pair whose first component is the time point of the last modification to the act results, the second
* element is a map whose keys are the sail IDs (in the Extreme Sailing Series we'll use the team names as
* the sail IDs, such as "SAP Extreme Sailing Team" or just "SAP" for short); values with be a list
* representing the act's races, from first to last, where each {@link Pair} holds in its first component a
* string describing the rank, which could be an integer number formatted as a string, or a three-letter
* disqualification reason such as "DNC", "DNF" or "DNS"; the second component is the points the competitor
* scored in that race. Usually, if the first component is a number, the score can be expected to be
* <code>#competitors+1 - rank</code>. A disqualification gets 0 points.
*/
private Pair<TimePoint, Map<String, List<Pair<String, Integer>>>> getActResults(URL actUrl) throws IOException {
Map<String, List<Pair<String, Integer>>> result = new HashMap<String, List<Pair<String,Integer>>>();
HttpURLConnection conn = (HttpURLConnection) actUrl.openConnection();
TimePoint lastModified = new MillisecondsTimePoint(conn.getLastModified());
BufferedReader br = new BufferedReader(new InputStreamReader((InputStream) conn.getContent()));
String line = br.readLine();
while (line != null) {
String[] split = line.split(",");
String sailID = split[0].trim();
List<Pair<String, Integer>> competitorEntry = new ArrayList<Pair<String, Integer>>();
result.put(sailID, competitorEntry);
for (int i=1; i<split.length-1; i+=2) {
String rankOrMaxPointsReason = split[i];
Integer points = Integer.valueOf(split[i+1]);
competitorEntry.add(new Pair<String, Integer>(rankOrMaxPointsReason, points));
}
line = br.readLine();
}
return new Pair<TimePoint, Map<String, List<Pair<String, Integer>>>>(lastModified, result);
}
@Override
public Map<String, Set<Pair<String, TimePoint>>> getHasResultsForBoatClassFromDateByEventName() throws Exception {
Map<String, Set<Pair<String, TimePoint>>> result = new HashMap<String, Set<Pair<String, TimePoint>>>();
for (String actName : ACT_NAMES) {
URL actUrl = getCsvUrls(actName).iterator().next();
Pair<TimePoint, Map<String, List<Pair<String, Integer>>>> actResults = getActResults(actUrl);
result.put(actName, Collections.singleton(new Pair<String, TimePoint>(EXTREME_40_CLASS_NAME, actResults.getA())));
}
return result;
}
@Override
public RegattaScoreCorrections getScoreCorrections(String actName, String boatClassName,
TimePoint millisecondsTimePoint) throws Exception {
URL actUrl = getCsvUrls(actName).iterator().next();
Pair<TimePoint, Map<String, List<Pair<String, Integer>>>> actResults = getActResults(actUrl);
return new RegattaScoreCorrectionsImpl(this, actResults);
}
}