Merge branch 'simulator' of ssh://git.wdf.sap.corp:29418/SAPSail/sapsailingcapture into simulator

Conflicts:
	java/com.sap.sailing.gwt.ui/src/main/java/com/sap/sailing/gwt/ui/server/SimulatorServiceImpl.java
This commit is contained in:
Alexandru Dimofte committed 2012-05-30 11:27:40 +03:00
commit 55c87a4bcf
12 files changed
+306 -75

No files matched your search

@@ -2,16 +2,13 @@ package com.sap.sailing.gwt.ui.server;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.sap.sailing.domain.base.impl.KnotSpeedImpl;
import com.sap.sailing.domain.common.Bearing;
import com.sap.sailing.domain.common.Distance;
import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.Speed;
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
import com.sap.sailing.domain.common.impl.DegreePosition;
import com.sap.sailing.domain.common.impl.NauticalMileDistance;
@@ -37,12 +34,13 @@ import com.sap.sailing.simulator.SimulationParameters;
import com.sap.sailing.simulator.TimedPositionWithSpeed;
import com.sap.sailing.simulator.WindControlParameters;
import com.sap.sailing.simulator.WindField;
import com.sap.sailing.simulator.WindFieldGenerator;
import com.sap.sailing.simulator.WindFieldGeneratorFactory;
import com.sap.sailing.simulator.impl.PolarDiagramImpl;
import com.sap.sailing.simulator.impl.RectangularBoundary;
import com.sap.sailing.simulator.impl.SailingSimulatorImpl;
import com.sap.sailing.simulator.impl.SimulationParametersImpl;
import com.sap.sailing.simulator.impl.TimedPositionWithSpeedSimple;
import com.sap.sailing.simulator.impl.WindFieldImpl;
public class SimulatorServiceImpl extends RemoteServiceServlet implements SimulatorService {
@@ -50,11 +48,11 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
* Generated uid serial version
*/
private static final long serialVersionUID = 4445427185387524086L;
private static Logger logger = Logger.getLogger("com.sap.sailing");
private WindControlParameters controlParameters = new WindControlParameters(0,0);
private WindControlParameters controlParameters = new WindControlParameters(0, 0);
@Override
public PositionDTO[] getRaceLocations() {
PositionDTO lakeGarda = new PositionDTO();
@@ -132,16 +130,16 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
}
private void retreiveWindControlParameters(WindPatternDisplay pattern) {
for(WindPatternSetting<?> s : pattern.getSettings()) {
for (WindPatternSetting<?> s : pattern.getSettings()) {
Field f;
try {
f = controlParameters.getClass().getField(s.getName());
try {
logger.info("Setting " + f.getName() + " to " + s.getName());
f.set(controlParameters, s.getValue());
//f.setDouble(controlParameters, (Double) s.getValue());
// f.setDouble(controlParameters, (Double) s.getValue());
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -153,12 +151,12 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchFieldException e) {
logger.info(e.getMessage());
logger.info(e.getMessage());
}
}
}
@Override
public WindFieldDTO getWindField(WindFieldGenParamsDTO params, WindPatternDisplay pattern) {
@@ -166,15 +164,19 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
Position se = new DegreePosition(params.getSouthEast().latDeg, params.getSouthEast().lngDeg);
List<Position> course = new ArrayList<Position>();
course.add(nw);
course.add(se);
course.add(se);
RectangularBoundary bd = new RectangularBoundary(nw, se, 0.1);
List<Position> lattice = bd.extractLattice(params.getxRes(), params.getyRes());
// List<Position> lattice = bd.extractLattice(params.getxRes(), params.getyRes());
retreiveWindControlParameters(pattern);
controlParameters.baseWindBearing = bd.getSouth().getDegrees();
WindField wf = new WindFieldImpl(bd, controlParameters);
controlParameters.baseWindBearing = bd.getSouth().getDegrees();
WindFieldGenerator wf = WindFieldGeneratorFactory.INSTANCE.createWindFieldGenerator(pattern.getWindPattern()
.name(), bd, controlParameters);
List<Position> lattice = wf.extractLattice(params.getxRes(), params.getyRes());
List<WindDTO> wList = new ArrayList<WindDTO>();
if (lattice != null) {
@@ -192,11 +194,12 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
return wfDTO;
}
/**
* Currently the path is a list of WindDTO objects at the path points and only a single optimal path is returned
*
* */
public PathDTO[] getPaths(WindFieldGenParamsDTO params, WindPatternDisplay pattern) {
public PathDTO[] getPaths(WindFieldGenParamsDTO params, WindPatternDisplay pattern) {
Position nw = new DegreePosition(params.getNorthWest().latDeg, params.getNorthWest().lngDeg);
Position se = new DegreePosition(params.getSouthEast().latDeg, params.getSouthEast().lngDeg);
@@ -206,12 +209,12 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
RectangularBoundary bd = new RectangularBoundary(nw, se, 0.1);
retreiveWindControlParameters(pattern);
controlParameters.baseWindBearing = bd.getSouth().getDegrees();
WindField wf = new WindFieldImpl(bd, controlParameters);
//TODO Get all the paths that need to be displayed
controlParameters.baseWindBearing = bd.getSouth().getDegrees();
WindFieldGenerator wf = WindFieldGeneratorFactory.INSTANCE.createWindFieldGenerator(pattern.getWindPattern()
.name(), bd, controlParameters);
// TODO Get all the paths that need to be displayed
List<WindDTO> path = getOptimumPath(course, wf);
PathDTO[] pathDTO = new PathDTO[1];
pathDTO[0] = new PathDTO("Path 1");
@@ -230,14 +233,14 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
List<WindDTO> wList = new ArrayList<WindDTO>();
for (TimedPositionWithSpeed p : pth.getPathPoints()) {
// the null in the Wind output is the timestamp - this Wind is time-invariant!
//System.out.println("Position: " + p.getPosition() + " Wind: "
// + wf.getWind(new TimedPositionWithSpeedSimple(p.getPosition())));
// System.out.println("Position: " + p.getPosition() + " Wind: "
// + wf.getWind(new TimedPositionWithSpeedSimple(p.getPosition())));
// System.out.println("Position: " + p.getPosition() + " Wind: " +
// wf.getWind(pth.getPositionAtTime(p.getTimePoint())));
Wind localWind = wf.getWind(pth.getPositionAtTime(p.getTimePoint()));
logger.fine(localWind.toString());
WindDTO w = createWindDTO(localWind);
//w.trueWindBearingDeg = 10.0*i;
// w.trueWindBearingDeg = 10.0*i;
++i;
wList.add(w);
}
@@ -255,7 +258,7 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
return new BoatClassDTO[] { boatClassDTO };
}
private WindDTO createWindDTO(Wind wind) {
WindDTO windDTO = new WindDTO();
windDTO.trueWindBearingDeg = wind.getBearing().getDegrees();
@@ -263,20 +266,18 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
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.timepoint = wind.getTimePoint().asMillis();
}
return windDTO;
}
@Override
public WindPatternDisplay getWindPatternDisplay(WindPatternDTO pattern) {
return WindPatternDisplayManager.INSTANCE.getDisplay(WindPattern.valueOf(pattern.name));
return WindPatternDisplayManager.INSTANCE.getDisplay(WindPattern.valueOf(pattern.name));
}
}
@@ -27,7 +27,7 @@ public class WindPatternDisplayManagerImpl implements WindPatternDisplayManager
public WindPatternDisplay getDisplay(WindPattern windPattern) {
WindPatternDisplay display = new WindPatternDisplayImpl(windPattern);
WindPatternSetting<Double> windSpeedSetting = new WindPatternSettingSliderBar("baseWindSpeed",
"Base Wind Speed (kn)", 0, 30, 0);
"Base Wind Speed (kn)", 0, 30, 3);
display.addSetting(windSpeedSetting);
switch (windPattern) {
@@ -189,7 +189,7 @@ public class RaceCourseCanvasOverlay extends FullCanvasOverlay {
public void onDoubleClick(MapDoubleClickEvent event) {
if (isSelected) {
endPoint = event.getLatLng();
logger.fine("Clicked endPoint " + "here " + endPoint);
logger.info("Clicked endPoint " + "here " + endPoint);
if (endPoint != null) {
setEndPoint(endPoint);
getMap().removeMapMouseMoveHandler(raceCourseMapMouseMoveHandler);
@@ -0,0 +1,59 @@
/**
*
*/
package com.sap.sailing.simulator.test;
import static org.junit.Assert.*;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Logger;
import org.junit.Test;
import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.impl.DegreePosition;
import com.sap.sailing.simulator.WindControlParameters;
import com.sap.sailing.simulator.impl.WindFieldGeneratorBlastImpl;
import com.sap.sailing.simulator.impl.RectangularBoundary;
/**
* Test for @WindFieldGenerator
* @author Nidhi Sawhney(D054070)
*
*/
public class WindFieldGeneratorTest {
private static Logger logger = Logger.getLogger("com.sap.sailing");
@Test
public void testWindFieldGeneratorBasic() {
Position start = new DegreePosition(54.32447456461419, 10.15613079071045);
Position end = new DegreePosition(54.32877915239163, 10.156173706054688);
List<Position> course = new LinkedList<Position>();
course.add(start);
course.add(end);
WindControlParameters windParameters = new WindControlParameters(3, 180);
RectangularBoundary bd = new RectangularBoundary(start, end);
WindFieldGeneratorBlastImpl wf = new WindFieldGeneratorBlastImpl(bd, windParameters);
int hSteps = 10;
int vSteps = 5;
List<Position> positionList = wf.extractLattice(hSteps,vSteps);
assert(positionList.size() == hSteps*vSteps);
int index = 0;
for(Position p : positionList) {
logger.info("P" + ++index + ":" + p);
}
Position[][] positionGrid = wf.getPositionsGrid();
assertNotNull("Position Grid is not null", positionGrid);
assertEquals("Position Grid Number of Rows", vSteps, positionGrid.length);
assertEquals("Position Grid Number of Columns", hSteps, positionGrid[0].length);
for (int i = 0; i < vSteps; ++i) {
for (int j = 0; j < hSteps; ++j) {
logger.info("P["+i+"]["+j+"]:" + positionGrid[i][j]);
assertEquals("Map index check",positionGrid[i][j],wf.getPosition(i, j));
}
}
}
}
@@ -0,0 +1,13 @@
package com.sap.sailing.simulator;
import java.util.List;
import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.TimePoint;
public interface WindFieldGenerator extends WindField {
public List<Position> extractLattice(int hSteps, int vSteps);
public void generate(TimePoint start, TimePoint end, TimePoint step);
}
@@ -0,0 +1,11 @@
package com.sap.sailing.simulator;
import com.sap.sailing.simulator.impl.WindFieldGeneratorFactoryImpl;
public interface WindFieldGeneratorFactory {
static WindFieldGeneratorFactory INSTANCE = new WindFieldGeneratorFactoryImpl();
public WindFieldGenerator createWindFieldGenerator(String patternName, Boundary boundary,
WindControlParameters windParameters);
}
@@ -1,9 +0,0 @@
package com.sap.sailing.simulator;
import com.sap.sailing.domain.common.Position;
public interface WindLattice {
Position[][] getPoints();
}
@@ -0,0 +1,21 @@
package com.sap.sailing.simulator.impl;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.simulator.Boundary;
import com.sap.sailing.simulator.WindControlParameters;
import com.sap.sailing.simulator.WindFieldGenerator;
import com.sap.sailing.simulator.impl.WindFieldGeneratorImpl;
public class WindFieldGeneratorBlastImpl extends WindFieldGeneratorImpl implements WindFieldGenerator {
public WindFieldGeneratorBlastImpl(Boundary boundary, WindControlParameters windParameters) {
super(boundary, windParameters);
}
@Override
public void generate(TimePoint start, TimePoint end, TimePoint step) {
// TODO Auto-generated method stub
}
}
@@ -0,0 +1,22 @@
package com.sap.sailing.simulator.impl;
import com.sap.sailing.simulator.Boundary;
import com.sap.sailing.simulator.WindControlParameters;
import com.sap.sailing.simulator.WindFieldGenerator;
import com.sap.sailing.simulator.WindFieldGeneratorFactory;
public class WindFieldGeneratorFactoryImpl implements WindFieldGeneratorFactory {
@Override
public WindFieldGenerator createWindFieldGenerator(String patternName, Boundary boundary,
WindControlParameters windParameters) {
if (patternName.equals("BLASTS")) {
return new WindFieldGeneratorBlastImpl(boundary, windParameters);
}
if (patternName.equals("OSCILLATIONS")) {
return new WindFieldGeneratorOscillationImpl(boundary, windParameters);
}
return null;
}
}
@@ -0,0 +1,118 @@
package com.sap.sailing.simulator.impl;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import com.sap.sailing.domain.base.SpeedWithBearing;
import com.sap.sailing.domain.base.impl.KilometersPerHourSpeedWithBearingImpl;
import com.sap.sailing.domain.base.impl.KnotSpeedImpl;
import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.domain.common.impl.DegreeBearingImpl;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.domain.tracking.Wind;
import com.sap.sailing.domain.tracking.impl.WindImpl;
import com.sap.sailing.simulator.Boundary;
import com.sap.sailing.simulator.TimedPosition;
import com.sap.sailing.simulator.WindControlParameters;
import com.sap.sailing.simulator.WindFieldGenerator;
public abstract class WindFieldGeneratorImpl implements WindFieldGenerator {
protected Boundary boundary;
protected WindControlParameters windParameters;
protected List<Position> sortedPositionList;
protected Position[][] positions;
protected Map<Pair<Integer, Integer>, Position> indexPositionMap;
protected Map<TimePoint, SpeedWithBearing[][]> timeSpeedWithBearingMap;
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger("com.sap.sailing");
private class LatLngComparator implements Comparator<Position> {
@Override
public int compare(Position p1, Position p2) {
if (p1.getLatDeg() < p2.getLatDeg()) {
return -1;
} else if (p1.getLatDeg() == p2.getLngDeg()) {
if (p1.getLngDeg() < p2.getLngDeg()) {
return -1;
} else if (p1.getLngDeg() == p2.getLngDeg()) {
return 0;
} else {
return 1;
}
} else {
return 1;
}
}
}
public WindFieldGeneratorImpl(Boundary boundary, WindControlParameters windParameters) {
this.boundary = boundary;
this.windParameters = windParameters;
this.positions = null;
this.indexPositionMap = null;
}
public List<Position> extractLattice(int hPoints, int vPoints) {
sortedPositionList = boundary.extractLattice(hPoints, vPoints);
Collections.sort(sortedPositionList, new LatLngComparator());
assert (sortedPositionList.size() == hPoints * vPoints);
positions = new Position[vPoints][hPoints];
indexPositionMap = new HashMap<Pair<Integer, Integer>, Position>();
int i = 0;
int j = 0;
for (Position p : sortedPositionList) {
if (j < hPoints) {
positions[i][j] = p;
indexPositionMap.put(new Pair<Integer, Integer>(i, j), p);
++j;
} else {
j = 0;
++i;
positions[i][j] = p;
indexPositionMap.put(new Pair<Integer, Integer>(i, j), p);
++j;
}
}
return sortedPositionList;
}
@Override
public Wind getWind(TimedPosition coordinates) {
KnotSpeedImpl knotSpeedImpl = new KnotSpeedImpl(windParameters.baseWindSpeed);
double wBearing = windParameters.baseWindBearing
* (1 + coordinates.getPosition().getDistance(boundary.getCorners().get("NorthWest")).getMeters()
/ boundary.getHeight().getMeters());
SpeedWithBearing wspeed = new KilometersPerHourSpeedWithBearingImpl(knotSpeedImpl.getKilometersPerHour(),
new DegreeBearingImpl(wBearing));
return new WindImpl(coordinates.getPosition(), coordinates.getTimePoint(), wspeed);
}
@Override
public Boundary getBoundaries() {
return boundary;
}
public Position[][] getPositionsGrid() {
return positions;
}
public Position getPosition(int i, int j) {
Pair<Integer, Integer> indexKey = new Pair<Integer, Integer>(i, j);
return indexPositionMap.get(indexKey);
}
}
@@ -0,0 +1,21 @@
package com.sap.sailing.simulator.impl;
import com.sap.sailing.domain.common.TimePoint;
import com.sap.sailing.simulator.Boundary;
import com.sap.sailing.simulator.WindControlParameters;
import com.sap.sailing.simulator.WindFieldGenerator;
import com.sap.sailing.simulator.impl.WindFieldGeneratorImpl;
public class WindFieldGeneratorOscillationImpl extends WindFieldGeneratorImpl implements WindFieldGenerator {
public WindFieldGeneratorOscillationImpl(Boundary boundary, WindControlParameters windParameters) {
super(boundary, windParameters);
}
@Override
public void generate(TimePoint start, TimePoint end, TimePoint step) {
// TODO Auto-generated method stub
}
}
@@ -1,26 +0,0 @@
package com.sap.sailing.simulator.impl;
import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.impl.DegreePosition;
import com.sap.sailing.simulator.WindLattice;
public class WindLatticeImpl implements WindLattice {
public class LatticePoint extends DegreePosition {
public LatticePoint(double lat, double lng) {
super(lat, lng);
}
public LatticePoint previous;
public LatticePoint left;
public LatticePoint right;
}
public LatticePoint[][] points;
@Override
public Position[][] getPoints() {
return points;
}
}