mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-02 18:33:54 +00:00
fixed other calls to getOrCreateWindTrack by introducing a variant that doesn't require a delay argument
This commit is contained in:
1 parent
d53c576b42
commit
5c29b9c771
7 files changed
+31
-18
No files matched your search
+1
-1
@@ -74,7 +74,7 @@ public class MongoObjectFactoryImpl implements MongoObjectFactory {
|
||||
|
||||
@Override
|
||||
public void addWindTrackDumper(TrackedEvent trackedEvent, TrackedRace trackedRace, WindSource windSource) {
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
|
||||
windTrack.addListener(new MongoWindListener(trackedEvent, trackedRace, windSource, this, database));
|
||||
}
|
||||
|
||||
|
||||
@@ -209,6 +209,11 @@ public interface TrackedRace extends Serializable {
|
||||
*/
|
||||
Iterable<WindSource> getWindSources();
|
||||
|
||||
/**
|
||||
* Same as {@link #getOrCreateWindTrack(WindSource, long) getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind())}.
|
||||
*/
|
||||
WindTrack getOrCreateWindTrack(WindSource windSource);
|
||||
|
||||
WindTrack getOrCreateWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation);
|
||||
|
||||
/**
|
||||
|
||||
+5
-6
@@ -77,7 +77,7 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
private void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException {
|
||||
ois.defaultReadObject();
|
||||
for (WindSource windSource : getWindSources()) {
|
||||
getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2).addListener(this);
|
||||
getOrCreateWindTrack(windSource).addListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,8 +118,7 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
public void setMillisecondsOverWhichToAverageWind(long millisecondsOverWhichToAverageWind) {
|
||||
this.millisecondsOverWhichToAverageWind = millisecondsOverWhichToAverageWind;
|
||||
for (WindSource windSource : getWindSources()) {
|
||||
getOrCreateWindTrack(windSource, millisecondsOverWhichToAverageWind/2).
|
||||
setMillisecondsOverWhichToAverage(millisecondsOverWhichToAverageWind);
|
||||
getOrCreateWindTrack(windSource).setMillisecondsOverWhichToAverage(millisecondsOverWhichToAverageWind);
|
||||
}
|
||||
updated(MillisecondsTimePoint.now());
|
||||
}
|
||||
@@ -379,13 +378,13 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
|
||||
@Override
|
||||
public synchronized void recordWind(Wind wind, WindSource windSource) {
|
||||
getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2).add(wind);
|
||||
getOrCreateWindTrack(windSource).add(wind);
|
||||
updated(null); // wind events shouldn't advance race time
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void removeWind(Wind wind, WindSource windSource) {
|
||||
getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2).remove(wind);
|
||||
getOrCreateWindTrack(windSource).remove(wind);
|
||||
updated(wind.getTimePoint());
|
||||
}
|
||||
|
||||
@@ -436,7 +435,7 @@ public class DynamicTrackedRaceImpl extends TrackedRaceImpl implements
|
||||
public long getMillisecondsOverWhichToAverageWind() {
|
||||
long result = 0; // default in case there is no competitor
|
||||
for (WindSource windSource : getWindSources()) {
|
||||
WindTrack someTrack = getOrCreateWindTrack(windSource, 0);
|
||||
WindTrack someTrack = getOrCreateWindTrack(windSource);
|
||||
result = someTrack.getMillisecondsOverWhichToAverageWind();
|
||||
}
|
||||
return result;
|
||||
|
||||
+11
-2
@@ -754,6 +754,9 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
* {@link #windTracks} for the respective source. If found, it's returned; otherwise the wind track is created
|
||||
* through the {@link #windStore} using {@link #createWindTrack(WindSource, long)} and added to {@link #windTracks} before
|
||||
* being returned.
|
||||
*
|
||||
* @param delayForWindEstimationCacheInvalidation if <code>-1</code> and the parameter is accessed, it will be
|
||||
* replaced by {@link #getMillisecondsOverWhichToAverageWind()}/2
|
||||
*/
|
||||
@Override
|
||||
public WindTrack getOrCreateWindTrack(WindSource windSource, long delayForWindEstimationCacheInvalidation) {
|
||||
@@ -764,7 +767,8 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
synchronized (windTracks) {
|
||||
result = windTracks.get(windSource);
|
||||
if (result == null) {
|
||||
result = createWindTrack(windSource, delayForWindEstimationCacheInvalidation);
|
||||
result = createWindTrack(windSource, delayForWindEstimationCacheInvalidation == -1 ?
|
||||
getMillisecondsOverWhichToAverageWind()/2 : delayForWindEstimationCacheInvalidation);
|
||||
windTracks.put(windSource, result);
|
||||
}
|
||||
}
|
||||
@@ -772,6 +776,11 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WindTrack getOrCreateWindTrack(WindSource windSource) {
|
||||
return getOrCreateWindTrack(windSource, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a wind track for the <code>windSource</code> specified and stores it in {@link #windTracks}. The
|
||||
* averaging interval is set according to the averaging interval set for all other wind sources, or the default if
|
||||
@@ -824,7 +833,7 @@ public abstract class TrackedRaceImpl implements TrackedRace, CourseListener {
|
||||
for (WindSource windSource : getWindSources()) {
|
||||
// TODO consider parallelizing
|
||||
if (!Util.contains(windSourcesToExclude, windSource)) {
|
||||
WindTrack track = getOrCreateWindTrack(windSource, getMillisecondsOverWhichToAverageWind()/2);
|
||||
WindTrack track = getOrCreateWindTrack(windSource);
|
||||
WindWithConfidence<Pair<Position, TimePoint>> windWithConfidence = track.getAveragedWindWithConfidence(
|
||||
p, at);
|
||||
if (windWithConfidence != null) {
|
||||
|
||||
+6
-6
@@ -610,7 +610,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
for (WindSource windSource : windSourcesToDeliver) {
|
||||
WindTrackInfoDTO windTrackInfoDTO = new WindTrackInfoDTO();
|
||||
windTrackInfoDTO.windFixes = new ArrayList<WindDTO>();
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
|
||||
windTrackInfoDTO.dampeningIntervalInMilliseconds = windTrack.getMillisecondsOverWhichToAverageWind();
|
||||
Iterator<Wind> windIter = windTrack.getFixesIterator(from, /* inclusive */true);
|
||||
while (windIter.hasNext()) {
|
||||
@@ -705,7 +705,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
TimePoint fromTimePoint = new MillisecondsTimePoint(from);
|
||||
WindTrackInfoDTO windTrackInfoDTO = new WindTrackInfoDTO();
|
||||
windTrackInfoDTO.windFixes = new ArrayList<WindDTO>();
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
|
||||
windTrackInfoDTOs.put(windSource, windTrackInfoDTO);
|
||||
windTrackInfoDTO.dampeningIntervalInMilliseconds = windTrack
|
||||
.getMillisecondsOverWhichToAverageWind();
|
||||
@@ -757,7 +757,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
if (windSourceTypeNames == null || windSourceTypeNames.contains(windSource.getType().name())) {
|
||||
WindTrackInfoDTO windTrackInfoDTO = new WindTrackInfoDTO();
|
||||
windTrackInfoDTO.windFixes = new ArrayList<WindDTO>();
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
|
||||
windTrackInfoDTOs.put(windSource, windTrackInfoDTO);
|
||||
windTrackInfoDTO.dampeningIntervalInMilliseconds = windTrack
|
||||
.getMillisecondsOverWhichToAverageWind();
|
||||
@@ -895,7 +895,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
trackedLegOfCompetitor.getLeg()).getLegType(fix.getTimePoint());
|
||||
GPSFixDTO fixDTO = createGPSFixDTO(fix, fix.getSpeed(), createWindDTOFromAlreadyAveraged(trackedRace.getWind(fix.getPosition(),
|
||||
toTimePointExcluding), trackedRace
|
||||
.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation)), tack, legType, /* extrapolate */
|
||||
.getOrCreateWindTrack(windSource)), tack, legType, /* extrapolate */
|
||||
false);
|
||||
fixesForCompetitor.add(fixDTO);
|
||||
if (fixIter.hasNext()) {
|
||||
@@ -915,7 +915,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
createSpeedWithBearingDTO(speedWithBearing),
|
||||
createWindDTOFromAlreadyAveraged(trackedRace.getWind(position,
|
||||
toTimePointExcluding), trackedRace
|
||||
.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation)), /* extrapolated */
|
||||
.getOrCreateWindTrack(windSource)), /* extrapolated */
|
||||
tack2, legType2, true);
|
||||
fixesForCompetitor.add(extrapolated);
|
||||
}
|
||||
@@ -1588,7 +1588,7 @@ public class SailingServiceImpl extends RemoteServiceServlet implements SailingS
|
||||
trackedLegOfCompetitor.getLeg()).getLegType(fix.getTimePoint());
|
||||
GPSFixDTO fixDTO = createGPSFixDTO(fix, speedWithBearing, createWindDTOFromAlreadyAveraged(trackedRace.getWind(
|
||||
fix.getPosition(), fix.getTimePoint()),
|
||||
trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation)), tack, legType, /* extrapolated */false);
|
||||
trackedRace.getOrCreateWindTrack(windSource)), tack, legType, /* extrapolated */false);
|
||||
gpsFixDouglasList.add(fixDTO);
|
||||
}
|
||||
result.put(competitorDTO, gpsFixDouglasList);
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ public class TestStoringAndRetrievingWindTracksTest extends AbstractTracTracLive
|
||||
Mongo myFirstMongo = newMongo();
|
||||
DB firstDatabase = myFirstMongo.getDB(dbConfiguration.getDatabaseName());
|
||||
new MongoObjectFactoryImpl(firstDatabase).addWindTrackDumper(trackedEvent, trackedRace, windSource);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
|
||||
Position pos = new DegreePosition(54, 9);
|
||||
TimePoint timePoint = MillisecondsTimePoint.now();
|
||||
for (double bearingDeg = 123.4; bearingDeg<140; bearingDeg += 1.1) {
|
||||
|
||||
@@ -262,7 +262,7 @@ public class AdminApp extends Servlet {
|
||||
JSONObject jsonWindTracks = new JSONObject();
|
||||
for (WindSource windSource : trackedRace.getWindSources()) {
|
||||
JSONArray jsonWindArray = new JSONArray();
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource, delayForWindEstimationCacheInvalidation);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(windSource);
|
||||
synchronized (windTrack) {
|
||||
Iterator<Wind> windIter = windTrack.getFixesIterator(from, /* inclusive */true);
|
||||
while (windIter.hasNext()) {
|
||||
@@ -370,7 +370,7 @@ public class AdminApp extends Servlet {
|
||||
try {
|
||||
final DynamicTrackedRace trackedRace = getService().getOrCreateTrackedEvent(event)
|
||||
.getTrackedRace(race);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(trackedRace.getWindSources(windSourceType).iterator().next(), delayForWindEstimationCacheInvalidation);
|
||||
WindTrack windTrack = trackedRace.getOrCreateWindTrack(trackedRace.getWindSources(windSourceType).iterator().next());
|
||||
TimePoint timePoint = getTimePoint(req, PARAM_NAME_TIME, PARAM_NAME_TIME_MILLIS,
|
||||
MillisecondsTimePoint.now());
|
||||
Wind wind = windTrack.getLastFixAtOrBefore(timePoint);
|
||||
|
||||
Reference in new issue
Block a user