fixed time formats in SwissTiming connector

This commit is contained in:
Axel Uhl committed 2011-09-30 23:29:01 +02:00
1 parent f93a4e1729
commit 8c87a0e8f9
3 files changed
+19 -12

No files matched your search

@@ -67,15 +67,15 @@ public class SailMasterDummy implements Runnable {
} }
} else if ("StartList".equals(sections[0])) { } else if ("StartList".equals(sections[0])) {
if (sections[1].equals("4711")) { if (sections[1].equals("4711")) {
transceiver.sendMessage("StartList|"+sections[1]+"|GER 8414,GER,Polgar/Koy|GER 8140,GER,Schlonski/Bohn", os); transceiver.sendMessage("Startlist|"+sections[1]+"|GER 8414,GER,Polgar/Koy|GER 8140,GER,Schlonski/Bohn", os);
} else if (sections[1].equals("4712")) { } else if (sections[1].equals("4712")) {
transceiver.sendMessage("StartList|"+sections[1]+"|GER 8340,GER,Stanjek/Kleen|GER 8433,GER,Babendererde/Jacobs|GER 8299,GER,Elsner/Schulz", os); transceiver.sendMessage("Startlist|"+sections[1]+"|GER 8340,GER,Stanjek/Kleen|GER 8433,GER,Babendererde/Jacobs|GER 8299,GER,Elsner/Schulz", os);
} }
} else if ("RaceTime".equals(sections[0])) { } else if ("RaceTime".equals(sections[0])) {
if (sections[1].equals("4711")) { if (sections[1].equals("4711")) {
transceiver.sendMessage("RaceTime|"+sections[1]+"|72498724937", os); transceiver.sendMessage("RaceTime|"+sections[1]+"|10:15:22", os);
} else if (sections[1].equals("4712")) { } else if (sections[1].equals("4712")) {
transceiver.sendMessage("RaceTime|"+sections[1]+"|61283761239", os); transceiver.sendMessage("RaceTime|"+sections[1]+"|18:17:23", os);
} }
} else if ("ClockAtMark".equals(sections[0])) { } else if ("ClockAtMark".equals(sections[0])) {
@@ -2,6 +2,7 @@ package com.sap.sailing.domain.swisstimingadapter;
import java.io.IOException; import java.io.IOException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.ParseException;
import java.util.Map; import java.util.Map;
import com.sap.sailing.domain.base.TimePoint; import com.sap.sailing.domain.base.TimePoint;
@@ -16,7 +17,7 @@ public interface SailMasterConnector {
StartList getStartList(String raceID) throws UnknownHostException, IOException; StartList getStartList(String raceID) throws UnknownHostException, IOException;
TimePoint getStartTime(String raceID) throws UnknownHostException, IOException; TimePoint getStartTime(String raceID) throws UnknownHostException, IOException, ParseException;
/** /**
* @param markIndex * @param markIndex
@@ -24,7 +25,7 @@ public interface SailMasterConnector {
* @return a map with the single mark index requested by <code>markIndex</code> or all mark indices (in case of * @return a map with the single mark index requested by <code>markIndex</code> or all mark indices (in case of
* <code>markIndex==-1</code>) as key; pairs of gap (TODO in milliseconds?) and boat ID as values. * <code>markIndex==-1</code>) as key; pairs of gap (TODO in milliseconds?) and boat ID as values.
*/ */
Map<Integer, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException; Map<Integer, Pair<TimePoint, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException, NumberFormatException, ParseException;
double getDistanceToMarkInMeters(String raceID, int markIndex, String boatID) throws UnknownHostException, IOException; double getDistanceToMarkInMeters(String raceID, int markIndex, String boatID) throws UnknownHostException, IOException;
@@ -4,6 +4,9 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@@ -25,6 +28,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
private final String host; private final String host;
private final int port; private final int port;
private Socket socket; private Socket socket;
private static final DateFormat dateFormat = new SimpleDateFormat("hh:MM:ss");
public SailMasterConnectorImpl(String host, int port) { public SailMasterConnectorImpl(String host, int port) {
super(); super();
@@ -106,7 +110,7 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
public StartList getStartList(String raceID) throws UnknownHostException, IOException { public StartList getStartList(String raceID) throws UnknownHostException, IOException {
SailMasterMessage response = sendRequestAndGetResponse("StartList|"+raceID); SailMasterMessage response = sendRequestAndGetResponse("StartList|"+raceID);
String[] sections = response.getSections(); String[] sections = response.getSections();
assertResponseType("StartList", sections[0]); assertResponseType("Startlist", sections[0]);
assertRaceID(raceID, sections[1]); assertRaceID(raceID, sections[1]);
ArrayList<Competitor> competitors = new ArrayList<Competitor>(); ArrayList<Competitor> competitors = new ArrayList<Competitor>();
for (int i=2; i<sections.length; i++) { for (int i=2; i<sections.length; i++) {
@@ -117,24 +121,26 @@ public class SailMasterConnectorImpl extends SailMasterTransceiver implements Sa
} }
@Override @Override
public TimePoint getStartTime(String raceID) throws UnknownHostException, IOException { public TimePoint getStartTime(String raceID) throws UnknownHostException, IOException, ParseException {
SailMasterMessage response = sendRequestAndGetResponse("RaceTime|"+raceID); SailMasterMessage response = sendRequestAndGetResponse("RaceTime|"+raceID);
String[] sections = response.getSections(); String[] sections = response.getSections();
assertResponseType("RaceTime", sections[0]); assertResponseType("RaceTime", sections[0]);
assertRaceID(raceID, sections[1]); assertRaceID(raceID, sections[1]);
return new MillisecondsTimePoint(Long.valueOf(sections[2])); return new MillisecondsTimePoint(dateFormat.parse(sections[2]));
} }
@Override @Override
public Map<Integer, Pair<Long, String>> getDeltaClockAtMark(String raceID, int markIndex) throws UnknownHostException, IOException { public Map<Integer, Pair<TimePoint, String>> getDeltaClockAtMark(String raceID, int markIndex)
throws UnknownHostException, IOException, NumberFormatException, ParseException {
SailMasterMessage response = sendRequestAndGetResponse("ClockAtMark|"+raceID+"|"+markIndex); SailMasterMessage response = sendRequestAndGetResponse("ClockAtMark|"+raceID+"|"+markIndex);
String[] sections = response.getSections(); String[] sections = response.getSections();
assertResponseType("ClockAtMark", sections[0]); assertResponseType("ClockAtMark", sections[0]);
assertRaceID(raceID, sections[1]); assertRaceID(raceID, sections[1]);
Map<Integer, Pair<Long, String>> result = new HashMap<Integer, Pair<Long,String>>(); Map<Integer, Pair<TimePoint, String>> result = new HashMap<Integer, Pair<TimePoint,String>>();
for (int i=2; i<sections.length; i+=2) { for (int i=2; i<sections.length; i+=2) {
String[] markTimeDetail = sections[i+1].split(","); String[] markTimeDetail = sections[i+1].split(",");
result.put(Integer.valueOf(sections[i]), new Pair<Long, String>(Long.valueOf(markTimeDetail[0]), markTimeDetail[1])); result.put(Integer.valueOf(sections[i]), new Pair<TimePoint, String>(
new MillisecondsTimePoint(dateFormat.parse(markTimeDetail[0])), markTimeDetail[1]));
} }
return result; return result;
} }