Deployment positions

This commit is contained in:
Douglas Gillespie 2023-03-13 21:44:19 +00:00
parent 98cf904830
commit 501c0ec292
2 changed files with 124 additions and 0 deletions

View File

@ -552,6 +552,71 @@ public abstract class SQLLogging {
return resultSet; return resultSet;
} }
/**
* Find the data point which is closest in time to that given, or null
* returning whatever type of data unit this deals with.
* @param timeMillis
* @return
*/
public PamDataUnit findClosestDataPoint(PamConnection con, long timeMillis) {
PamCursor pamCursor = loggingCursorFinder.getCursor(con, pamTableDefinition);
// can't really do any math with the string based dates, so will have to query from
// a few s before the time we want.
PamDataUnit[] beforeNafter = new PamDataUnit[2];
SQLTypes sqlTypes = con.getSqlTypes();
for (int i = 0; i < 2; i++) {
String clause;
if (i == 0) {
clause = String.format("WHERE UTC <= %s ORDER BY UTC DESC", sqlTypes.formatDBDateTimeQueryString(timeMillis));
}
else {
clause = String.format("WHERE UTC >= %s ORDER BY UTC ASC", sqlTypes.formatDBDateTimeQueryString(timeMillis));
}
ResultSet result = pamCursor.openReadOnlyCursor(con, clause);
if (result==null) {
return null;
}
PamTableItem tableItem;
try {
if (result.next()) {
// for (int i = 0; i < pamTableDefinition.getTableItemCount(); i++) {
// tableItem = pamTableDefinition.getTableItem(i);
// tableItem.setValue(result.getObject(i + 1));
// }
// return true;
boolean ok = transferDataFromResult(con.getSqlTypes(), result);
result.close();
beforeNafter[i] = createDataUnit(sqlTypes, lastTime, lastLoadIndex);
}
} catch (SQLException ex) {
ex.printStackTrace();
continue;
}
}
// now pick the closest
if (beforeNafter[0] == null) {
return beforeNafter[1];
}
if (beforeNafter[1] == null) {
return beforeNafter[0];
}
long t1 = timeMillis-beforeNafter[0].getTimeMilliseconds();
long t2 = beforeNafter[1].getTimeMilliseconds()-timeMillis;
if (t1 < t2) {
return beforeNafter[0];
}
else {
return beforeNafter[1];
}
}
/** /**
* Called when a new database is connected to read the last values back in * Called when a new database is connected to read the last values back in
* from the database. * from the database.

View File

@ -1,7 +1,19 @@
package tethys; package tethys;
import Array.ArrayManager;
import Array.HydrophoneLocator;
import Array.PamArray;
import Array.Streamer;
import GPS.GPSControl;
import GPS.GpsData; import GPS.GpsData;
import GPS.GpsDataUnit;
import PamUtils.LatLong;
import PamUtils.PamUtils;
import PamguardMVC.PamDataUnit;
import generalDatabase.DBControlUnit;
import generalDatabase.PamConnection;
import nilus.Deployment; import nilus.Deployment;
import nilus.DeploymentRecoveryDetails;
/** /**
* Function(s) to get location information for Tethys in the required format. * Function(s) to get location information for Tethys in the required format.
@ -21,6 +33,53 @@ public class TethysLocationFuncs {
*/ */
public static void getTrackAndPositionData(Deployment deployment) { public static void getTrackAndPositionData(Deployment deployment) {
long start = TethysTimeFuncs.millisFromGregorianXML(deployment.getDeploymentDetails().getAudioTimeStamp()); long start = TethysTimeFuncs.millisFromGregorianXML(deployment.getDeploymentDetails().getAudioTimeStamp());
long end = TethysTimeFuncs.millisFromGregorianXML(deployment.getRecoveryDetails().getAudioTimeStamp());
/*
* Need to load data for GPS, Hydrophones and Streamers datablocks for this time period. Can then use
* the snapshot geomentry classes to do the rest from the array manager ?
*/
boolean ok = true;
ok &= addPositionData(deployment.getDeploymentDetails());
ok &= addPositionData(deployment.getRecoveryDetails());
}
/**
* Add position data to DeploymentRecoveryDetails.
* @param drd
* @return
*/
public static boolean addPositionData(DeploymentRecoveryDetails drd) {
long timeMillis = TethysTimeFuncs.millisFromGregorianXML(drd.getAudioTimeStamp());
LatLong pos = getLatLongData(timeMillis);
if (pos == null) {
return false;
}
drd.setLongitude(PamUtils.constrainedAngle(pos.getLongitude(), 360));
drd.setLatitude(pos.getLatitude());
drd.setElevationInstrumentM(pos.getHeight());
drd.setDepthInstrumentM(-pos.getHeight());
return true;
}
public static LatLong getLatLongData(long timeMillis) {
// check the array time.
PamArray array = ArrayManager.getArrayManager().getCurrentArray();
Streamer aStreamer = array.getStreamer(0);
GPSControl gpsControl = GPSControl.getGpsControl();
PamConnection con = DBControlUnit.findConnection();
if (gpsControl != null) {
// check GPS data are loaded for times around this.
GpsDataUnit gpsData = (GpsDataUnit) gpsControl.getGpsDataBlock().getLogging().findClosestDataPoint(con, timeMillis);
if (gpsData != null) {
return gpsData.getGpsData();
}
}
HydrophoneLocator hydrophoneLocator = aStreamer.getHydrophoneLocator();
if (hydrophoneLocator == null) {
return null;
}
return hydrophoneLocator.getStreamerLatLong(timeMillis);
} }
} }