I've added the code for providing the legs names to the UI.

This commit is contained in:
I077899 committed 2013-02-13 13:59:58 +02:00
1 parent f80bc445ad
commit 4fa01a44c7
5 files changed
+96 -21

No files matched your search

@@ -6,6 +6,7 @@ import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.sap.sailing.gwt.ui.shared.BoatClassDTOsAndNotificationMessage;
import com.sap.sailing.gwt.ui.shared.ConfigurationException;
import com.sap.sailing.gwt.ui.shared.LegsNamesDTO;
import com.sap.sailing.gwt.ui.shared.PolarDiagramDTOAndNotificationMessage;
import com.sap.sailing.gwt.ui.shared.PositionDTO;
import com.sap.sailing.gwt.ui.shared.Request1TurnerDTO;
@@ -46,4 +47,7 @@ public interface SimulatorService extends RemoteService {
ResponseTotalTimeDTO getTotalTime_new(RequestTotalTimeDTO requestData) throws ConfigurationException;
Response1TurnerDTO get1Turner(final Request1TurnerDTO requestData) throws ConfigurationException;
LegsNamesDTO getLegs(char mode, WindFieldGenParamsDTO params, WindPatternDisplay pattern, boolean withWindField, int boatClassIndex)
throws WindPatternNotFoundException, ConfigurationException;
}
@@ -4,6 +4,7 @@ import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sap.sailing.gwt.ui.shared.BoatClassDTOsAndNotificationMessage;
import com.sap.sailing.gwt.ui.shared.LegsNamesDTO;
import com.sap.sailing.gwt.ui.shared.PolarDiagramDTOAndNotificationMessage;
import com.sap.sailing.gwt.ui.shared.PositionDTO;
import com.sap.sailing.gwt.ui.shared.Request1TurnerDTO;
@@ -42,4 +43,7 @@ public interface SimulatorServiceAsync {
void getTotalTime_new(RequestTotalTimeDTO requestData, AsyncCallback<ResponseTotalTimeDTO> asyncCallback);
void get1Turner(final Request1TurnerDTO requestData, AsyncCallback<Response1TurnerDTO> asyncCallback);
void getLegs(char mode, WindFieldGenParamsDTO params, WindPatternDisplay pattern, boolean withWindField, int boatClassIndex,
AsyncCallback<LegsNamesDTO> asyncCallback);
}
@@ -32,6 +32,7 @@ import com.sap.sailing.gwt.ui.shared.BoatClassDTO;
import com.sap.sailing.gwt.ui.shared.BoatClassDTOsAndNotificationMessage;
import com.sap.sailing.gwt.ui.shared.ConfigurationException;
import com.sap.sailing.gwt.ui.shared.CourseDTO;
import com.sap.sailing.gwt.ui.shared.LegsNamesDTO;
import com.sap.sailing.gwt.ui.shared.PathDTO;
import com.sap.sailing.gwt.ui.shared.PolarDiagramDTO;
import com.sap.sailing.gwt.ui.shared.PolarDiagramDTOAndNotificationMessage;
@@ -76,7 +77,6 @@ import com.sap.sailing.simulator.windfield.WindControlParameters;
import com.sap.sailing.simulator.windfield.WindFieldGenerator;
import com.sap.sailing.simulator.windfield.WindFieldGeneratorFactory;
import com.sap.sailing.simulator.windfield.impl.WindFieldGeneratorMeasured;
public class SimulatorServiceImpl extends RemoteServiceServlet implements SimulatorService {
private final static long serialVersionUID = 4445427185387524086L;
@@ -85,8 +85,10 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
private static final WindFieldGeneratorFactory wfGenFactory = WindFieldGeneratorFactory.INSTANCE;
private static final WindPatternDisplayManager wpDisplayManager = WindPatternDisplayManager.INSTANCE;
private static final String POLYLINE_PATH_NAME = "Polyline";
// private static final double REACHING_TOLERANCE_FACTOR = 0.03;
// private static final int MAX_NO_OF_STEPS = 800;
private static final double DEFAULT_REACHING_TOLERANCE = 0.15;
private static final int DEFAULT_STEP_MAX = 800;
private static final long DEFAULT_TIMESTEP = 4000;
private WindControlParameters controlParameters = new WindControlParameters(0, 0);
@@ -491,7 +493,7 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
PolarDiagram polarDiagram = polarDiagramAndNotificationMessage.getA();
String notificationMessage = polarDiagramAndNotificationMessage.getB();
Position startPosition = toPosition(requestData.firstPoint.position);
Position startPosition = toPosition(requestData.firstPoint);
Position endPosition = toPosition(requestData.secondPoint);
RectangularBoundary rectangularBoundry = new RectangularBoundary(startPosition, endPosition, 0.1);
@@ -503,14 +505,20 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
WindFieldGeneratorMeasured windFieldGenerator = new WindFieldGeneratorMeasured(rectangularBoundry, this.controlParameters);
windFieldGenerator.setGPSWind(gpsWind);
TimePoint startTime = new MillisecondsTimePoint(requestData.firstPoint.timepoint);
TimePoint startTime = new MillisecondsTimePoint(requestData.firstPointTimepoint);
PathGenerator1Turner pathGenerator = new PathGenerator1Turner(null);
TimedPositionWithSpeed oneTurner = pathGenerator.get1Turner(windFieldGenerator, polarDiagram, startPosition, endPosition, startTime,
requestData.leftSide);
return new Response1TurnerDTO(new SimulatorWindDTO(oneTurner.getPosition().getLatDeg(), oneTurner.getPosition().getLngDeg(), oneTurner.getSpeed()
.getKnots(), oneTurner.getSpeed().getBearing().getDegrees(), oneTurner.getTimePoint().asMillis()), notificationMessage);
TimedPositionWithSpeed oneTurner = pathGenerator.get1Turner(windFieldGenerator, polarDiagram, startPosition, endPosition, startTime,
requestData.leftSide,
DEFAULT_REACHING_TOLERANCE, DEFAULT_STEP_MAX, DEFAULT_TIMESTEP);
Position oneTurnerPosition = oneTurner.getPosition();
SpeedWithBearing oneTurnerWindSpeed = oneTurner.getSpeed();
TimePoint oneTurnerTimePoint = oneTurner.getTimePoint();
return new Response1TurnerDTO(new SimulatorWindDTO(oneTurnerPosition.getLatDeg(), oneTurnerPosition.getLngDeg(), oneTurnerWindSpeed.getKnots(),
oneTurnerWindSpeed.getBearing().getDegrees(), oneTurnerTimePoint.asMillis()), notificationMessage);
}
private void retreiveWindControlParameters(WindPatternDisplay pattern) {
@@ -528,17 +536,14 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
// f.setDouble(controlParameters, (Double) s.getValue());
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOGGER.warning("SimulatorServiceImpl => IllegalArgumentException with message " + e.getMessage());
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOGGER.warning("SimulatorServiceImpl => IllegalAccessException with message " + e.getMessage());
}
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
LOGGER.warning("SimulatorServiceImpl => SecurityException with message " + e.getMessage());
} catch (NoSuchFieldException e) {
LOGGER.info(e.getMessage());
LOGGER.warning("SimulatorServiceImpl => NoSuchFieldException with message " + e.getMessage());
}
}
@@ -964,4 +969,53 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
public static boolean equals(Position position, PositionDTO positonDTO) {
return (position.getLatDeg() == positonDTO.latDeg && position.getLngDeg() == positonDTO.lngDeg);
}
@Override
public LegsNamesDTO getLegs(char mode, WindFieldGenParamsDTO params, WindPatternDisplay pattern, boolean withWindField, int boatClassIndex)
throws WindPatternNotFoundException, ConfigurationException {
WindFieldGenerator wf = null;
List<Position> course = null;
TimePoint startTime = new MillisecondsTimePoint(params.getStartTime().getTime());
TimePoint timeStep = new MillisecondsTimePoint(params.getTimeStep().getTime());
controlParameters.resetBlastRandomStream = params.isKeepState();
this.retreiveWindControlParameters(pattern);
wf = wfGenFactory.createWindFieldGenerator(pattern.getWindPattern().name(), null, controlParameters);
if (wf == null) {
throw new WindPatternNotFoundException("Please select a valid wind pattern.");
}
if (mode != SailingSimulatorUtil.measured) {
Position nw = new DegreePosition(params.getNorthWest().latDeg, params.getNorthWest().lngDeg);
Position se = new DegreePosition(params.getSouthEast().latDeg, params.getSouthEast().lngDeg);
course = new ArrayList<Position>();
course.add(nw);
course.add(se);
Position[] gridAreaGps = new Position[2];
gridAreaGps = course.toArray(gridAreaGps);
wf.setGridAreaGps(gridAreaGps);
}
int[] gridRes = new int[2];
gridRes[0] = params.getxRes();
gridRes[1] = params.getyRes();
wf.setGridResolution(gridRes);
wf.generate(startTime, null, timeStep);
Long longestPathTime = 0L;
Pair<PolarDiagram, String> polarDiagramAndNotificationMessage = this.getPolarDiagram(boatClassIndex);
PolarDiagram pd = polarDiagramAndNotificationMessage.getA();
SimulationParameters sp = new SimulationParametersImpl(course, pd, wf, mode);
SailingSimulator simulator = new SailingSimulatorImpl(sp);
List<String> legsNames = simulator.getLegsNames(boatClassIndex);
return new LegsNamesDTO(polarDiagramAndNotificationMessage.getB(), legsNames);
}
}
@@ -1,5 +1,6 @@
package com.sap.sailing.simulator;
import java.util.List;
import java.util.Map;
public interface SailingSimulator {
@@ -15,4 +16,6 @@ public interface SailingSimulator {
Map<String, Path> getAllPathsEvenTimed(long millisecondsStep);
Path getRaceCourse();
List<String> getLegsNames(int boatClassIndex);
}
@@ -150,7 +150,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
// get instance of heuristic searcher
PathGeneratorTreeGrowWind2 genTreeGrow = new PathGeneratorTreeGrowWind2(this.simulationParameters);
// search best left-starting 1-turner
genTreeGrow.setEvaluationParameters("L", 1);
Path leftPath = genTreeGrow.getPath();
@@ -172,12 +172,12 @@ public class SailingSimulatorImpl implements SailingSimulator {
// search best multi-turn course
genTreeGrow.setEvaluationParameters(null, 0);
Path optPath = genTreeGrow.getPath();
// evaluate opportunistic heuristic
PathGeneratorOpportunistEuclidian genOpportunistic = new PathGeneratorOpportunistEuclidian(this.simulationParameters);
// PathGeneratorOpportunistVMG genOpportunistic = new PathGeneratorOpportunistVMG(simulationParameters);
// left-starting opportunist
genOpportunistic.setEvaluationParameters(left1TurnMiddle, right1TurnMiddle, true);
Path oppPathL = genOpportunistic.getPath();
@@ -185,7 +185,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
genOpportunistic.setEvaluationParameters(left1TurnMiddle, right1TurnMiddle, false);
Path oppPathR = genOpportunistic.getPath();
// compare left- & right-starting opportunists
// compare left- & right-starting opportunists
Path oppPath = null;
if (oppPathL.getPathPoints().get(oppPathL.getPathPoints().size() - 1).getTimePoint().asMillis() <= oppPathR
.getPathPoints().get(oppPathR.getPathPoints().size() - 1).getTimePoint().asMillis()) {
@@ -223,7 +223,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
}
}
}
allPaths.put("4#1-Turner Right", rightPath);
allPaths.put("3#1-Turner Left", leftPath);
allPaths.put("2#Opportunistic", oppPath);
@@ -439,4 +439,14 @@ public class SailingSimulatorImpl implements SailingSimulator {
return path;
}
@Override
public List<String> getLegsNames(int boatClassIndex) {
List<String> result = new ArrayList<String>();
result.add("Bogdan boatClassIndex=" + boatClassIndex);
result.add("Andu boatClassIndex=" + boatClassIndex);
result.add("Mircea boatClassIndex=" + boatClassIndex);
return result;
}
}