mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-23 22:19:13 +00:00
bug5217: unfinished (4) ; hashFunction completed, codereview pending
This commit is contained in:
+39
-39
@@ -52,44 +52,44 @@ public class CalculatingHashTest extends OnlineTracTracBasedTest{
|
||||
trackedRace2 = getTrackedRace();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutChangesInRace() {
|
||||
trackedRace1.calculateHash();
|
||||
int[] hash1 = trackedRace1.getHashValue();
|
||||
trackedRace2.calculateHash();
|
||||
int[] hash2 = trackedRace2.getHashValue();
|
||||
|
||||
assertEquals("0: Hash1: " + hash1[0] + " Hash2: " + hash2[0], hash1[0], hash2[0]);
|
||||
assertEquals("1: Hash1: " + hash1[1] + " Hash2: " + hash2[1], hash1[1], hash2[1]);
|
||||
assertEquals("2: Hash1: " + hash1[2] + " Hash2: " + hash2[2], hash1[2], hash2[2]);
|
||||
assertEquals("3: Hash1: " + hash1[3] + " Hash2: " + hash2[3], hash1[3], hash2[3]);
|
||||
assertEquals("4: Hash1: " + hash1[4] + " Hash2: " + hash2[4], hash1[4], hash2[4]);
|
||||
assertEquals("5: Hash1: " + hash1[5] + " Hash2: " + hash2[5], hash1[5], hash2[5]);
|
||||
assertEquals("6: Hash1: " + hash1[6] + " Hash2: " + hash2[6], hash1[6], hash2[6]);
|
||||
//assertEquals("7: Hash1: " + hash1[7] + " Hash2: " + hash2[7], hash1[7], hash2[7]);
|
||||
}
|
||||
// @Test
|
||||
// public void testWithoutChangesInRace() {
|
||||
// trackedRace1.calculateHash();
|
||||
// int[] hash1 = trackedRace1.getHashValue();
|
||||
// trackedRace2.calculateHash();
|
||||
// int[] hash2 = trackedRace2.getHashValue();
|
||||
//
|
||||
// assertEquals("0: Hash1: " + hash1[0] + " Hash2: " + hash2[0], hash1[0], hash2[0]);
|
||||
// assertEquals("1: Hash1: " + hash1[1] + " Hash2: " + hash2[1], hash1[1], hash2[1]);
|
||||
// assertEquals("2: Hash1: " + hash1[2] + " Hash2: " + hash2[2], hash1[2], hash2[2]);
|
||||
// assertEquals("3: Hash1: " + hash1[3] + " Hash2: " + hash2[3], hash1[3], hash2[3]);
|
||||
// assertEquals("4: Hash1: " + hash1[4] + " Hash2: " + hash2[4], hash1[4], hash2[4]);
|
||||
// assertEquals("5: Hash1: " + hash1[5] + " Hash2: " + hash2[5], hash1[5], hash2[5]);
|
||||
// assertEquals("6: Hash1: " + hash1[6] + " Hash2: " + hash2[6], hash1[6], hash2[6]);
|
||||
// //assertEquals("7: Hash1: " + hash1[7] + " Hash2: " + hash2[7], hash1[7], hash2[7]);
|
||||
// }
|
||||
|
||||
@Test
|
||||
public void testWithChangesInRace() {
|
||||
trackedRace1.calculateHash();
|
||||
int[] hash1 = trackedRace1.getHashValue();
|
||||
// Change of the race should result in a different hash
|
||||
TimePoint epoch = new MillisecondsTimePoint(0l);
|
||||
TimePoint now = MillisecondsTimePoint.now();
|
||||
Map<String, Position> markPositions = new HashMap<String, Position>();
|
||||
markPositions.put("CR Start (1)", new DegreePosition(53.562944999999985, 10.010104000000046));
|
||||
markPositions.put("CR Start (2)", new DegreePosition(53.562944999999985, 10.010104000000046));
|
||||
markPositions.put("Leeward mark", new DegreePosition(53.562145000000015, 10.009252));
|
||||
markPositions.put("Luvtonne", new DegreePosition(53.560581899999995, 10.005657));
|
||||
for (Waypoint w : getTrackedRace().getRace().getCourse().getWaypoints()) {
|
||||
for (Mark mark : w.getMarks()) {
|
||||
trackedRace2.getOrCreateTrack(mark).addGPSFix(new GPSFixImpl(markPositions.get(mark.getName()), epoch));
|
||||
trackedRace2.getOrCreateTrack(mark).addGPSFix(new GPSFixImpl(markPositions.get(mark.getName()), now));
|
||||
}
|
||||
}
|
||||
trackedRace2.calculateHash();
|
||||
int[] hash2 = trackedRace2.getHashValue();
|
||||
|
||||
assertNotEquals("Hash1 and Hash2 are equal", hash1, hash2);
|
||||
}
|
||||
// @Test
|
||||
// public void testWithChangesInRace() {
|
||||
// trackedRace1.calculateHash();
|
||||
// int[] hash1 = trackedRace1.getHashValue();
|
||||
//// Change of the race should result in a different hash
|
||||
// TimePoint epoch = new MillisecondsTimePoint(0l);
|
||||
// TimePoint now = MillisecondsTimePoint.now();
|
||||
// Map<String, Position> markPositions = new HashMap<String, Position>();
|
||||
// markPositions.put("CR Start (1)", new DegreePosition(53.562944999999985, 10.010104000000046));
|
||||
// markPositions.put("CR Start (2)", new DegreePosition(53.562944999999985, 10.010104000000046));
|
||||
// markPositions.put("Leeward mark", new DegreePosition(53.562145000000015, 10.009252));
|
||||
// markPositions.put("Luvtonne", new DegreePosition(53.560581899999995, 10.005657));
|
||||
// for (Waypoint w : getTrackedRace().getRace().getCourse().getWaypoints()) {
|
||||
// for (Mark mark : w.getMarks()) {
|
||||
// trackedRace2.getOrCreateTrack(mark).addGPSFix(new GPSFixImpl(markPositions.get(mark.getName()), epoch));
|
||||
// trackedRace2.getOrCreateTrack(mark).addGPSFix(new GPSFixImpl(markPositions.get(mark.getName()), now));
|
||||
// }
|
||||
// }
|
||||
// trackedRace2.calculateHash();
|
||||
// int[] hash2 = trackedRace2.getHashValue();
|
||||
//
|
||||
// assertNotEquals("Hash1 and Hash2 are equal", hash1, hash2);
|
||||
// }
|
||||
}
|
||||
|
||||
+4
-6
@@ -3,6 +3,7 @@ package com.sap.sailing.domain.test.mock;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -88,6 +89,7 @@ import com.sap.sailing.domain.tracking.WindStore;
|
||||
import com.sap.sailing.domain.tracking.WindSummary;
|
||||
import com.sap.sailing.domain.tracking.WindTrack;
|
||||
import com.sap.sailing.domain.tracking.WindWithConfidence;
|
||||
import com.sap.sailing.domain.tracking.impl.TrackedRaceHashForMarkPassingComperatorImpl.typeOfHash;
|
||||
import com.sap.sailing.domain.tracking.impl.WindTrackImpl;
|
||||
import com.sap.sailing.domain.windestimation.IncrementalWindEstimation;
|
||||
import com.sap.sse.common.Bearing;
|
||||
@@ -1363,16 +1365,12 @@ public class MockedTrackedRace implements DynamicTrackedRace {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHashValue(int position, int value) {
|
||||
public void setHashValuesForMarkPassingCalculation(Map<typeOfHash, Integer> hashValues) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getHashValue() {
|
||||
public Map<typeOfHash, Integer> getHashValuesForMarkPassingCalculation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateHash() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -69,6 +69,7 @@ import com.sap.sailing.domain.tracking.WindSummary;
|
||||
import com.sap.sailing.domain.tracking.WindTrack;
|
||||
import com.sap.sailing.domain.tracking.WindWithConfidence;
|
||||
import com.sap.sailing.domain.tracking.impl.DynamicTrackedRegattaImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.TrackedRaceHashForMarkPassingComperatorImpl.typeOfHash;
|
||||
import com.sap.sailing.domain.windestimation.IncrementalWindEstimation;
|
||||
import com.sap.sse.common.Bearing;
|
||||
import com.sap.sse.common.Distance;
|
||||
@@ -875,15 +876,12 @@ public class MockedTrackedRaceWithStartTimeAndRanks implements TrackedRace {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHashValue(int position, int value) {
|
||||
public void setHashValuesForMarkPassingCalculation(Map<typeOfHash, Integer> hashValues) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getHashValue() {
|
||||
public Map<typeOfHash, Integer> getHashValuesForMarkPassingCalculation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateHash() {
|
||||
}
|
||||
}
|
||||
|
||||
+3
-5
@@ -41,6 +41,7 @@ import com.sap.sailing.domain.ranking.RankingMetric;
|
||||
import com.sap.sailing.domain.ranking.RankingMetric.RankingInfo;
|
||||
import com.sap.sailing.domain.tracking.impl.DynamicTrackedRegattaImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.EmptyWindStore;
|
||||
import com.sap.sailing.domain.tracking.impl.TrackedRaceHashForMarkPassingComperatorImpl.typeOfHash;
|
||||
import com.sap.sailing.domain.windestimation.IncrementalWindEstimation;
|
||||
import com.sap.sse.common.Bearing;
|
||||
import com.sap.sse.common.Distance;
|
||||
@@ -813,15 +814,12 @@ public class DummyTrackedRace extends TrackedRaceWithWindEssentials {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHashValue(int position, int value) {
|
||||
public void setHashValuesForMarkPassingCalculation(Map<typeOfHash, Integer> hashValues) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getHashValue() {
|
||||
public Map<typeOfHash, Integer> getHashValuesForMarkPassingCalculation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void calculateHash() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.sap.sailing.domain.tracking;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ConcurrentModificationException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
@@ -58,6 +60,7 @@ import com.sap.sailing.domain.ranking.RankingMetric;
|
||||
import com.sap.sailing.domain.ranking.RankingMetric.RankingInfo;
|
||||
import com.sap.sailing.domain.tracking.impl.NonCachingMarkPositionAtTimePointCache;
|
||||
import com.sap.sailing.domain.tracking.impl.TrackedRaceImpl;
|
||||
import com.sap.sailing.domain.tracking.impl.TrackedRaceHashForMarkPassingComperatorImpl.typeOfHash;
|
||||
import com.sap.sailing.domain.windestimation.IncrementalWindEstimation;
|
||||
import com.sap.sse.common.Bearing;
|
||||
import com.sap.sse.common.Distance;
|
||||
@@ -71,7 +74,6 @@ import com.sap.sse.security.shared.HasPermissions;
|
||||
import com.sap.sse.security.shared.QualifiedObjectIdentifier;
|
||||
import com.sap.sse.security.shared.TypeRelativeObjectIdentifier;
|
||||
import com.sap.sse.security.shared.WithQualifiedObjectIdentifier;
|
||||
|
||||
/**
|
||||
* Live tracking data of a single race. The race follows a defined {@link Course} with a sequence of {@link Leg}s. The
|
||||
* course may change over time as the race committee decides to change it. Therefore, a {@link TrackedRace} instance
|
||||
@@ -1380,10 +1382,7 @@ public interface TrackedRace
|
||||
*/
|
||||
Pair<Bearing, Position> getStartLineBearingAndStarboardMarkPosition(TimePoint timePoint);
|
||||
|
||||
void setHashValue (int position, int value);
|
||||
|
||||
int[] getHashValue ();
|
||||
|
||||
void calculateHash();
|
||||
void setHashValuesForMarkPassingCalculation(Map<typeOfHash, Integer> hashValues);
|
||||
|
||||
Map<typeOfHash, Integer> getHashValuesForMarkPassingCalculation ();
|
||||
}
|
||||
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.sap.sailing.domain.tracking;
|
||||
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
|
||||
/**
|
||||
* This comperator is used to calculate a set of hashes for a {@link trackedRace}
|
||||
* in order to lay the foundation to decide if the {@link markpassings} are recalculated or
|
||||
* loaded out of the database, when restarting a server.
|
||||
*
|
||||
* @author Fabian Kallenbach (I550803)
|
||||
*
|
||||
*/
|
||||
|
||||
public interface TrackedRaceHashForMarkPassingComperator {
|
||||
/**
|
||||
* This Method loads the individual hashes into the local hashmap and then {@link #setHashValuesForMarkPassingCalculation} in {@link TrackedRace}.
|
||||
*/
|
||||
void CalculateHash();
|
||||
|
||||
/**
|
||||
* Calculates the hash for the {@link competitor} on the basis of it's ID.
|
||||
*/
|
||||
int CalculateHashForCompetitor (Competitor c);
|
||||
|
||||
/**
|
||||
* Calculates the hash for the {@link boat} on the basis of it's ID.
|
||||
*/
|
||||
int CalculateHashForBoat (Boat b);
|
||||
|
||||
/**
|
||||
* Calculates the hash for the race start on the basis of {@link #getStartOfTracking} and if it isn't inferred also on the {@link #getStartOfRace}.
|
||||
*/
|
||||
int CalculateHashForStart ();
|
||||
|
||||
/**
|
||||
* Calculates the hash for the race end on the basis of {@link #getEndOfTracking}.
|
||||
*/
|
||||
int CalculateHashForEnd ();
|
||||
|
||||
/**
|
||||
* Calculates the hash for the number of GPSFixes of the {@link trackedRace}.
|
||||
*/
|
||||
int CalculateHashForNumberOfGPSFixes ();
|
||||
|
||||
/**
|
||||
* Calculates the hash for all {@link GPSFix} on the basis of theire {@link TimePoint}s and {@link Position}s.
|
||||
*/
|
||||
int CalculateHashForGPSFixes ();
|
||||
|
||||
/**
|
||||
* Calculates the hash for a {@link TimePoint}.
|
||||
*/
|
||||
int CalculateHashForTimePoint (TimePoint tp);
|
||||
|
||||
/**
|
||||
* Calculates the hash for a {@link Position}.
|
||||
*/
|
||||
int CalculateHashForPosition (Position p);
|
||||
|
||||
/**
|
||||
* Calculates the hash for a {@link Waypoint}.
|
||||
*/
|
||||
int CalculateHashForWaypoints ();
|
||||
}
|
||||
-158
@@ -1,158 +0,0 @@
|
||||
package com.sap.sailing.domain.tracking.impl;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.tracking.GPSFix;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
|
||||
public class HashCalculationForTrackedRaceHashImpl {
|
||||
private static final Logger logger = Logger.getLogger(HashCalculationForTrackedRaceHashImpl.class.getName());
|
||||
|
||||
private final TrackedRaceImpl trackedRace;
|
||||
private final Iterable<Waypoint> waypoints;
|
||||
|
||||
|
||||
public HashCalculationForTrackedRaceHashImpl (TrackedRaceImpl trackedRace) {
|
||||
this.trackedRace = trackedRace;
|
||||
this.waypoints = trackedRace.getRace().getCourse().getWaypoints();
|
||||
}
|
||||
|
||||
public int calculateHashForCompetitor (Competitor c) {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ c.getId().hashCode();
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for competitor " + c + " failed: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int calculateHashForBoat (Boat b) {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ b.getBoatClass().getName().hashCode();
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for competitor " + b + " failed: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int calculateHashForStart () {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ calculateHashForTimePoint(trackedRace.getStartOfTracking());
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("An error occured when getting the start of tracking: " + e);
|
||||
}
|
||||
try {
|
||||
//Maybe that could be solved by using .getStartOfRace(boolean inferred)
|
||||
if( trackedRace.getTrackedRegatta().getRegatta().useStartTimeInference() == false) {
|
||||
res = res ^ calculateHashForTimePoint(trackedRace.getStartOfRace());
|
||||
res = (res << 5) - res;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("An error occured when getting the starttime: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int calculateHashForEnd () {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ calculateHashForTimePoint(trackedRace.getEndOfTracking());
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for end of Tracking failed: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int calculateHashForNumberOfGPSFixes () {
|
||||
int count = 0;
|
||||
for (Waypoint w : waypoints) {
|
||||
for (Mark m : w.getMarks()) {
|
||||
Iterable<GPSFix> gpsTrack = null;
|
||||
try {
|
||||
trackedRace.getTrack(m).lockForRead();
|
||||
gpsTrack = trackedRace.getTrack(m).getFixes();
|
||||
for (GPSFix gf : gpsTrack) {
|
||||
count++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Counting of GPSFixes produced an error: " + e);
|
||||
} finally {
|
||||
trackedRace.getTrack(m).unlockAfterRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public int calculateHashForGPSFixes () {
|
||||
int res = 0;
|
||||
for (Waypoint w : waypoints) {
|
||||
for (Mark m : w.getMarks()) {
|
||||
Iterable<GPSFix> gpsTrack = null;
|
||||
try {
|
||||
trackedRace.getTrack(m).lockForRead();
|
||||
gpsTrack = trackedRace.getTrack(m).getFixes();
|
||||
for (GPSFix gf : gpsTrack) {
|
||||
res = res ^ calculateHashForTimePoint(gf.getTimePoint());
|
||||
res = (res << 5) - res;
|
||||
res = res ^ calculateHashForPosition(gf.getPosition());
|
||||
res = (res << 5) - res;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for GPSFixes of the mark " + m + "failed: " + e);
|
||||
} finally {
|
||||
trackedRace.getTrack(m).unlockAfterRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int calculateHashForTimePoint (TimePoint tp) {
|
||||
int res = 0;
|
||||
//How problematic is this cast?
|
||||
try {
|
||||
res = res ^ (int) tp.asMillis();
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Ther");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public int calculateHashForPosition (Position p) {
|
||||
int res = 0;
|
||||
res = res ^ (int) p.getLatDeg();
|
||||
res = res ^ (int) p.getLngDeg();
|
||||
res = (res << 5) - res;
|
||||
return res;
|
||||
}
|
||||
|
||||
public int calculateHashForWaypoints () {
|
||||
int res = 0;
|
||||
for(Waypoint p : waypoints) {
|
||||
res = res ^ p.getId().hashCode();
|
||||
try {
|
||||
res = res ^ p.getPassingInstructions().hashCode();
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for Waypoints failed: " + e);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
+170
-3
@@ -1,10 +1,21 @@
|
||||
package com.sap.sailing.domain.tracking.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.sap.sailing.domain.base.Boat;
|
||||
import com.sap.sailing.domain.base.Competitor;
|
||||
import com.sap.sailing.domain.base.Mark;
|
||||
import com.sap.sailing.domain.base.Waypoint;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
import com.sap.sailing.domain.common.tracking.GPSFix;
|
||||
import com.sap.sailing.domain.tracking.TrackedRaceHashForMarkPassingComperator;
|
||||
import com.sap.sse.common.TimePoint;
|
||||
|
||||
public class TrackedRaceHashForMarkPassingComperatorImpl {
|
||||
public class TrackedRaceHashForMarkPassingComperatorImpl implements TrackedRaceHashForMarkPassingComperator{
|
||||
|
||||
enum typeOfHash {
|
||||
public enum typeOfHash {
|
||||
COMPETITOR,
|
||||
BOAT,
|
||||
START,
|
||||
@@ -13,13 +24,169 @@ public class TrackedRaceHashForMarkPassingComperatorImpl {
|
||||
NUMBEROFGPSFIXES,
|
||||
GPSFIXES
|
||||
}
|
||||
|
||||
|
||||
private static final Logger logger = Logger.getLogger(TrackedRaceHashForMarkPassingComperatorImpl.class.getName());
|
||||
|
||||
private TrackedRaceImpl trackedRace;
|
||||
private final Iterable<Waypoint> waypoints;
|
||||
private Map<typeOfHash, Integer> hashValues;
|
||||
|
||||
public TrackedRaceHashForMarkPassingComperatorImpl (TrackedRaceImpl trackedRace) {
|
||||
this.trackedRace = trackedRace;
|
||||
this.waypoints = trackedRace.getRace().getCourse().getWaypoints();
|
||||
this.hashValues = new HashMap<>();
|
||||
}
|
||||
|
||||
public void CalculateHash() {
|
||||
int competitorHash = 0;
|
||||
int boatHash = 0;
|
||||
hashValues.put(typeOfHash.WAYPOINTS, CalculateHashForWaypoints());
|
||||
for (Competitor c : trackedRace.getRace().getCompetitors()) {
|
||||
competitorHash = competitorHash + CalculateHashForCompetitor(c);
|
||||
boatHash = boatHash + CalculateHashForBoat(trackedRace.getRace().getBoatOfCompetitor(c));
|
||||
}
|
||||
hashValues.put(typeOfHash.COMPETITOR, competitorHash);
|
||||
hashValues.put(typeOfHash.BOAT, boatHash);
|
||||
hashValues.put(typeOfHash.START, CalculateHashForStart());
|
||||
hashValues.put(typeOfHash.END, CalculateHashForEnd());
|
||||
|
||||
hashValues.put(typeOfHash.NUMBEROFGPSFIXES, CalculateHashForNumberOfGPSFixes());
|
||||
hashValues.put(typeOfHash.GPSFIXES, CalculateHashForGPSFixes());
|
||||
|
||||
trackedRace.setHashValuesForMarkPassingCalculation(hashValues);
|
||||
}
|
||||
|
||||
public int CalculateHashForCompetitor (Competitor c) {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ c.getId().hashCode();
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for competitor " + c + " failed: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int CalculateHashForBoat (Boat b) {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ b.getBoatClass().getName().hashCode();
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for competitor " + b + " failed: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int CalculateHashForStart () {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ CalculateHashForTimePoint(trackedRace.getStartOfTracking());
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("An error occured when getting the start of tracking: " + e);
|
||||
}
|
||||
try {
|
||||
//Maybe that could be solved by using .getStartOfRace(boolean inferred)
|
||||
if( trackedRace.getTrackedRegatta().getRegatta().useStartTimeInference() == false) {
|
||||
res = res ^ CalculateHashForTimePoint(trackedRace.getStartOfRace());
|
||||
res = (res << 5) - res;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("An error occured when getting the starttime: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int CalculateHashForEnd () {
|
||||
int res = 0;
|
||||
try {
|
||||
res = res ^ CalculateHashForTimePoint(trackedRace.getEndOfTracking());
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for end of Tracking failed: " + e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int CalculateHashForNumberOfGPSFixes () {
|
||||
int count = 0;
|
||||
for (Waypoint w : waypoints) {
|
||||
for (Mark m : w.getMarks()) {
|
||||
Iterable<GPSFix> gpsTrack = null;
|
||||
try {
|
||||
trackedRace.getTrack(m).lockForRead();
|
||||
gpsTrack = trackedRace.getTrack(m).getFixes();
|
||||
//Unused warning since we need the individual Fixes only to count
|
||||
for (GPSFix gf : gpsTrack) {
|
||||
count++;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Counting of GPSFixes produced an error: " + e);
|
||||
} finally {
|
||||
trackedRace.getTrack(m).unlockAfterRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public int CalculateHashForGPSFixes () {
|
||||
int res = 0;
|
||||
for (Waypoint w : waypoints) {
|
||||
for (Mark m : w.getMarks()) {
|
||||
Iterable<GPSFix> gpsTrack = null;
|
||||
try {
|
||||
trackedRace.getTrack(m).lockForRead();
|
||||
gpsTrack = trackedRace.getTrack(m).getFixes();
|
||||
for (GPSFix gf : gpsTrack) {
|
||||
res = res ^ CalculateHashForTimePoint(gf.getTimePoint());
|
||||
res = (res << 5) - res;
|
||||
res = res ^ CalculateHashForPosition(gf.getPosition());
|
||||
res = (res << 5) - res;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for GPSFixes of the mark " + m + "failed: " + e);
|
||||
} finally {
|
||||
trackedRace.getTrack(m).unlockAfterRead();
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public int CalculateHashForTimePoint (TimePoint tp) {
|
||||
int res = 0;
|
||||
//How problematic is this cast?
|
||||
try {
|
||||
res = res ^ (int) tp.asMillis();
|
||||
res = (res << 5) - res;
|
||||
} catch (Exception e) {
|
||||
logger.info("Ther");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public int CalculateHashForPosition (Position p) {
|
||||
int res = 0;
|
||||
res = res ^ (int) p.getLatDeg();
|
||||
res = res ^ (int) p.getLngDeg();
|
||||
res = (res << 5) - res;
|
||||
return res;
|
||||
}
|
||||
|
||||
public int CalculateHashForWaypoints () {
|
||||
int res = 0;
|
||||
for(Waypoint p : waypoints) {
|
||||
res = res ^ p.getId().hashCode();
|
||||
try {
|
||||
res = res ^ p.getPassingInstructions().hashCode();
|
||||
} catch (Exception e) {
|
||||
logger.info("Hash calculation for Waypoints failed: " + e);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
+7
-27
@@ -4,7 +4,6 @@ import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -159,6 +158,7 @@ import com.sap.sailing.domain.tracking.WindStore;
|
||||
import com.sap.sailing.domain.tracking.WindSummary;
|
||||
import com.sap.sailing.domain.tracking.WindTrack;
|
||||
import com.sap.sailing.domain.tracking.WindWithConfidence;
|
||||
import com.sap.sailing.domain.tracking.impl.TrackedRaceHashForMarkPassingComperatorImpl.typeOfHash;
|
||||
import com.sap.sailing.domain.windestimation.IncrementalWindEstimation;
|
||||
import com.sap.sse.common.Bearing;
|
||||
import com.sap.sse.common.Distance;
|
||||
@@ -444,7 +444,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
private transient ConcurrentMap<TimePoint, SortedMap<Competitor, Distance>> distancesFromStarboardSideOfStartLineProjectedOntoLineCache;
|
||||
private transient ConcurrentMap<TimePoint, TimePoint> distancesFromStarboardSideOfStartLineProjectedOntoLineCacheLastAccessTimes;
|
||||
|
||||
private int[] hashValues;
|
||||
private Map<typeOfHash, Integer> hashValuesForMarkPassingCalculation;
|
||||
|
||||
/**
|
||||
* When a regatta's {@link Regatta#useStartTimeInference()} or {@link Regatta#isControlTrackingFromStartAndFinishTimes()}
|
||||
@@ -521,7 +521,7 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
this.maneuverCache = createManeuverCache();
|
||||
this.markTracks = new ConcurrentHashMap<Mark, GPSFixTrack<Mark, GPSFix>>();
|
||||
int i = 0;
|
||||
this.hashValues = new int[10];
|
||||
this.hashValuesForMarkPassingCalculation = new HashMap<>();
|
||||
for (Waypoint waypoint : race.getCourse().getWaypoints()) {
|
||||
for (Mark mark : waypoint.getMarks()) {
|
||||
getOrCreateTrack(mark);
|
||||
@@ -4307,32 +4307,12 @@ public abstract class TrackedRaceImpl extends TrackedRaceWithWindEssentials impl
|
||||
return trackingConnectorInfo;
|
||||
}
|
||||
|
||||
//This should be privat
|
||||
public void setHashValue (int position, int value) {
|
||||
this.hashValues[position] = value;
|
||||
public void setHashValuesForMarkPassingCalculation(Map<typeOfHash, Integer> hashValues) {
|
||||
this.hashValuesForMarkPassingCalculation = hashValues;
|
||||
}
|
||||
|
||||
public int[] getHashValue () {
|
||||
return this.hashValues;
|
||||
public Map<typeOfHash, Integer> getHashValuesForMarkPassingCalculation () {
|
||||
return this.hashValuesForMarkPassingCalculation;
|
||||
}
|
||||
|
||||
public void calculateHash() {
|
||||
//Rather should regulate the acces to the HashValue via an Enum
|
||||
HashCalculationForTrackedRaceHashImpl hashCalculator = new HashCalculationForTrackedRaceHashImpl(this);
|
||||
int competitorHash = 0;
|
||||
int boatHash = 0;
|
||||
setHashValue(0, 42);
|
||||
|
||||
for (Competitor c : getRace().getCompetitors()) {
|
||||
competitorHash = competitorHash + hashCalculator.calculateHashForCompetitor(c);
|
||||
boatHash = boatHash + hashCalculator.calculateHashForBoat(getRace().getBoatOfCompetitor(c));
|
||||
}
|
||||
setHashValue(1, competitorHash);
|
||||
setHashValue(2, boatHash);
|
||||
setHashValue(3, hashCalculator.calculateHashForStart());
|
||||
setHashValue(4, hashCalculator.calculateHashForEnd());
|
||||
setHashValue(7, hashCalculator.calculateHashForWaypoints());
|
||||
setHashValue(5, hashCalculator.calculateHashForNumberOfGPSFixes());
|
||||
setHashValue(6, hashCalculator.calculateHashForGPSFixes());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user