mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-08 21:30:57 +00:00
added skeleton for CourseDesignComputer.java.
This commit is contained in:
1 parent
c438711f3a
commit
60d615a671
7 files changed
+159
-53
No files matched your search
+5
@@ -0,0 +1,5 @@
|
||||
package com.sap.sailing.domain.common.racelog.courseDesigner;
|
||||
|
||||
public class CourseDesign {
|
||||
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package com.sap.sailing.racecommittee.app.courseDesigner;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.BoatClassType;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.CourseLayout;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.NumberOfRounds;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.TargetTime;
|
||||
|
||||
public class CourseDesignComputer {
|
||||
private LatLng startBoatPosition;
|
||||
private Double windSpeed;
|
||||
private Integer windDirection;
|
||||
private BoatClassType boatClass;
|
||||
private CourseLayout courseLayout;
|
||||
private NumberOfRounds numberOfRounds;
|
||||
private TargetTime targetTime;
|
||||
|
||||
public LatLng getStartBoatPosition() {
|
||||
return startBoatPosition;
|
||||
}
|
||||
|
||||
public CourseDesignComputer setStartBoatPosition(LatLng startBoatPosition) {
|
||||
this.startBoatPosition = startBoatPosition;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Double getWindSpeed() {
|
||||
return windSpeed;
|
||||
}
|
||||
|
||||
public CourseDesignComputer setWindSpeed(Double windSpeed) {
|
||||
this.windSpeed = windSpeed;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getWindDirection() {
|
||||
return windDirection;
|
||||
}
|
||||
|
||||
public CourseDesignComputer setWindDirection(Integer windDirection) {
|
||||
this.windDirection = windDirection;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BoatClassType getBoatClass() {
|
||||
return boatClass;
|
||||
}
|
||||
|
||||
public CourseDesignComputer setBoatClass(BoatClassType boatClass) {
|
||||
this.boatClass = boatClass;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CourseLayout getCourseLayout() {
|
||||
return courseLayout;
|
||||
}
|
||||
|
||||
public CourseDesignComputer setCourseLayout(CourseLayout courseLayout) {
|
||||
this.courseLayout = courseLayout;
|
||||
return this;
|
||||
}
|
||||
|
||||
public NumberOfRounds getNumberOfRounds() {
|
||||
return numberOfRounds;
|
||||
}
|
||||
|
||||
public CourseDesignComputer setNumberOfRounds(NumberOfRounds numberOfRounds) {
|
||||
this.numberOfRounds = numberOfRounds;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TargetTime getTargetTime() {
|
||||
return targetTime;
|
||||
}
|
||||
|
||||
public CourseDesignComputer setTargetTime(TargetTime targetTime) {
|
||||
this.targetTime = targetTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CourseDesignComputer compute() {
|
||||
if(startBoatPosition != null && windSpeed != null && windDirection != null && boatClass != null && courseLayout != null && numberOfRounds != null && targetTime != null)
|
||||
return null;
|
||||
else
|
||||
throw new IllegalStateException("At least one mandatory parameter was not set in the computer!");
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -3,6 +3,7 @@ package com.sap.sailing.racecommittee.app.data;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.domain.base.CourseBase;
|
||||
import com.sap.sailing.domain.base.EventBase;
|
||||
@@ -36,10 +37,8 @@ public interface DataStore {
|
||||
public CourseBase getLastPublishedCourseDesign();
|
||||
public void setLastPublishedCourseDesign(CourseBase courseData);
|
||||
|
||||
public Double getLastLongitude();
|
||||
public void setLastLongitude(Double lastLongitude);
|
||||
public Double getLastLatitude();
|
||||
public void setLastLatitude(Double lastLatitude);
|
||||
public LatLng getLastWindPosition();
|
||||
public void setLastWindPosition(LatLng lastWindPosition);
|
||||
public Integer getLastWindDirection();
|
||||
public void setLastWindDirection(Integer lastWindDirection);
|
||||
public Double getLastWindSpeed();
|
||||
|
||||
+13
-17
@@ -4,6 +4,7 @@ import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.sap.sailing.domain.base.CourseArea;
|
||||
import com.sap.sailing.domain.base.CourseBase;
|
||||
import com.sap.sailing.domain.base.EventBase;
|
||||
@@ -18,8 +19,9 @@ public enum InMemoryDataStore implements DataStore {
|
||||
private HashMap<Serializable, ManagedRace> managedRaceById;
|
||||
private HashMap<Serializable, Mark> marksById;
|
||||
private CourseBase courseData;
|
||||
private Double lastLatitude, lastLongitude, lastWindSpeed;
|
||||
private Double lastWindSpeed;
|
||||
private Integer lastWindDirection;
|
||||
private LatLng lastWindPosition;
|
||||
|
||||
private InMemoryDataStore() {
|
||||
reset();
|
||||
@@ -172,22 +174,6 @@ public enum InMemoryDataStore implements DataStore {
|
||||
* * * * * * *
|
||||
*/
|
||||
@Override
|
||||
public Double getLastLongitude() {
|
||||
return lastLongitude;
|
||||
}
|
||||
@Override
|
||||
public void setLastLongitude(Double lastLongitude) {
|
||||
this.lastLongitude = lastLongitude;
|
||||
}
|
||||
@Override
|
||||
public Double getLastLatitude() {
|
||||
return lastLatitude;
|
||||
}
|
||||
@Override
|
||||
public void setLastLatitude(Double lastLatitude) {
|
||||
this.lastLatitude = lastLatitude;
|
||||
}
|
||||
@Override
|
||||
public Integer getLastWindDirection() {
|
||||
return lastWindDirection;
|
||||
}
|
||||
@@ -203,4 +189,14 @@ public enum InMemoryDataStore implements DataStore {
|
||||
public void setLastWindSpeed(Double lastWindSpeed) {
|
||||
this.lastWindSpeed = lastWindSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastWindPosition(LatLng lastWindPosition) {
|
||||
this.lastWindPosition = lastWindPosition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LatLng getLastWindPosition() {
|
||||
return this.lastWindPosition;
|
||||
}
|
||||
}
|
||||
+22
-17
@@ -17,6 +17,7 @@ import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.data.InMemoryDataStore;
|
||||
import com.sap.sailing.racecommittee.app.logging.ExLog;
|
||||
@@ -77,17 +78,19 @@ public class WindActivity extends BaseActivity implements CompassDirectionListen
|
||||
btnSend.setOnClickListener(new OnClickListener() {
|
||||
|
||||
public void onClick(View v) {
|
||||
try{
|
||||
InMemoryDataStore.INSTANCE.setLastWindSpeed(Double.valueOf(windSpeed.getText().toString().replace(",", ".")));
|
||||
InMemoryDataStore.INSTANCE.setLastWindDirection(Integer.valueOf(windDirection.getText().toString()));
|
||||
InMemoryDataStore.INSTANCE.setLastLatitude(Double.valueOf(latitude.getText().toString()));
|
||||
InMemoryDataStore.INSTANCE.setLastLongitude(Double.valueOf(longitude.getText().toString()));
|
||||
//TODO uses domain Wind and send result to calling activity instead of using InMemoryDataStore
|
||||
//Wind windMeasurement = new WindImpl();
|
||||
Intent returnIntent = new Intent();
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
}catch (NumberFormatException nfe){
|
||||
try {
|
||||
InMemoryDataStore.INSTANCE.setLastWindSpeed(Double.valueOf(windSpeed.getText().toString()
|
||||
.replace(",", ".")));
|
||||
InMemoryDataStore.INSTANCE.setLastWindDirection(Integer.valueOf(windDirection.getText().toString()));
|
||||
LatLng lastWindPosition = new LatLng(Double.valueOf(latitude.getText().toString()), Double
|
||||
.valueOf(longitude.getText().toString()));
|
||||
InMemoryDataStore.INSTANCE.setLastWindPosition(lastWindPosition);
|
||||
// TODO uses domain Wind and send result to calling activity instead of using InMemoryDataStore
|
||||
// Wind windMeasurement = new WindImpl();
|
||||
Intent returnIntent = new Intent();
|
||||
setResult(RESULT_OK, returnIntent);
|
||||
finish();
|
||||
} catch (NumberFormatException nfe) {
|
||||
Toast.makeText(WindActivity.this, "The entered information is not valid", Toast.LENGTH_LONG).show();
|
||||
ExLog.i(this.getClass().getCanonicalName(), nfe.getMessage());
|
||||
}
|
||||
@@ -96,11 +99,13 @@ public class WindActivity extends BaseActivity implements CompassDirectionListen
|
||||
|
||||
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, this);
|
||||
|
||||
windSpeed.setText(InMemoryDataStore.INSTANCE.getLastWindSpeed()+"");
|
||||
windDirection.setText(InMemoryDataStore.INSTANCE.getLastWindDirection()+"");
|
||||
latitude.setText(InMemoryDataStore.INSTANCE.getLastLatitude()+"");
|
||||
longitude.setText(InMemoryDataStore.INSTANCE.getLastLongitude()+"");
|
||||
|
||||
windSpeed.setText(InMemoryDataStore.INSTANCE.getLastWindSpeed() + "");
|
||||
windDirection.setText(InMemoryDataStore.INSTANCE.getLastWindDirection() + "");
|
||||
if (InMemoryDataStore.INSTANCE.getLastWindPosition() != null) {
|
||||
latitude.setText(InMemoryDataStore.INSTANCE.getLastWindPosition().latitude + "");
|
||||
longitude.setText(InMemoryDataStore.INSTANCE.getLastWindPosition().longitude + "");
|
||||
}
|
||||
}
|
||||
|
||||
DecimalFormat speedFormat = new DecimalFormat("##.0");
|
||||
@@ -123,7 +128,7 @@ public class WindActivity extends BaseActivity implements CompassDirectionListen
|
||||
BigDecimal round = decimal.setScale(precision, BigDecimal.ROUND_UP);
|
||||
return round.floatValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
locationManager.removeUpdates(this);
|
||||
|
||||
+29
-15
@@ -25,13 +25,14 @@ import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.MapView;
|
||||
import com.google.android.gms.maps.MapsInitializer;
|
||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.BoatClassType;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.CourseDesign;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.CourseLayout;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.NumberOfRounds;
|
||||
import com.sap.sailing.domain.common.racelog.courseDesigner.TargetTime;
|
||||
import com.sap.sailing.racecommittee.app.R;
|
||||
import com.sap.sailing.racecommittee.app.courseDesigner.CourseDesignComputer;
|
||||
import com.sap.sailing.racecommittee.app.data.DataStore;
|
||||
import com.sap.sailing.racecommittee.app.data.InMemoryDataStore;
|
||||
import com.sap.sailing.racecommittee.app.ui.activities.WindActivity;
|
||||
@@ -52,6 +53,8 @@ public class ClassicCourseDesignDialogFragment extends RaceDialogFragment {
|
||||
private Spinner spinnerNumberOfRounds;
|
||||
private Spinner spinnerTargetTime;
|
||||
|
||||
private CourseDesignComputer courseDesignComputer;
|
||||
|
||||
private ArrayAdapter<CourseLayout> courseLayoutAdapter;
|
||||
|
||||
// TODO determine this by given race
|
||||
@@ -97,8 +100,6 @@ public class ClassicCourseDesignDialogFragment extends RaceDialogFragment {
|
||||
|
||||
mMapView = (MapView) view.findViewById(R.id.mapView);
|
||||
mMapView.onCreate(mBundle);
|
||||
setUpMapIfNeeded(view);
|
||||
|
||||
return view;
|
||||
|
||||
}
|
||||
@@ -136,6 +137,13 @@ public class ClassicCourseDesignDialogFragment extends RaceDialogFragment {
|
||||
setupNumberOfRoundsSpinner();
|
||||
spinnerTargetTime = (Spinner) getView().findViewById(R.id.classic_course_designer_target_time);
|
||||
setupTargetTimeSpinner();
|
||||
|
||||
DataStore ds = InMemoryDataStore.INSTANCE;
|
||||
courseDesignComputer= new CourseDesignComputer().setStartBoatPosition(ds.getLastWindPosition()).setWindDirection(ds.getLastWindDirection())
|
||||
.setWindSpeed(ds.getLastWindSpeed()).setBoatClass(selectedBoatClass)
|
||||
.setCourseLayout(selectedCourseLayout).setNumberOfRounds(selectedNumberOfRounds)
|
||||
.setTargetTime(selectedTargetTime);
|
||||
setUpMapIfNeeded(getView());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,13 +156,20 @@ public class ClassicCourseDesignDialogFragment extends RaceDialogFragment {
|
||||
}
|
||||
}// onActivityResult
|
||||
|
||||
private void recomputeCourseDesign() {
|
||||
private CourseDesign recomputeCourseDesign() {
|
||||
try{
|
||||
courseDesignComputer.compute();
|
||||
}catch (IllegalStateException ise){
|
||||
Toast.makeText(
|
||||
getActivity(),
|
||||
ise.getMessage(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
DataStore ds = InMemoryDataStore.INSTANCE;
|
||||
Toast.makeText(
|
||||
getActivity(),
|
||||
"" + ds.getLastLatitude() + ds.getLastLongitude() + ds.getLastWindDirection() + ds.getLastWindSpeed()
|
||||
+ selectedBoatClass + selectedCourseLayout + selectedNumberOfRounds + selectedTargetTime,
|
||||
Toast.LENGTH_LONG).show();
|
||||
"" + ds.getLastWindPosition() + ds.getLastWindDirection() + ds.getLastWindSpeed() + selectedBoatClass
|
||||
+ selectedCourseLayout + selectedNumberOfRounds + selectedTargetTime, Toast.LENGTH_LONG).show();
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@@ -169,7 +184,7 @@ public class ClassicCourseDesignDialogFragment extends RaceDialogFragment {
|
||||
courseLayoutAdapter.clear();
|
||||
courseLayoutAdapter.addAll(selectedBoatClass.getPossibleCourseLayoutsWithTargetTime().keySet());
|
||||
courseLayoutAdapter.notifyDataSetChanged();
|
||||
if(selectedBoatClass.getPossibleCourseLayoutsWithTargetTime().keySet().contains(selectedCourseLayout)){
|
||||
if (selectedBoatClass.getPossibleCourseLayoutsWithTargetTime().keySet().contains(selectedCourseLayout)) {
|
||||
recomputeCourseDesign();
|
||||
}
|
||||
}
|
||||
@@ -270,10 +285,8 @@ public class ClassicCourseDesignDialogFragment extends RaceDialogFragment {
|
||||
private void setUpMap() {
|
||||
courseAreaMap.clear();
|
||||
DataStore ds = InMemoryDataStore.INSTANCE;
|
||||
if (ds.getLastLatitude() != null && ds.getLastLongitude() != null && ds.getLastWindDirection() != null
|
||||
&& ds.getLastWindSpeed() != null) {
|
||||
courseAreaMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
|
||||
new LatLng(ds.getLastLatitude(), ds.getLastLongitude()), 17.0f));
|
||||
if (ds.getLastWindPosition() != null && ds.getLastWindDirection() != null && ds.getLastWindSpeed() != null) {
|
||||
courseAreaMap.animateCamera(CameraUpdateFactory.newLatLngZoom(ds.getLastWindPosition(), 17.0f));
|
||||
|
||||
Bitmap bmpOriginal = BitmapFactory.decodeResource(this.getResources(), R.drawable.boat);
|
||||
Bitmap bmResult = Bitmap.createBitmap(bmpOriginal.getHeight(), bmpOriginal.getHeight(),
|
||||
@@ -283,12 +296,13 @@ public class ClassicCourseDesignDialogFragment extends RaceDialogFragment {
|
||||
tempCanvas.drawBitmap(bmpOriginal, 0, 0, null);
|
||||
|
||||
courseAreaMap.addMarker(new MarkerOptions()
|
||||
.position(new LatLng(ds.getLastLatitude(), ds.getLastLongitude()))
|
||||
.position(ds.getLastWindPosition())
|
||||
.icon(BitmapDescriptorFactory.fromBitmap(bmResult))
|
||||
.draggable(false)
|
||||
.title(ds.getLastLatitude() + "/" + ds.getLastLongitude() + ", " + ds.getLastWindSpeed() + "kn, "
|
||||
+ ds.getLastWindDirection() + "°"));
|
||||
.title(ds.getLastWindPosition() + ", " + ds.getLastWindSpeed() + "kn, " + ds.getLastWindDirection()
|
||||
+ "°"));
|
||||
}
|
||||
recomputeCourseDesign();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user