createAndOpenReplicationServiceTracker(
@@ -698,7 +689,6 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
*
*
* Otherwise, the leaderboard is computed synchronously on the fly.
- *
* @param previousLeaderboardId
* if null or no leaderboard with that {@link LeaderboardDTO#getId() ID} is known, a
* {@link FullLeaderboardDTO} will be computed; otherwise, an {@link IncrementalLeaderboardDTO} will be
@@ -707,8 +697,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
@Override
public IncrementalOrFullLeaderboardDTO getLeaderboardByName(final String leaderboardName, final Date date,
final Collection namesOfRaceColumnsForWhichToLoadLegDetails, boolean addOverallDetails,
- String previousLeaderboardId, boolean fillNetPointsUncorrected) throws NoWindException,
- InterruptedException, ExecutionException, IllegalArgumentException {
+ String previousLeaderboardId, boolean fillNetPointsUncorrected) throws NoWindException, InterruptedException, ExecutionException,
+ IllegalArgumentException {
try {
long startOfRequestHandling = System.currentTimeMillis();
IncrementalOrFullLeaderboardDTO result = null;
@@ -721,8 +711,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
timePoint = new MillisecondsTimePoint(date);
}
LeaderboardDTO leaderboardDTO = leaderboard.getLeaderboardDTO(timePoint,
- namesOfRaceColumnsForWhichToLoadLegDetails, addOverallDetails, getService(), baseDomainFactory,
- fillNetPointsUncorrected);
+ namesOfRaceColumnsForWhichToLoadLegDetails, addOverallDetails, getService(), baseDomainFactory, fillNetPointsUncorrected);
LeaderboardDTO previousLeaderboardDTO = null;
synchronized (leaderboardByNameResultsCacheById) {
leaderboardByNameResultsCacheById.put(leaderboardDTO.getId(), leaderboardDTO);
@@ -730,22 +719,18 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
previousLeaderboardDTO = leaderboardByNameResultsCacheById.get(previousLeaderboardId);
}
}
- // Un-comment the following lines if you need to update the file used by LeaderboardDTODiffingTest, set
- // a breakpoint
+ // Un-comment the following lines if you need to update the file used by LeaderboardDTODiffingTest, set a breakpoint
// and toggle the storeLeaderboardForTesting flag if you found a good version. See also bug 1417.
- // boolean storeLeaderboardForTesting = false;
- // if (storeLeaderboardForTesting) {
- // ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new
- // File("c:/data/SAP/sailing/workspace/java/com.sap.sailing.domain.test/resources/IncrementalLeaderboardDTO.ser")));
- // oos.writeObject(leaderboardDTO);
- // oos.close();
- // }
+// boolean storeLeaderboardForTesting = false;
+// if (storeLeaderboardForTesting) {
+// ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("c:/data/SAP/sailing/workspace/java/com.sap.sailing.domain.test/resources/IncrementalLeaderboardDTO.ser")));
+// oos.writeObject(leaderboardDTO);
+// oos.close();
+// }
final IncrementalLeaderboardDTO cachedDiff;
if (previousLeaderboardId != null) {
synchronized (leaderboardDifferenceCacheByIdPair) {
- cachedDiff = leaderboardDifferenceCacheByIdPair
- .get(new com.sap.sse.common.Util.Pair(previousLeaderboardId,
- leaderboardDTO.getId()));
+ cachedDiff = leaderboardDifferenceCacheByIdPair.get(new com.sap.sse.common.Util.Pair(previousLeaderboardId, leaderboardDTO.getId()));
}
if (cachedDiff == null) {
leaderboardDifferenceCacheByIdPairMisses++;
@@ -760,18 +745,15 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
} else {
final IncrementalLeaderboardDTO incrementalResult;
if (cachedDiff == null) {
- IncrementalLeaderboardDTO preResult = new IncrementalLeaderboardDTOCloner().clone(
- leaderboardDTO).strip(previousLeaderboardDTO);
+ IncrementalLeaderboardDTO preResult = new IncrementalLeaderboardDTOCloner().clone(leaderboardDTO).strip(previousLeaderboardDTO);
synchronized (leaderboardDifferenceCacheByIdPair) {
- leaderboardDifferenceCacheByIdPair.put(new com.sap.sse.common.Util.Pair(
- previousLeaderboardId, leaderboardDTO.getId()), preResult);
+ leaderboardDifferenceCacheByIdPair.put(new com.sap.sse.common.Util.Pair(previousLeaderboardId, leaderboardDTO.getId()), preResult);
}
incrementalResult = preResult;
} else {
incrementalResult = cachedDiff;
}
- incrementalResult.setCurrentServerTime(new Date()); // may update a cached object, but we consider a
- // reference update atomic
+ incrementalResult.setCurrentServerTime(new Date()); // may update a cached object, but we consider a reference update atomic
result = incrementalResult;
}
logger.fine("getLeaderboardByName(" + leaderboardName + ", " + date + ", "
@@ -790,7 +772,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
} catch (IllegalArgumentException e) {
throw e;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Exception during SailingService.getLeaderboardByName", e);
+ logger.log(Level.SEVERE,"Exception during SailingService.getLeaderboardByName", e);
throw new RuntimeException(e);
}
}
@@ -818,7 +800,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
private MarkDTO convertToMarkDTO(Mark mark, Position position) {
MarkDTO markDTO;
- if (position != null) {
+ if(position != null) {
markDTO = new MarkDTO(mark.getId().toString(), mark.getName(), position.getLatDeg(), position.getLngDeg());
} else {
markDTO = new MarkDTO(mark.getId().toString(), mark.getName());
@@ -838,8 +820,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
regattaDTO.endDate = regatta.getStartDate() != null ? regatta.getEndDate().asDate() : null;
BoatClass boatClass = regatta.getBoatClass();
if (boatClass != null) {
- regattaDTO.boatClass = new BoatClassDTO(boatClass.getName(), boatClass.getDisplayName(), boatClass
- .getHullLength().getMeters());
+ regattaDTO.boatClass = new BoatClassDTO(boatClass.getName(), boatClass.getDisplayName(), boatClass.getHullLength().getMeters());
}
if (regatta.getDefaultCourseArea() != null) {
regattaDTO.defaultCourseAreaUuid = regatta.getDefaultCourseArea().getId();
@@ -866,9 +847,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
List raceColumns = convertToRaceColumnDTOs(series.getRaceColumns());
SeriesDTO result = new SeriesDTO(series.getName(), fleets, raceColumns, series.isMedal(),
- series.getResultDiscardingRule() == null ? null : series.getResultDiscardingRule()
- .getDiscardIndexResultsStartingWithHowManyRaces(), series.isStartsWithZeroScore(),
- series.isFirstColumnIsNonDiscardableCarryForward(), series.hasSplitFleetContiguousScoring());
+ series.getResultDiscardingRule() == null ? null : series.getResultDiscardingRule().getDiscardIndexResultsStartingWithHowManyRaces(),
+ series.isStartsWithZeroScore(), series.isFirstColumnIsNonDiscardableCarryForward(), series.hasSplitFleetContiguousScoring());
return result;
}
@@ -877,41 +857,39 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
raceColumnDTO.setMedalRace(raceColumn.isMedalRace());
raceColumnDTO.setExplicitFactor(raceColumn.getExplicitFactor());
}
-
+
private List convertToRaceColumnDTOs(Iterable extends RaceColumn> raceColumns) {
List raceColumnDTOs = new ArrayList();
RaceColumnDTOFactory columnFactory = RaceColumnDTOFactory.INSTANCE;
for (RaceColumn raceColumn : raceColumns) {
-
- final RaceColumnDTO raceColumnDTO = columnFactory.createRaceColumnDTO(raceColumn.getName(), raceColumn
- .isMedalRace(), raceColumn.getExplicitFactor(),
- raceColumn instanceof RaceColumnInSeries ? ((RaceColumnInSeries) raceColumn).getRegatta().getName()
- : null, raceColumn instanceof RaceColumnInSeries ? ((RaceColumnInSeries) raceColumn)
- .getSeries().getName() : null);
+ final RaceColumnDTO raceColumnDTO = columnFactory.createRaceColumnDTO(raceColumn.getName(),
+ raceColumn.isMedalRace(), raceColumn.getExplicitFactor(),
+ raceColumn instanceof RaceColumnInSeries ? ((RaceColumnInSeries) raceColumn).getRegatta().getName() : null,
+ raceColumn instanceof RaceColumnInSeries ? ((RaceColumnInSeries) raceColumn).getSeries().getName() : null);
raceColumnDTOs.add(raceColumnDTO);
}
return raceColumnDTOs;
}
-
+
private RaceInfoDTO createRaceInfoDTO(String seriesName, RaceColumn raceColumn, Fleet fleet) {
RaceInfoDTO raceInfoDTO = new RaceInfoDTO();
RaceLog raceLog = raceColumn.getRaceLog(fleet);
if (raceLog != null) {
-
+
raceInfoDTO.isTracked = raceColumn.getTrackedRace(fleet) != null ? true : false;
ReadonlyRaceState state = ReadonlyRaceStateImpl.create(raceLog);
-
+
TimePoint startTime = state.getStartTime();
if (startTime != null) {
raceInfoDTO.startTime = startTime.asDate();
}
raceInfoDTO.lastStatus = state.getStatus();
-
+
if (raceLog.getLastRawFix() != null) {
raceInfoDTO.lastUpdateTime = raceLog.getLastRawFix().getCreatedAt().asDate();
}
-
+
TimePoint finishedTime = state.getFinishedTime();
if (finishedTime != null) {
raceInfoDTO.finishedTime = finishedTime.asDate();
@@ -924,11 +902,9 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
if (startTime != null) {
- FlagPoleState activeFlagState = state.getRacingProcedure().getActiveFlags(startTime,
- MillisecondsTimePoint.now());
+ FlagPoleState activeFlagState = state.getRacingProcedure().getActiveFlags(startTime, MillisecondsTimePoint.now());
List activeFlags = activeFlagState.getCurrentState();
- FlagPoleState previousFlagState = activeFlagState.getPreviousState(state.getRacingProcedure(),
- startTime);
+ FlagPoleState previousFlagState = activeFlagState.getPreviousState(state.getRacingProcedure(), startTime);
List previousFlags = previousFlagState.getCurrentState();
FlagPole mostInterestingFlagPole = FlagPoleState.getMostInterestingFlagPole(previousFlags, activeFlags);
@@ -937,18 +913,17 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
raceInfoDTO.lastUpperFlag = mostInterestingFlagPole.getUpperFlag();
raceInfoDTO.lastLowerFlag = mostInterestingFlagPole.getLowerFlag();
raceInfoDTO.lastFlagsAreDisplayed = mostInterestingFlagPole.isDisplayed();
- raceInfoDTO.lastFlagsDisplayedStateChanged = previousFlagState
- .hasPoleChanged(mostInterestingFlagPole);
+ raceInfoDTO.lastFlagsDisplayedStateChanged = previousFlagState.hasPoleChanged(mostInterestingFlagPole);
}
}
-
+
AbortingFlagFinder abortingFlagFinder = new AbortingFlagFinder(raceLog);
-
+
RaceLogFlagEvent abortingFlagEvent = abortingFlagFinder.analyze();
if (abortingFlagEvent != null) {
raceInfoDTO.isRaceAbortedInPassBefore = true;
raceInfoDTO.abortingTimeInPassBefore = abortingFlagEvent.getLogicalTimePoint().asDate();
-
+
if (raceInfoDTO.lastStatus.equals(RaceLogRaceStatus.UNSCHEDULED)) {
raceInfoDTO.lastUpperFlag = abortingFlagEvent.getUpperFlag();
raceInfoDTO.lastLowerFlag = abortingFlagEvent.getLowerFlag();
@@ -956,13 +931,13 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
raceInfoDTO.lastFlagsDisplayedStateChanged = true;
}
}
-
+
CourseBase lastCourse = state.getCourseDesign();
if (lastCourse != null) {
raceInfoDTO.lastCourseDesign = convertCourseDesignToRaceCourseDTO(lastCourse);
raceInfoDTO.lastCourseName = lastCourse.getName();
}
-
+
if (raceInfoDTO.lastStatus.equals(RaceLogRaceStatus.FINISHED)) {
TimePoint protestStartTime = state.getProtestTime();
if (protestStartTime != null) {
@@ -974,7 +949,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
raceInfoDTO.lastFlagsDisplayedStateChanged = true;
}
}
-
+
Wind wind = state.getWindFix();
if (wind != null) {
raceInfoDTO.lastWind = createWindDTOFromAlreadyAveraged(wind, MillisecondsTimePoint.now());
@@ -990,7 +965,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
raceInfoDTO.isTracked = raceColumn.getTrackedRace(fleet) != null ? true : false;
return raceInfoDTO;
}
-
+
private void fillStartProcedureSpecifics(RaceInfoDTO raceInfoDTO, ReadonlyRaceState state) {
RaceInfoExtensionDTO info = null;
raceInfoDTO.startProcedure = state.getRacingProcedure().getType();
@@ -1015,8 +990,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
List waypointDTOs = new ArrayList();
for (Waypoint waypoint : lastCourseDesign.getWaypoints()) {
ControlPointDTO controlPointDTO = convertToControlPointDTO(waypoint.getControlPoint());
- WaypointDTO waypointDTO = new WaypointDTO(waypoint.getName(), controlPointDTO,
- waypoint.getPassingInstructions());
+ WaypointDTO waypointDTO = new WaypointDTO(waypoint.getName(), controlPointDTO, waypoint.getPassingInstructions());
waypointDTOs.add(waypointDTO);
}
result = new RaceCourseDTO(waypointDTOs);
@@ -1029,18 +1003,16 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
for (RaceDefinition r : regatta.getAllRaces()) {
RegattaAndRaceIdentifier raceIdentifier = new RegattaNameAndRaceName(regatta.getName(), r.getName());
TrackedRace trackedRace = getService().getExistingTrackedRace(raceIdentifier);
- TrackedRaceDTO trackedRaceDTO = null;
+ TrackedRaceDTO trackedRaceDTO = null;
if (trackedRace != null) {
trackedRaceDTO = getBaseDomainFactory().createTrackedRaceDTO(trackedRace);
-
}
- RaceWithCompetitorsDTO raceDTO = new RaceWithCompetitorsDTO(raceIdentifier,
- convertToCompetitorDTOs(r.getCompetitors()), trackedRaceDTO, getService().isRaceBeingTracked(
- regatta, r));
+ RaceWithCompetitorsDTO raceDTO = new RaceWithCompetitorsDTO(raceIdentifier, convertToCompetitorDTOs(r.getCompetitors()),
+ trackedRaceDTO, getService().isRaceBeingTracked(regatta, r));
if (trackedRace != null) {
getBaseDomainFactory().updateRaceDTOWithTrackedRaceData(trackedRace, raceDTO);
}
- raceDTO.boatClass = regatta.getBoatClass() == null ? null : regatta.getBoatClass().getName();
+ raceDTO.boatClass = regatta.getBoatClass() == null ? null : regatta.getBoatClass().getName();
result.add(raceDTO);
}
return result;
@@ -1056,18 +1028,15 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
@Override
- public com.sap.sse.common.Util.Pair> listTracTracRacesInEvent(
- String eventJsonURL, boolean listHiddenRaces) throws MalformedURLException, IOException, ParseException,
- org.json.simple.parser.ParseException, URISyntaxException {
- com.sap.sse.common.Util.Pair> raceRecords;
- raceRecords = getTracTracAdapter().getTracTracRaceRecords(new URL(eventJsonURL), /* loadClientParam */false);
+ public com.sap.sse.common.Util.Pair> listTracTracRacesInEvent(String eventJsonURL, boolean listHiddenRaces) throws MalformedURLException, IOException, ParseException, org.json.simple.parser.ParseException, URISyntaxException {
+ com.sap.sse.common.Util.Pair> raceRecords;
+ raceRecords = getTracTracAdapter().getTracTracRaceRecords(new URL(eventJsonURL), /*loadClientParam*/ false);
List result = new ArrayList();
for (RaceRecord raceRecord : raceRecords.getB()) {
- if (listHiddenRaces == false
- && raceRecord.getRaceStatus().equals(TracTracConnectionConstants.HIDDEN_STATUS)) {
+ if (listHiddenRaces == false && raceRecord.getRaceStatus().equals(TracTracConnectionConstants.HIDDEN_STATUS)) {
continue;
}
-
+
result.add(new TracTracRaceRecordDTO(raceRecord.getID(), raceRecord.getEventName(), raceRecord.getName(),
raceRecord.getTrackingStartTime().asDate(),
raceRecord
@@ -1083,19 +1052,14 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
@Override
- public void trackWithTracTrac(RegattaIdentifier regattaToAddTo, Iterable rrs,
- String liveURI, String storedURI, String courseDesignUpdateURI, boolean trackWind,
- final boolean correctWindByDeclination, final boolean simulateWithStartTimeNow, String tracTracUsername,
- String tracTracPassword) throws Exception {
- logger.info("tracWithTracTrac for regatta " + regattaToAddTo + " for race records " + rrs + " with liveURI "
- + liveURI + " and storedURI " + storedURI);
+ public void trackWithTracTrac(RegattaIdentifier regattaToAddTo, Iterable rrs, String liveURI, String storedURI,
+ String courseDesignUpdateURI, boolean trackWind, final boolean correctWindByDeclination, final boolean simulateWithStartTimeNow,
+ String tracTracUsername, String tracTracPassword) throws Exception {
+ logger.info("tracWithTracTrac for regatta "+regattaToAddTo+" for race records "+rrs+" with liveURI "+liveURI+" and storedURI "+storedURI);
for (TracTracRaceRecordDTO rr : rrs) {
// reload JSON and load clientparams.php
- RaceRecord record = getTracTracAdapter().getSingleTracTracRaceRecord(new URL(rr.jsonURL), rr.id, /* loadClientParams */
- true);
- logger.info("Loaded race " + record.getName() + " in " + record.getEventName() + " start:"
- + record.getRaceStartTime() + " trackingStart:" + record.getTrackingStartTime() + " trackingEnd:"
- + record.getTrackingEndTime());
+ RaceRecord record = getTracTracAdapter().getSingleTracTracRaceRecord(new URL(rr.jsonURL), rr.id, /*loadClientParams*/true);
+ logger.info("Loaded race " + record.getName() + " in " + record.getEventName() + " start:" + record.getRaceStartTime() + " trackingStart:" + record.getTrackingStartTime() + " trackingEnd:" + record.getTrackingEndTime());
// note that the live URI may be null for races that were put into replay mode
final String effectiveLiveURI;
if (!record.getRaceStatus().equals(TracTracConnectionConstants.REPLAY_STATUS)) {
@@ -1146,19 +1110,17 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
Iterable configs = tractracDomainObjectFactory.getTracTracConfigurations();
List result = new ArrayList();
for (TracTracConfiguration ttConfig : configs) {
- result.add(new TracTracConfigurationDTO(ttConfig.getName(), ttConfig.getJSONURL().toString(), ttConfig
- .getLiveDataURI().toString(), ttConfig.getStoredDataURI().toString(), ttConfig
- .getCourseDesignUpdateURI().toString(), ttConfig.getTracTracUsername().toString(), ttConfig
- .getTracTracPassword().toString()));
+ result.add(new TracTracConfigurationDTO(ttConfig.getName(), ttConfig.getJSONURL().toString(),
+ ttConfig.getLiveDataURI().toString(), ttConfig.getStoredDataURI().toString(), ttConfig.getCourseDesignUpdateURI().toString(),
+ ttConfig.getTracTracUsername().toString(), ttConfig.getTracTracPassword().toString()));
}
return result;
}
@Override
- public void storeTracTracConfiguration(String name, String jsonURL, String liveDataURI, String storedDataURI,
- String courseDesignUpdateURI, String tracTracUsername, String tracTracPassword) throws Exception {
- tractracMongoObjectFactory.storeTracTracConfiguration(getTracTracAdapter().createTracTracConfiguration(name,
- jsonURL, liveDataURI, storedDataURI, courseDesignUpdateURI, tracTracUsername, tracTracPassword));
+ public void storeTracTracConfiguration(String name, String jsonURL, String liveDataURI, String storedDataURI, String courseDesignUpdateURI, String tracTracUsername, String tracTracPassword) throws Exception {
+ tractracMongoObjectFactory.storeTracTracConfiguration(getTracTracAdapter().createTracTracConfiguration(name, jsonURL, liveDataURI, storedDataURI,
+ courseDesignUpdateURI, tracTracUsername, tracTracPassword));
}
@Override
@@ -1189,13 +1151,11 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
/**
- * @param timeoutInMilliseconds
- * eventually passed to {@link RaceHandle#getRace(long)}. If the race definition can be obtained within
- * this timeout, wind for the race will be tracked; otherwise, the method returns without taking any
- * effect.
+ * @param timeoutInMilliseconds eventually passed to {@link RaceHandle#getRace(long)}. If the race definition
+ * can be obtained within this timeout, wind for the race will be tracked; otherwise, the method returns without
+ * taking any effect.
*/
- private void startTrackingWind(RaceHandle raceHandle, boolean correctByDeclination, long timeoutInMilliseconds)
- throws Exception {
+ private void startTrackingWind(RaceHandle raceHandle, boolean correctByDeclination, long timeoutInMilliseconds) throws Exception {
Regatta regatta = raceHandle.getRegatta();
if (regatta != null) {
RaceDefinition race = raceHandle.getRace(timeoutInMilliseconds);
@@ -1209,8 +1169,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
@Override
- public WindInfoForRaceDTO getRawWindFixes(RegattaAndRaceIdentifier raceIdentifier,
- Collection windSources) {
+ public WindInfoForRaceDTO getRawWindFixes(RegattaAndRaceIdentifier raceIdentifier, Collection windSources) {
WindInfoForRaceDTO result = null;
TrackedRace trackedRace = getExistingTrackedRace(raceIdentifier);
if (trackedRace != null) {
@@ -1227,7 +1186,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
windSourcesToDeliver.add(new WindSourceImpl(WindSourceType.WEB));
}
for (WindSource windSource : windSourcesToDeliver) {
- if (windSource.getType() == WindSourceType.WEB) {
+ if(windSource.getType() == WindSourceType.WEB) {
WindTrackInfoDTO windTrackInfoDTO = new WindTrackInfoDTO();
windTrackInfoDTO.windFixes = new ArrayList();
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
@@ -1237,7 +1196,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
Iterator windIter = windTrack.getRawFixes().iterator();
while (windIter.hasNext()) {
Wind wind = windIter.next();
- if (wind != null) {
+ if(wind != null) {
WindDTO windDTO = createWindDTO(wind, windTrack);
windTrackInfoDTO.windFixes.add(windDTO);
}
@@ -1260,11 +1219,13 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
windDTO.trueWindSpeedInKnots = wind.getKnots();
windDTO.trueWindSpeedInMetersPerSecond = wind.getMetersPerSecond();
if (wind.getPosition() != null) {
- windDTO.position = new PositionDTO(wind.getPosition().getLatDeg(), wind.getPosition().getLngDeg());
+ windDTO.position = new PositionDTO(wind.getPosition().getLatDeg(), wind.getPosition()
+ .getLngDeg());
}
if (wind.getTimePoint() != null) {
windDTO.measureTimepoint = wind.getTimePoint().asMillis();
- Wind estimatedWind = windTrack.getAveragedWind(wind.getPosition(), wind.getTimePoint());
+ Wind estimatedWind = windTrack
+ .getAveragedWind(wind.getPosition(), wind.getTimePoint());
if (estimatedWind != null) {
windDTO.dampenedTrueWindBearingDeg = estimatedWind.getBearing().getDegrees();
windDTO.dampenedTrueWindFromDeg = estimatedWind.getBearing().reverse().getDegrees();
@@ -1290,7 +1251,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
windDTO.dampenedTrueWindSpeedInKnots = wind.getKnots();
windDTO.dampenedTrueWindSpeedInMetersPerSecond = wind.getMetersPerSecond();
if (wind.getPosition() != null) {
- windDTO.position = new PositionDTO(wind.getPosition().getLatDeg(), wind.getPosition().getLngDeg());
+ windDTO.position = new PositionDTO(wind.getPosition().getLatDeg(), wind.getPosition()
+ .getLngDeg());
}
if (wind.getTimePoint() != null) {
windDTO.measureTimepoint = wind.getTimePoint().asMillis();
@@ -1299,8 +1261,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
/**
- * Fetches the {@link WindTrack#getAveragedWind(Position, TimePoint) average wind} from all wind tracks or those
- * identified by windSourceTypeNames
+ * Fetches the {@link WindTrack#getAveragedWind(Position, TimePoint) average wind} from all wind tracks or those identified
+ * by windSourceTypeNames
*/
@Override
public WindInfoForRaceDTO getAveragedWindInfo(RegattaAndRaceIdentifier raceIdentifier, Date from, long millisecondsStepWidth,
@@ -1335,11 +1297,9 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
Double minWindConfidence = 2.0;
Double maxWindConfidence = -1.0;
for (int i = 0; i < numberOfFixes; i++) {
- WindWithConfidence> averagedWindWithConfidence = windTrack
- .getAveragedWindWithConfidence(position, timePoint);
+ WindWithConfidence> averagedWindWithConfidence = windTrack.getAveragedWindWithConfidence(position, timePoint);
if (averagedWindWithConfidence != null) {
- WindDTO windDTO = createWindDTOFromAlreadyAveraged(averagedWindWithConfidence.getObject(),
- timePoint);
+ WindDTO windDTO = createWindDTOFromAlreadyAveraged(averagedWindWithConfidence.getObject(), timePoint);
double confidence = averagedWindWithConfidence.getConfidence();
windDTO.confidence = confidence;
windTrackInfoDTO.windFixes.add(windDTO);
@@ -1352,8 +1312,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
timePoint = new MillisecondsTimePoint(timePoint.asMillis() + millisecondsStepWidth);
}
- windTrackInfoDTO.minWindConfidence = minWindConfidence;
- windTrackInfoDTO.maxWindConfidence = maxWindConfidence;
+ windTrackInfoDTO.minWindConfidence = minWindConfidence;
+ windTrackInfoDTO.maxWindConfidence = maxWindConfidence;
}
}
}
@@ -1370,14 +1330,13 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
* trackedRace.getTimePointOfNewestEvent()}.
*/
@Override
- public WindInfoForRaceDTO getAveragedWindInfo(RegattaAndRaceIdentifier raceIdentifier, Date from,
- long millisecondsStepWidth, int numberOfFixes, Collection windSourceTypeNames,
- boolean onlyUpToNewestEvent, boolean includeCombinedWindForAllLegMiddles) throws NoWindException {
+ public WindInfoForRaceDTO getAveragedWindInfo(RegattaAndRaceIdentifier raceIdentifier, Date from, long millisecondsStepWidth,
+ int numberOfFixes, Collection windSourceTypeNames, boolean onlyUpToNewestEvent, boolean includeCombinedWindForAllLegMiddles)
+ throws NoWindException {
assert from != null;
TrackedRace trackedRace = getExistingTrackedRace(raceIdentifier);
- WindInfoForRaceDTO result = getAveragedWindInfo(new MillisecondsTimePoint(from), millisecondsStepWidth,
- numberOfFixes, windSourceTypeNames, trackedRace, /* onlyUpToNewestEvent */true,
- includeCombinedWindForAllLegMiddles);
+ WindInfoForRaceDTO result = getAveragedWindInfo(new MillisecondsTimePoint(from), millisecondsStepWidth, numberOfFixes,
+ windSourceTypeNames, trackedRace, /* onlyUpToNewestEvent */ true, includeCombinedWindForAllLegMiddles);
return result;
}
@@ -1428,12 +1387,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
for (final TrackedLeg trackedLeg : trackedRace.getTrackedLegs()) {
WindTrackInfoDTO windTrackInfoForLegMiddle = createWindTrackInfoDTO(from, millisecondsStepWidth,
numberOfFixes, trackedRace, onlyUpToNewestEvent, newestEvent, combinedWindSource,
- new PositionAtTimeProvider() {
- @Override
- public Position getPosition(TimePoint at) {
- return trackedLeg.getMiddleOfLeg(at);
- }
- });
+ new PositionAtTimeProvider() { @Override public Position getPosition(TimePoint at) { return trackedLeg.getMiddleOfLeg(at); }});
result.addWindOnLegMiddle(zeroBasedLegNumber, windTrackInfoForLegMiddle);
zeroBasedLegNumber++;
}
@@ -1445,7 +1399,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
private interface PositionAtTimeProvider {
Position getPosition(TimePoint at);
}
-
+
private WindTrackInfoDTO createWindTrackInfoDTO(TimePoint from, long millisecondsStepWidth, int numberOfFixes,
TrackedRace trackedRace, boolean onlyUpToNewestEvent, TimePoint newestEvent, WindSource windSource,
PositionAtTimeProvider positionProvider) {
@@ -1456,10 +1410,10 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
TimePoint timePoint = from;
Double minWindConfidence = 2.0;
Double maxWindConfidence = -1.0;
- for (int i = 0; i < numberOfFixes
- && (!onlyUpToNewestEvent || (newestEvent != null && timePoint.before(newestEvent))); i++) {
- WindWithConfidence> averagedWindWithConfidence = windTrack
- .getAveragedWindWithConfidence(positionProvider.getPosition(timePoint), timePoint);
+ for (int i = 0; i < numberOfFixes && (!onlyUpToNewestEvent ||
+ (newestEvent != null && timePoint.before(newestEvent))); i++) {
+ WindWithConfidence> averagedWindWithConfidence =
+ windTrack.getAveragedWindWithConfidence(positionProvider.getPosition(timePoint), timePoint);
if (averagedWindWithConfidence != null) {
if (logger.getLevel() != null && logger.getLevel().equals(Level.FINEST)) {
logger.finest("Found averaged wind: " + averagedWindWithConfidence);
@@ -1476,13 +1430,12 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
} else {
if (logger.getLevel() != null && logger.getLevel().equals(Level.FINEST)) {
- logger.finest("Did NOT find any averaged wind for timepoint " + timePoint + " and tracked race "
- + trackedRace.getRaceIdentifier().getRaceName());
+ logger.finest("Did NOT find any averaged wind for timepoint " + timePoint + " and tracked race " + trackedRace.getRaceIdentifier().getRaceName());
}
}
timePoint = new MillisecondsTimePoint(timePoint.asMillis() + millisecondsStepWidth);
}
- windTrackInfoDTO.minWindConfidence = minWindConfidence;
+ windTrackInfoDTO.minWindConfidence = minWindConfidence;
windTrackInfoDTO.maxWindConfidence = maxWindConfidence;
return windTrackInfoDTO;
}
@@ -1506,14 +1459,12 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
WindInfoForRaceDTO result = null;
if (trackedRace != null) {
TimePoint fromTimePoint = from == null ? trackedRace.getStartOfTracking() : new MillisecondsTimePoint(from);
- TimePoint toTimePoint = to == null ? trackedRace.getEndOfRace() == null ? MillisecondsTimePoint.now()
- .minus(trackedRace.getDelayToLiveInMillis()) : trackedRace.getEndOfRace()
- : new MillisecondsTimePoint(to);
+ TimePoint toTimePoint = to == null ? trackedRace.getEndOfRace() == null ?
+ MillisecondsTimePoint.now().minus(trackedRace.getDelayToLiveInMillis()) : trackedRace.getEndOfRace() : new MillisecondsTimePoint(to);
if (fromTimePoint != null && toTimePoint != null) {
- int numberOfFixes = (int) ((toTimePoint.asMillis() - fromTimePoint.asMillis()) / resolutionInMilliseconds);
+ int numberOfFixes = (int) ((toTimePoint.asMillis() - fromTimePoint.asMillis())/resolutionInMilliseconds);
result = getAveragedWindInfo(fromTimePoint, resolutionInMilliseconds, numberOfFixes,
- windSourceTypeNames, trackedRace, onlyUpToNewestEvent, /* includeCombinedWindForAllLegMiddles */
- false);
+ windSourceTypeNames, trackedRace, onlyUpToNewestEvent, /* includeCombinedWindForAllLegMiddles */ false);
}
}
return result;
@@ -1686,7 +1637,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
Wind wind = new WindImpl(p, at, speedWithBearing);
Iterable webWindSources = trackedRace.getWindSources(WindSourceType.WEB);
- if (Util.size(webWindSources) == 0) {
+ if(Util.size(webWindSources) == 0) {
// create a new WEB wind source if not available
trackedRace.recordWind(wind, new WindSourceImpl(WindSourceType.WEB));
} else {
@@ -1727,7 +1678,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
*/
private Map> getBoatPositions(RegattaAndRaceIdentifier raceIdentifier,
Map fromPerCompetitorIdAsString, Map toPerCompetitorIdAsString,
- boolean extrapolate) throws NoWindException {
+ boolean extrapolate)
+ throws NoWindException {
Map, LegType> legTypeCache = new HashMap<>();
Map> result = new HashMap>();
TrackedRace trackedRace = getExistingTrackedRace(raceIdentifier);
@@ -1738,10 +1690,8 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
List fixesForCompetitor = new ArrayList();
result.put(competitorDTO, fixesForCompetitor);
GPSFixTrack track = trackedRace.getTrack(competitor);
- TimePoint fromTimePoint = new MillisecondsTimePoint(fromPerCompetitorIdAsString.get(competitorDTO
- .getIdAsString()));
- TimePoint toTimePointExcluding = new MillisecondsTimePoint(
- toPerCompetitorIdAsString.get(competitorDTO.getIdAsString()));
+ TimePoint fromTimePoint = new MillisecondsTimePoint(fromPerCompetitorIdAsString.get(competitorDTO.getIdAsString()));
+ TimePoint toTimePointExcluding = new MillisecondsTimePoint(toPerCompetitorIdAsString.get(competitorDTO.getIdAsString()));
// copy the fixes into a list while holding the monitor; then release the monitor to avoid deadlocks
// during wind estimations required for tack determination
List fixes = new ArrayList();
@@ -1752,7 +1702,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
GPSFixMoving fix = fixIter.next();
if (fix.getTimePoint().before(toTimePointExcluding)) {
if (logger.isLoggable(Level.FINEST)) {
- logger.finest("" + competitor.getName() + ": " + fix);
+ logger.finest(""+competitor.getName()+": " + fix);
}
fixes.add(fix);
} else {
@@ -1763,16 +1713,14 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
track.unlockAfterRead();
}
if (fixes.isEmpty()) {
- // then there was no (smoothened) fix between fromTimePoint and toTimePointExcluding;
- // estimate...
- TimePoint middle = new MillisecondsTimePoint(
- (toTimePointExcluding.asMillis() + fromTimePoint.asMillis()) / 2);
+ // then there was no (smoothened) fix between fromTimePoint and toTimePointExcluding; estimate...
+ TimePoint middle = new MillisecondsTimePoint((toTimePointExcluding.asMillis()+fromTimePoint.asMillis())/2);
Position estimatedPosition = track.getEstimatedPosition(middle, extrapolate);
SpeedWithBearing estimatedSpeed = track.getEstimatedSpeed(middle);
if (estimatedPosition != null && estimatedSpeed != null) {
GPSFixMoving estimatedFix = new GPSFixMovingImpl(estimatedPosition, middle, estimatedSpeed);
if (logger.getLevel() != null && logger.getLevel().equals(Level.FINEST)) {
- logger.finest("" + competitor.getName() + ": " + estimatedFix + " (estimated)");
+ logger.finest(""+competitor.getName()+": " + estimatedFix+" (estimated)");
}
fixes.add(estimatedFix);
}
@@ -1780,13 +1728,11 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
Iterator fixIter = fixes.iterator();
if (fixIter.hasNext()) {
GPSFixMoving fix = fixIter.next();
- while (fix != null
- && (fix.getTimePoint().before(toTimePointExcluding) || (fix.getTimePoint().equals(
- toTimePointExcluding) && toTimePointExcluding.equals(fromTimePoint)))) {
+ while (fix != null && (fix.getTimePoint().before(toTimePointExcluding) ||
+ (fix.getTimePoint().equals(toTimePointExcluding) && toTimePointExcluding.equals(fromTimePoint)))) {
Wind wind = trackedRace.getWind(fix.getPosition(), fix.getTimePoint());
final SpeedWithBearing estimatedSpeed = track.getEstimatedSpeed(fix.getTimePoint());
- Tack tack = wind == null ? null : trackedRace.getTack(estimatedSpeed, wind,
- fix.getTimePoint());
+ Tack tack = wind == null? null : trackedRace.getTack(estimatedSpeed, wind, fix.getTimePoint());
TrackedLegOfCompetitor trackedLegOfCompetitor = trackedRace.getTrackedLeg(competitor,
fix.getTimePoint());
LegType legType;
@@ -1804,8 +1750,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
} else {
legType = null;
}
- WindDTO windDTO = wind == null ? null : createWindDTOFromAlreadyAveraged(wind,
- toTimePointExcluding);
+ WindDTO windDTO = wind == null ? null : createWindDTOFromAlreadyAveraged(wind, toTimePointExcluding);
GPSFixDTO fixDTO = createGPSFixDTO(fix, estimatedSpeed, windDTO, tack, legType, /* extrapolate */
false);
fixesForCompetitor.add(fixDTO);
@@ -1817,8 +1762,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
Position position = track.getEstimatedPosition(toTimePointExcluding, extrapolate);
Wind wind2 = trackedRace.getWind(position, toTimePointExcluding);
SpeedWithBearing estimatedSpeed2 = track.getEstimatedSpeed(toTimePointExcluding);
- Tack tack2 = wind2 == null ? null : trackedRace.getTack(estimatedSpeed2, wind2,
- toTimePointExcluding);
+ Tack tack2 = wind2 == null ? null : trackedRace.getTack(estimatedSpeed2, wind2, toTimePointExcluding);
LegType legType2;
if (trackedLegOfCompetitor != null && trackedLegOfCompetitor.getLeg() != null) {
TimePoint quantifiedTimePoint = quantifyTimePointWithResolution(
@@ -1829,19 +1773,19 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
legType2 = legTypeCache.get(cacheKey);
if (legType2 == null) {
legType2 = trackedRace.getTrackedLeg(trackedLegOfCompetitor.getLeg())
- .getLegType(fix.getTimePoint());
+ .getLegType(
+ fix.getTimePoint());
legTypeCache.put(cacheKey, legType2);
}
} else {
legType2 = null;
}
- WindDTO windDTO2 = wind2 == null ? null : createWindDTOFromAlreadyAveraged(wind2,
- toTimePointExcluding);
- GPSFixDTO extrapolated = new GPSFixDTO(toPerCompetitorIdAsString.get(competitorDTO
- .getIdAsString()), position == null ? null : new PositionDTO(
- position.getLatDeg(), position.getLngDeg()), estimatedSpeed2 == null ? null
- : createSpeedWithBearingDTO(estimatedSpeed2), windDTO2, tack2, legType2, /* extrapolated */
- true);
+ WindDTO windDTO2 = wind2 == null ? null : createWindDTOFromAlreadyAveraged(wind2, toTimePointExcluding);
+ GPSFixDTO extrapolated = new GPSFixDTO(
+ toPerCompetitorIdAsString.get(competitorDTO.getIdAsString()),
+ position==null?null:new PositionDTO(position.getLatDeg(), position.getLngDeg()),
+ estimatedSpeed2==null?null:createSpeedWithBearingDTO(estimatedSpeed2), windDTO2,
+ tack2, legType2, /* extrapolated */ true);
fixesForCompetitor.add(extrapolated);
}
fix = null;
@@ -1859,14 +1803,14 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
}
private SpeedWithBearingDTO createSpeedWithBearingDTO(SpeedWithBearing speedWithBearing) {
- return new SpeedWithBearingDTO(speedWithBearing.getKnots(), speedWithBearing.getBearing().getDegrees());
+ return new SpeedWithBearingDTO(speedWithBearing.getKnots(), speedWithBearing
+ .getBearing().getDegrees());
}
- private GPSFixDTO createGPSFixDTO(GPSFix fix, SpeedWithBearing speedWithBearing, WindDTO windDTO, Tack tack,
- LegType legType, boolean extrapolated) {
- return new GPSFixDTO(fix.getTimePoint().asDate(), fix.getPosition() == null ? null : new PositionDTO(fix
- .getPosition().getLatDeg(), fix.getPosition().getLngDeg()), speedWithBearing == null ? null
- : createSpeedWithBearingDTO(speedWithBearing), windDTO, tack, legType, extrapolated);
+ private GPSFixDTO createGPSFixDTO(GPSFix fix, SpeedWithBearing speedWithBearing, WindDTO windDTO, Tack tack, LegType legType, boolean extrapolated) {
+ return new GPSFixDTO(fix.getTimePoint().asDate(), fix.getPosition()==null?null:new PositionDTO(fix
+ .getPosition().getLatDeg(), fix.getPosition().getLngDeg()),
+ speedWithBearing==null?null:createSpeedWithBearingDTO(speedWithBearing), windDTO, tack, legType, extrapolated);
}
@Override
@@ -1881,19 +1825,14 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
List markPassingTimesDTOs = new ArrayList();
raceTimesInfo.setMarkPassingTimes(markPassingTimesDTOs);
- raceTimesInfo.startOfRace = trackedRace.getStartOfRace() == null ? null : trackedRace.getStartOfRace()
- .asDate();
- raceTimesInfo.startOfTracking = trackedRace.getStartOfTracking() == null ? null : trackedRace
- .getStartOfTracking().asDate();
- raceTimesInfo.newestTrackingEvent = trackedRace.getTimePointOfNewestEvent() == null ? null : trackedRace
- .getTimePointOfNewestEvent().asDate();
- raceTimesInfo.endOfTracking = trackedRace.getEndOfTracking() == null ? null : trackedRace
- .getEndOfTracking().asDate();
+ raceTimesInfo.startOfRace = trackedRace.getStartOfRace() == null ? null : trackedRace.getStartOfRace().asDate();
+ raceTimesInfo.startOfTracking = trackedRace.getStartOfTracking() == null ? null : trackedRace.getStartOfTracking().asDate();
+ raceTimesInfo.newestTrackingEvent = trackedRace.getTimePointOfNewestEvent() == null ? null : trackedRace.getTimePointOfNewestEvent().asDate();
+ raceTimesInfo.endOfTracking = trackedRace.getEndOfTracking() == null ? null : trackedRace.getEndOfTracking().asDate();
raceTimesInfo.endOfRace = trackedRace.getEndOfRace() == null ? null : trackedRace.getEndOfRace().asDate();
raceTimesInfo.delayToLiveInMs = trackedRace.getDelayToLiveInMillis();
- Iterable>> markPassingsTimes = trackedRace
- .getMarkPassingsTimes();
+ Iterable