mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-25 05:23:51 +00:00
consolidated code that produces a RaceCourseDTO
This commit is contained in:
1 parent
591146d667
commit
14105f8bf9
2 files changed
+34
-24
No files matched your search
+33
-23
@@ -902,7 +902,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
|
||||
CourseBase lastCourse = state.getCourseDesign();
|
||||
if (lastCourse != null) {
|
||||
raceInfoDTO.lastCourseDesign = convertToRaceCourseDTO(lastCourse);
|
||||
raceInfoDTO.lastCourseDesign = convertToRaceCourseDTO(lastCourse, /* trackedRace */ null, /* timePoint */ null);
|
||||
raceInfoDTO.lastCourseName = lastCourse.getName();
|
||||
}
|
||||
|
||||
@@ -1850,7 +1850,9 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
result.totalLegsCount = trackedRace.getRace().getCourse().getLegs().size();
|
||||
result.currentLegNumber = trackedRace.getLastLegStarted(dateAsTimePoint);
|
||||
result.marks = new HashSet<MarkDTO>();
|
||||
result.course = new ArrayList<>();
|
||||
result.course = convertToRaceCourseDTO(trackedRace.getRace().getCourse(), trackedRace, dateAsTimePoint);
|
||||
// now make sure we don't duplicate the MarkDTO objects but instead use the ones from the RaceCourseDTO
|
||||
// object and amend them with the Position
|
||||
result.waypointPositions = new ArrayList<>();
|
||||
Set<Mark> marks = new HashSet<Mark>();
|
||||
Course course = trackedRace.getRace().getCourse();
|
||||
@@ -1939,32 +1941,22 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
|
||||
private ControlPointDTO convertToControlPointDTO(ControlPoint controlPoint, TrackedRace trackedRace, TimePoint timePoint) {
|
||||
ControlPointDTO result;
|
||||
final TimePoint timePointToUse = trackedRace == null ? null :
|
||||
timePoint == null ? MillisecondsTimePoint.now().minus(trackedRace.getDelayToLiveInMillis()) : timePoint;
|
||||
if (controlPoint instanceof ControlPointWithTwoMarks) {
|
||||
final Mark left = ((ControlPointWithTwoMarks) controlPoint).getLeft();
|
||||
final Position leftPos = trackedRace.getOrCreateTrack(left).getEstimatedPosition(timePoint, /* extrapolate */ false);
|
||||
final Position leftPos = timePointToUse == null ? null : trackedRace.getOrCreateTrack(left).getEstimatedPosition(timePointToUse, /* extrapolate */ false);
|
||||
final Mark right = ((ControlPointWithTwoMarks) controlPoint).getRight();
|
||||
final Position rightPos = trackedRace.getOrCreateTrack(right).getEstimatedPosition(timePoint, /* extrapolate */ false);
|
||||
final Position rightPos = timePointToUse == null ? null : trackedRace.getOrCreateTrack(right).getEstimatedPosition(timePointToUse, /* extrapolate */ false);
|
||||
result = new GateDTO(controlPoint.getId().toString(), controlPoint.getName(), convertToMarkDTO(left, leftPos), convertToMarkDTO(right, rightPos));
|
||||
} else {
|
||||
final Position posOfFirst = trackedRace.getOrCreateTrack(controlPoint.getMarks().iterator().next()).
|
||||
getEstimatedPosition(timePoint, /* extrapolate */ false);
|
||||
final Position posOfFirst = timePointToUse == null ? null : trackedRace.getOrCreateTrack(controlPoint.getMarks().iterator().next()).
|
||||
getEstimatedPosition(timePointToUse, /* extrapolate */ false);
|
||||
result = new MarkDTO(controlPoint.getId().toString(), controlPoint.getName(), posOfFirst == null ? -1 : posOfFirst.getLatDeg(), posOfFirst == null ? -1 : posOfFirst.getLngDeg());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ControlPointDTO convertToControlPointDTO(ControlPoint controlPoint) {
|
||||
ControlPointDTO result;
|
||||
if (controlPoint instanceof ControlPointWithTwoMarks) {
|
||||
final Mark left = ((ControlPointWithTwoMarks) controlPoint).getLeft();
|
||||
final Mark right = ((ControlPointWithTwoMarks) controlPoint).getRight();
|
||||
result = new GateDTO(controlPoint.getId().toString(), controlPoint.getName(), convertToMarkDTO(left, null), convertToMarkDTO(right, null));
|
||||
} else {
|
||||
result = new MarkDTO(controlPoint.getId().toString(), controlPoint.getName());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ControlPoint getOrCreateControlPoint(ControlPointDTO dto) {
|
||||
String idAsString = dto.getIdAsString();
|
||||
if (idAsString == null) {
|
||||
@@ -5075,22 +5067,40 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
raceLog.add(event);
|
||||
}
|
||||
|
||||
private WaypointDTO convertToWaypointDTO(Waypoint waypoint, Map<Serializable, ControlPointDTO> controlPointCache) {
|
||||
/**
|
||||
* @param trackedRace
|
||||
* if <code>null</code>, no position data will be attached to the {@link MarkDTO}s
|
||||
* @param timePoint
|
||||
* if <code>trackedRace</code> is not <code>null</code>, specifies the time point for which to determine
|
||||
* the mark positions and attach to the {@link MarkDTO}s. If <code>null<c/code>, the current time point
|
||||
* will be used as default.
|
||||
*/
|
||||
private WaypointDTO convertToWaypointDTO(Waypoint waypoint, Map<Serializable, ControlPointDTO> controlPointCache, TrackedRace trackedRace, TimePoint timePoint) {
|
||||
ControlPointDTO cp = controlPointCache.get(waypoint.getControlPoint().getId());
|
||||
if (cp == null) {
|
||||
cp = convertToControlPointDTO(waypoint.getControlPoint());
|
||||
cp = convertToControlPointDTO(waypoint.getControlPoint(), trackedRace, timePoint);
|
||||
controlPointCache.put(waypoint.getControlPoint().getId(), cp);
|
||||
}
|
||||
return new WaypointDTO(waypoint.getName(), cp, waypoint.getPassingInstructions());
|
||||
}
|
||||
|
||||
private RaceCourseDTO convertToRaceCourseDTO(CourseBase course) {
|
||||
/**
|
||||
* @param course
|
||||
* the course to convert
|
||||
* @param trackedRace
|
||||
* if <code>null</code>, no position data will be attached to the {@link MarkDTO}s
|
||||
* @param timePoint
|
||||
* if <code>trackedRace</code> is not <code>null</code>, specifies the time point for which to determine
|
||||
* the mark positions and attach to the {@link MarkDTO}s. If <code>null<c/code>, the current time point
|
||||
* will be used as default.
|
||||
*/
|
||||
private RaceCourseDTO convertToRaceCourseDTO(CourseBase course, TrackedRace trackedRace, TimePoint timePoint) {
|
||||
final RaceCourseDTO result;
|
||||
if (course != null) {
|
||||
List<WaypointDTO> waypointDTOs = new ArrayList<WaypointDTO>();
|
||||
Map<Serializable, ControlPointDTO> controlPointCache = new HashMap<>();
|
||||
for (Waypoint waypoint : course.getWaypoints()) {
|
||||
waypointDTOs.add(convertToWaypointDTO(waypoint, controlPointCache));
|
||||
waypointDTOs.add(convertToWaypointDTO(waypoint, controlPointCache, trackedRace, timePoint));
|
||||
}
|
||||
result = new RaceCourseDTO(waypointDTOs);
|
||||
} else {
|
||||
@@ -5106,7 +5116,7 @@ public class SailingServiceImpl extends ProxiedRemoteServiceServlet implements S
|
||||
if (lastPublishedCourse == null) {
|
||||
lastPublishedCourse = new CourseDataImpl("");
|
||||
}
|
||||
return convertToRaceCourseDTO(lastPublishedCourse);
|
||||
return convertToRaceCourseDTO(lastPublishedCourse, /* trackedRace */ null, /* timePoint */ null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import com.sap.sailing.domain.common.NauticalSide;
|
||||
import com.sap.sailing.domain.common.Position;
|
||||
|
||||
public class CoursePositionsDTO implements IsSerializable {
|
||||
public List<RaceCourseDTO> course;
|
||||
public RaceCourseDTO course;
|
||||
public List<Position> waypointPositions;
|
||||
public List<Position> startMarkPositions;
|
||||
public List<Position> finishMarkPositions;
|
||||
|
||||
Reference in new issue
Block a user