Refactoring Tethys

A lot of refactoring of Nilus wrappers with more useful Objects for PAMGUard to work with.
This commit is contained in:
Douglas Gillespie 2024-07-22 16:07:33 +01:00
parent 3abaff0379
commit 4f87b7b661
30 changed files with 553 additions and 118 deletions

View File

@ -6,8 +6,9 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="module" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>

View File

@ -888,7 +888,7 @@
<dependency>
<groupId>tethys.org</groupId>
<artifactId>nilus</artifactId>
<version>3.0</version>
<version>3.1</version>
</dependency>
<dependency>

View File

@ -0,0 +1,4 @@
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
#Tue Jul 16 19:29:56 BST 2024
nilus-3.1.jar>=
nilus-3.1.pom>=

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>tethys.org</groupId>
<artifactId>nilus</artifactId>
<version>3.1</version>
<description>POM was created from install:install-file</description>
</project>

View File

@ -306,6 +306,9 @@ abstract public class PamDialog extends JDialog {
* put the dialog near the mouse location.
*/
public void moveToMouseLocation() {
if (MouseInfo.getPointerInfo() == null) {
return;
}
Point mouse = MouseInfo.getPointerInfo().getLocation();
moveToLocation(mouse);
}

View File

@ -2929,7 +2929,7 @@ InternalFrameListener, DisplayPanelContainer, SpectrogramParametersUser, PamSett
String name = spectrogramDisplay.getDataSelectorName(panelId);
DataSelector dataSelector = usedDataBlock.getDataSelector(name, false);
if (dataSelector.getParams().getCombinationFlag() == DataSelectParams.DATA_SELECT_DISABLE) {
if (dataSelector != null && dataSelector.getParams().getCombinationFlag() == DataSelectParams.DATA_SELECT_DISABLE) {
dataSelector = null;
}
directDrawProjector.setDataSelector(dataSelector);

View File

@ -89,7 +89,7 @@ public enum Collection {
return Calibrations;
case "nilus.Ensemble":
return Ensembles;
case "nilus.Localization":
case "nilus.Localize":
return Localizations;
case "nilus.SpeciesAbbreviation":
return SpeciesAbbreviations;

View File

@ -49,6 +49,7 @@ import tethys.dbxml.TethysException;
import tethys.dbxml.TethysQueryException;
import tethys.deployment.DeploymentHandler;
import tethys.detection.DetectionsHandler;
import tethys.localization.LocalizationHandler;
import tethys.niluswraps.PDeployment;
import tethys.output.DatablockSynchInfo;
import tethys.output.TethysExportParams;
@ -91,6 +92,7 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
private DeploymentHandler deploymentHandler;
private DetectionsHandler detectionsHandler;
private CalibrationHandler calibrationHandler;
private LocalizationHandler localizationHandler;
private ITISFunctions itisFunctions;
@ -102,6 +104,7 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
deploymentHandler = new DeploymentHandler(this);
detectionsHandler = new DetectionsHandler(this);
calibrationHandler = new CalibrationHandler(this);
localizationHandler = new LocalizationHandler(this);
serverCheckTimer = new Timer(10000, new ActionListener() {
@Override
@ -569,8 +572,8 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
int detectionCount = 0;
int documentCount = 0;
for (PDeployment pDepl : matchedDeployments) {
detectionCount += dbxmlQueries.countData(synchInfo.getDataBlock(), pDepl.deployment.getId());
ArrayList<String> detectionsNames = getDbxmlQueries().getDetectionsDocuments(synchInfo.getDataBlock(), pDepl.deployment.getId());
detectionCount += dbxmlQueries.countData(synchInfo.getDataBlock(), pDepl.getDocumentId());
ArrayList<String> detectionsNames = getDbxmlQueries().getDetectionsDocuments(synchInfo.getDataBlock(), pDepl.getDocumentId());
if (detectionsNames != null) {
documentCount += detectionsNames.size();
}

View File

@ -26,14 +26,14 @@ public class TethysMenuActions {
}
public void deploymentMouseActions(MouseEvent e, PDeployment pDeployment) {
ArrayList<String> detDocNames = tethysControl.getDbxmlQueries().getDetectionsDocuments(pDeployment.deployment.getId());
ArrayList<String> detDocNames = tethysControl.getDbxmlQueries().getDetectionsDocuments(pDeployment.nilusObject.getId());
// System.out.println("Detections for deployment " + pDeployment.deployment.getId());
// for (String detName : detDocNames) {
// System.out.println(detName);
// }
JPopupMenu menu = new JPopupMenu();
if (detDocNames.size() == 0) {
JMenuItem menuItem = new JMenuItem("Delete deployment " + pDeployment.deployment.getId());
JMenuItem menuItem = new JMenuItem("Delete deployment " + pDeployment.nilusObject.getId());
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -47,7 +47,7 @@ public class TethysMenuActions {
menu.add(menuItem);
}
else {
String str = String.format("Delete deployment %s and %d Detections documents", pDeployment.deployment.getId(), detDocNames.size());
String str = String.format("Delete deployment %s and %d Detections documents", pDeployment.nilusObject.getId(), detDocNames.size());
JMenuItem menuItem = new JMenuItem(str);
menuItem.addActionListener(new ActionListener() {
@Override
@ -65,6 +65,6 @@ public class TethysMenuActions {
}
protected void deleteDeployment(PDeployment pDeployment) throws TethysException {
tethysControl.getDbxmlConnect().deleteDeployment(pDeployment.deployment.getId());
tethysControl.getDbxmlConnect().deleteDeployment(pDeployment.nilusObject.getId());
}
}

View File

@ -420,10 +420,24 @@ public class CalibrationHandler extends CollectionHandler implements TethysState
calibration.setSensitivityDBFS(fullScale);
}
FrequencyResponse frs = calibration.getFrequencyResponse();
if (frs == null) {
frs = new FrequencyResponse();
try {
Helper.createRequiredElements(frs);
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
}
calibration.setFrequencyResponse(frs);
}
List<Double> hz = frs.getHz();
List<Double> db = frs.getDB();
// if (hz == null) {
//
// }
if (hz != null && db != null) {
hz.add(Double.valueOf(0));
db.add(Double.valueOf(hSens+preampGain));
}
if (NilusChecker.isEmpty(calibration.getResponsibleParty())) {
calibration.setResponsibleParty(null);

View File

@ -515,7 +515,7 @@ C:\Users\dg50\AppData\Local\Temp\PAMGuardTethys\20080311_2DSimplex_0.xmlnot: 0 b
* @param nilusObject
* @return document Id for any type of document, or null if the document doesn't have a getID function
*/
private String getDocumentId(Object nilusObject) {
public static String getDocumentId(Object nilusObject) {
String tempName = null;
Class nilusClass = nilusObject.getClass();
Method getId;

View File

@ -561,6 +561,63 @@ public class DBXMLQueries {
}
return detectionsNames;
}
/**
* Get a list of Localization documents which associate with a datablock and a deploymentId.
* @param dataBlock
* @param deploymentId can be null to get all docs for data block
* @return
*/
public ArrayList<String> getLocalizationDocuments(PamDataBlock dataBlock, String deploymentId) {
/**
* first query for Detections documents associated with this deployment and datablock.
* updated May 23
*/
if (dataBlock == null) {
return null;
}
String queryNoDepl = "{\"species\":{\"query\":{\"op\":\"lib:completename2tsn\",\"optype\":\"function\",\"operands\":[\"%s\"]},\"return\":{\"op\":\"lib:tsn2completename\",\"optype\":\"function\",\"operands\":[\"%s\"]}},\"return\":[\"Localize/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Localize/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}";
String queryWithDepl = "{\"species\":{\"query\":{\"op\":\"lib:completename2tsn\",\"optype\":\"function\",\"operands\":[\"%s\"]},\"return\":{\"op\":\"lib:tsn2completename\",\"optype\":\"function\",\"operands\":[\"%s\"]}},\"return\":[\"Localize/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Localize/DataSource/DeploymentId\",\"TheDeploymentId\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Localize/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}";
String query;
if (deploymentId == null) {
query = queryNoDepl;
}
else {
query = queryWithDepl.replace("TheDeploymentId", deploymentId);
}
query = query.replace("LongDataName", dataBlock.getLongDataName());
DBQueryResult queryResult = null;
try {
queryResult = executeQuery(query);
} catch (TethysQueryException e1) {
tethysControl.showException(e1);
return null;
}
if (queryResult ==null) {
return null;
}
Document doc;
try {
doc = queryResult.getDocument();
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
return null;
}
if (doc == null) {
return null;
}
ArrayList<String> detectionsNames = new ArrayList();
int count = 0;
NodeList returns = doc.getElementsByTagName("Localize");
// if (returns.getLength() == 0) {
// returns = doc.getElementsByTagName("Result");
// }
for (int i = 0; i < returns.getLength(); i++) {
Node aNode = returns.item(i);
String docName = aNode.getTextContent();
detectionsNames.add(docName);
}
return detectionsNames;
}
/**

View File

@ -492,7 +492,7 @@ public class DeploymentHandler extends CollectionHandler implements TethysStateO
PDeployment exDeploymnet = onePeriod.getMatchedTethysDeployment();
try {
if (exDeploymnet != null) {
deployment.setId(exDeploymnet.deployment.getId());
deployment.setId(exDeploymnet.nilusObject.getId());
dbxmlConnect.updateDocument(deployment);
}
else {
@ -522,7 +522,7 @@ public class DeploymentHandler extends CollectionHandler implements TethysStateO
String id = String.format("%s_%d", exportParams.getDatasetName(), i);
if (exDeploymnet != null) {
deployment = createDeploymentDocument(freeId, recordPeriod, id);
deployment.setId(exDeploymnet.deployment.getId());
deployment.setId(exDeploymnet.nilusObject.getId());
}
if (deployment == null) {
deployment = createDeploymentDocument(freeId++, recordPeriod, id);
@ -646,7 +646,7 @@ public class DeploymentHandler extends CollectionHandler implements TethysStateO
}
ArrayList<PInstrument> instruments = new ArrayList<>();
for (PDeployment aDepl : projectDeployments) {
Instrument intr = aDepl.deployment.getInstrument();
Instrument intr = aDepl.nilusObject.getInstrument();
if (intr == null) {
continue;
}
@ -764,7 +764,7 @@ public class DeploymentHandler extends CollectionHandler implements TethysStateO
int firstFree = 0;
if (projectDeployments != null) {
for (PDeployment dep : projectDeployments) {
firstFree = Math.max(firstFree, dep.deployment.getDeploymentId()+1);
firstFree = Math.max(firstFree, dep.nilusObject.getDeploymentId()+1);
}
}
return firstFree;

View File

@ -12,6 +12,8 @@ import javax.xml.datatype.XMLGregorianCalendar;
import PamController.PamControlledUnit;
import PamController.PamController;
import PamController.PamguardVersionInfo;
import PamDetection.LocContents;
import PamDetection.LocalisationInfo;
import PamModel.PamPluginInterface;
import PamUtils.PamCalendar;
import PamView.dialog.PamDialog;
@ -26,6 +28,8 @@ import dataMap.OfflineDataMap;
import dataMap.OfflineDataMapPoint;
import nilus.AlgorithmType;
import nilus.AlgorithmType.SupportSoftware;
import nilus.Localize.Effort;
import nilus.Localize.Effort.CoordinateReferenceSystem;
import nilus.Localize.Localizations;
import nilus.DataSourceType;
import nilus.Deployment;
@ -36,6 +40,7 @@ import nilus.DetectionGroup;
import nilus.Detections;
import nilus.GranularityEnumType;
import nilus.Helper;
import nilus.Localize;
import tethys.Collection;
import tethys.CollectionHandler;
import tethys.TethysControl;
@ -43,6 +48,9 @@ import tethys.TethysTimeFuncs;
import tethys.dbxml.DBXMLConnect;
import tethys.dbxml.TethysException;
import tethys.deployment.DeploymentHandler;
import tethys.localization.CoordinateName;
import tethys.localization.LocalizationSubType;
import tethys.localization.LocalizationType;
import tethys.niluswraps.PDeployment;
import tethys.niluswraps.PDetections;
import tethys.output.StreamExportParams;
@ -87,6 +95,7 @@ public class DetectionsHandler extends CollectionHandler {
*/
public StreamDetectionsSummary getStreamDetections(PamDataBlock dataBlock) {
ArrayList<PDeployment> deployments = tethysControl.getDeploymentHandler().getMatchedDeployments();
// getStreamLocalizations(dataBlock, deployments);
return getStreamDetections(dataBlock, deployments);
}
@ -102,7 +111,7 @@ public class DetectionsHandler extends CollectionHandler {
ArrayList<PDetections> detectionsDocs = new ArrayList<>();
for (PDeployment aDep : deployments) {
ArrayList<String> someNames = tethysControl.getDbxmlQueries().getDetectionsDocuments(dataBlock, aDep.deployment.getId());
ArrayList<String> someNames = tethysControl.getDbxmlQueries().getDetectionsDocuments(dataBlock, aDep.nilusObject.getId());
if (someNames == null) {
continue;
}
@ -117,6 +126,7 @@ public class DetectionsHandler extends CollectionHandler {
return new StreamDetectionsSummary(detectionsDocs);
}
/**
* Get the Detection Effort part of a Detections document
* @param pDeployment
@ -126,12 +136,12 @@ public class DetectionsHandler extends CollectionHandler {
*/
private DetectionEffort getDetectorEffort(PDeployment pDeployment, PamDataBlock dataBlock, StreamExportParams exportParams) {
DetectionEffort effort = new DetectionEffort();
Deployment deployment = pDeployment.deployment;
Deployment deployment = pDeployment.nilusObject;
Long effortStart = pDeployment.getAudioStart();
Long effortEnd = pDeployment.getAudioEnd();
effort.setStart(TethysTimeFuncs.xmlGregCalFromMillis(effortStart));
effort.setEnd(TethysTimeFuncs.xmlGregCalFromMillis(effortEnd));
// effort.set // no setter for DetectionEffortKind
// effort.set // no setter for DetectionEffortKind
List<DetectionEffortKind> effortKinds = effort.getKind();
TethysDataProvider dataProvider = dataBlock.getTethysDataProvider(tethysControl);
@ -202,7 +212,7 @@ public class DetectionsHandler extends CollectionHandler {
* @return PAMGuard version
*/
public String getSupportSoftwareVersion(PamDataBlock dataBlock) {
// should try to dig into the binary store and get the version from there.
// should try to dig into the binary store and get the version from there.
return PamguardVersionInfo.version;
}
@ -284,7 +294,7 @@ public class DetectionsHandler extends CollectionHandler {
TethysExportParams exportParams = tethysControl.getTethysExportParams();
DeploymentHandler depHandler = tethysControl.getDeploymentHandler();
ArrayList<PDeployment> deployments = depHandler.getMatchedDeployments();
// Detections currentDetections = null;
// Detections currentDetections = null;
OfflineDataMap dataMap = dataBlock.getPrimaryDataMap();
DataSelector dataSelector = dataBlock.getDataSelector(tethysControl.getDataSelectName(), false);
int totalCount = dataMap.getDataCount();
@ -353,10 +363,10 @@ public class DetectionsHandler extends CollectionHandler {
exportObserver.update(prog);
}
}
// Detection det = dataProvider.createDetection(dataUnit, exportParams, streamExportParams);
// exportCount++;
// documentCount++;
// onEffort.getDetection().add(det);
// Detection det = dataProvider.createDetection(dataUnit, exportParams, streamExportParams);
// exportCount++;
// documentCount++;
// onEffort.getDetection().add(det);
lastUnitTime = dataUnit.getTimeMilliseconds();
}
doneMapPoints++;
@ -404,8 +414,9 @@ public class DetectionsHandler extends CollectionHandler {
* The main documents for both dets and locs.
*/
Detections detectionsDocument = null;
Localizations localisationsDocument = null;
Localize localiseDocument = null;
DetectionGroup onEffortDetections = null;
Localizations localisations = null;
OfflineDataMap dataMap = dataBlock.getPrimaryDataMap();
DataSelector dataSelector = dataBlock.getDataSelector(tethysControl.getDataSelectName(), false);
@ -432,6 +443,8 @@ public class DetectionsHandler extends CollectionHandler {
exportObserver.update(prog);
granularityHandler.prepare(deployment.getAudioStart());
List<Detection> detectionList;
// export everything in that deployment.
// need to loop through all map points in this interval.
List<OfflineDataMapPoint> mapPoints = dataMap.getMapPoints();
@ -448,12 +461,23 @@ public class DetectionsHandler extends CollectionHandler {
detectionsDocument = startDetectionsDocument(deployment, dataBlock, streamExportParams);
detectionsDocument.getEffort().setStart(TethysTimeFuncs.xmlGregCalFromMillis(deployment.getAudioStart()));
onEffortDetections = detectionsDocument.getOnEffort();
detectionList = onEffortDetections.getDetection();
// if {detectionList == null) {
// onEffortDetections.
// }
}
else {
onEffortDetections = null;
detectionList = null;
}
if (localisationsDocument == null && streamExportParams.exportLocalisations) {
localisationsDocument = startLocalisationDocument(deployment, dataBlock, streamExportParams);
if (localiseDocument == null && streamExportParams.exportLocalisations) {
localiseDocument = startLocalisationDocument(deployment, dataBlock, streamExportParams);
Effort eff = localiseDocument.getEffort();
localiseDocument.getEffort().setStart(TethysTimeFuncs.xmlGregCalFromMillis(deployment.getAudioStart()));
localisations = localiseDocument.getLocalizations();
}
else {
localisations = null;
}
if (mapPoint.getEndTime() < deployment.getAudioStart()) {
@ -476,10 +500,14 @@ public class DetectionsHandler extends CollectionHandler {
exportCount++;
documentCount++;
if (streamExportParams.exportDetections) {
onEffortDetections.getDetection().add(dets[dd]);
detectionList.add(dets[dd]);
}
if (streamExportParams.exportLocalisations) {
// convert the dets into localisations and add them.
}
}
}
if (exportCount % 100 == 0) {
prog = new DetectionExportProgress(deployment, detectionsDocument, totalMapPoints, doneMapPoints,
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_GATHERING);
@ -508,6 +536,17 @@ public class DetectionsHandler extends CollectionHandler {
}
detectionsDocument = null;
}
if (localiseDocument != null) {
closeLocaliseDocument(localiseDocument, mapPoint.getEndTime());
try {
if (checkLocaliseDocument(localiseDocument, granularityHandler)) {
dbxmlConnect.postAndLog(localiseDocument);
}
} catch (TethysException e) {
tethysControl.showException(e);
}
localiseDocument = null;
}
}
if (viewerLoadPolicy == ViewerLoadPolicy.LOAD_ALWAYS_EVERYTHING) {
@ -543,6 +582,27 @@ public class DetectionsHandler extends CollectionHandler {
}
detectionsDocument = null;
}
if (localiseDocument != null) {
Detection dets[] = granularityHandler.cleanup(deployment.getAudioEnd());
if (dets != null) {
for (int dd = 0; dd < dets.length; dd++) {
exportCount++;
documentCount++;
// localiseDocument.getOnEffort().getDetection().add(dets[dd]);
}
}
prog = new DetectionExportProgress(deployment, detectionsDocument,totalMapPoints, doneMapPoints,
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_WRITING);
closeLocaliseDocument(localiseDocument, deployment.getAudioEnd());
try {
if (checkLocaliseDocument(localiseDocument, granularityHandler)) {
dbxmlConnect.postAndLog(localiseDocument);
}
} catch (TethysException e) {
tethysControl.showException(e);
}
localiseDocument = null;
}
}
prog = new DetectionExportProgress(null, null,totalMapPoints, totalMapPoints,
@ -551,20 +611,6 @@ public class DetectionsHandler extends CollectionHandler {
return DetectionExportProgress.STATE_COMPLETE;
}
private Localizations startLocalisationDocument(PDeployment deployment, PamDataBlock dataBlock,
StreamExportParams streamExportParams) {
Localizations localisations = new Localizations();
try {
Helper.createRequiredElements(localisations);
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
return null;
}
return localisations;
}
/**
* Start a new detections document for the deployment and datablock. <br>
* Add all the standard information to the top of the Document
@ -584,7 +630,7 @@ public class DetectionsHandler extends CollectionHandler {
}
TethysDataProvider dataProvider = dataBlock.getTethysDataProvider(tethysControl);
String prefix = deployment.deployment.getId() + "_" + dataProvider.getDetectionsName();
String prefix = deployment.nilusObject.getId() + "_" + dataProvider.getDetectionsName();
String fullId = "";
/*
* Check the document name isn't already used and increment id as necessary.
@ -596,17 +642,17 @@ public class DetectionsHandler extends CollectionHandler {
}
}
detections.setId(fullId);
// detections.setDescription(dataProvider.getDescription(deployment, tethysExportParams));
// detections.setDescription(dataProvider.getDescription(deployment, tethysExportParams));
detections.setDescription(exportParams.getNilusDetectionDescription());
DataSourceType dataSource = new DataSourceType();
dataSource.setDeploymentId(deployment.deployment.getId());
// dataSource.setEnsembleId(""); ToDo
dataSource.setDeploymentId(deployment.nilusObject.getId());
// dataSource.setEnsembleId(""); ToDo
detections.setDataSource(dataSource);
AlgorithmType algorithm = detections.getAlgorithm();
if (dataProvider != null) {
algorithm = dataProvider.getAlgorithm();
// detections.setAlgorithm(algorithm);
// detections.setAlgorithm(algorithm);
}
algorithm.setMethod(getMethodString(dataBlock));
algorithm.setSoftware(getSoftwareString(dataBlock));
@ -624,6 +670,141 @@ public class DetectionsHandler extends CollectionHandler {
return detections;
}
private Localize startLocalisationDocument(PDeployment deployment, PamDataBlock dataBlock,
StreamExportParams exportParams) {
Localize localisations = new Localize();
try {
Helper.createRequiredElements(localisations);
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
return null;
}
if (localisations.getEffort() == null) {
Effort eff = new Effort();
try {
Helper.createRequiredElements(eff);
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
return null;
}
localisations.setEffort(eff);
}
TethysDataProvider dataProvider = dataBlock.getTethysDataProvider(tethysControl);
String prefix = deployment.nilusObject.getId() + "_" + dataProvider.getDetectionsName();
String fullId = "";
/*
* Check the document name isn't already used and increment id as necessary.
*/
while (true) {
fullId = String.format("%s_%d", prefix, uniqueDetectionsId++);
if (!tethysControl.getDbxmlQueries().documentExists(Collection.Localizations.toString(), fullId)) {
break;
}
}
localisations.setId(fullId);
// detections.setDescription(dataProvider.getDescription(deployment, tethysExportParams));
localisations.setDescription(exportParams.getNilusDetectionDescription());
DataSourceType dataSource = new DataSourceType();
dataSource.setDeploymentId(deployment.nilusObject.getId());
// dataSource.setEnsembleId(""); ToDo
localisations.setDataSource(dataSource);
AlgorithmType algorithm = localisations.getAlgorithm();
if (dataProvider != null) {
algorithm = dataProvider.getAlgorithm();
// detections.setAlgorithm(algorithm);
}
algorithm.setMethod(getMethodString(dataBlock));
algorithm.setSoftware(getSoftwareString(dataBlock));
algorithm.setVersion(getVersionString(dataBlock));
List<SupportSoftware> supSoft = algorithm.getSupportSoftware();
SupportSoftware supportSoft = new SupportSoftware();
supportSoft.setSoftware(getSupportSoftware(dataBlock));
supportSoft.setVersion(getSupportSoftwareVersion(dataBlock));
supSoft.add(supportSoft);
localisations.setAlgorithm(algorithm);
localisations.setUserId("PAMGuard user");
// localisations.setEffort(getLocaliserEffort(deployment, dataBlock, exportParams));
sortLocaliseCoordinates(dataBlock, localisations);
// sort out coordinate system.
return localisations;
}
private boolean sortLocaliseCoordinates(PamDataBlock dataBlock, Localize localisations) {
LocalisationInfo locInfo = dataBlock.getLocalisationContents();
Effort locEffort = localisations.getEffort();
if (locEffort == null) {
locEffort = new Effort();
localisations.setEffort(locEffort);
}
try {
Helper.createRequiredElements(locEffort);
} catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
return false;
}
locEffort.setTimeReference("relative");
// List<String> locTypes = locEffort.getLocalizationType();
boolean ambiguity = locInfo.hasLocContent(LocContents.HAS_AMBIGUITY);
CoordinateReferenceSystem coordRefs = locEffort.getCoordinateReferenceSystem();
if (locInfo.getLocContent() == 0) {
return false;
}
else if (locInfo.hasLocContent(LocContents.HAS_LATLONG)) {
coordRefs.setName(CoordinateName.WGS84.toString());
coordRefs.setSubtype(LocalizationSubType.Geographic.toString());
locEffort.setLocalizationType(LocalizationType.Point.toString());
// locEffort.set
if (locInfo.hasLocContent(LocContents.HAS_DEPTH)) {
locEffort.setDimension(3);
}
else {
locEffort.setDimension(2);
}
// locEffort.set
}
else if (locInfo.hasLocContent(LocContents.HAS_XYZ)) {
coordRefs.setName(CoordinateName.Cartesian.toString());
coordRefs.setSubtype(LocalizationSubType.Engineering.toString());
locEffort.setLocalizationType(LocalizationType.Point.toString());
locEffort.setDimension(3);
}
else if (locInfo.hasLocContent(LocContents.HAS_XY)) {
coordRefs.setName(CoordinateName.Cartesian.toString());
coordRefs.setSubtype(LocalizationSubType.Engineering.toString());
locEffort.setLocalizationType(LocalizationType.Point.toString());
locEffort.setDimension(2);
}
else if (locInfo.hasLocContent(LocContents.HAS_BEARING)) {
coordRefs.setName(CoordinateName.Polar.toString());
coordRefs.setSubtype(LocalizationSubType.Engineering.toString());
locEffort.setLocalizationType(LocalizationType.Bearing.toString());
if (ambiguity) {
locEffort.setDimension(1);
}
else {
locEffort.setDimension(2);
}
}
else {
return false;
}
return true;
}
private nilus.Localize.Effort getLocaliserEffort(PDeployment deployment, PamDataBlock dataBlock, StreamExportParams exportParams) {
// TODO Auto-generated method stub
return null;
}
/**
* Close a detections document. This basically just means rewriting the end time and it's only
* important in the event that a document got too big and has to be restarted.
@ -634,6 +815,11 @@ public class DetectionsHandler extends CollectionHandler {
detections.getEffort().setEnd(TethysTimeFuncs.xmlGregCalFromMillis(audioEnd));
}
private void closeLocaliseDocument(Localize localiseDocument, long endTime) {
localiseDocument.getEffort().setEnd(TethysTimeFuncs.xmlGregCalFromMillis(endTime));
}
/**
* Run some checks on the Detections document prior to submission. <br>
* Currently, is is just a check that the detections are within the effort times.
@ -678,6 +864,11 @@ public class DetectionsHandler extends CollectionHandler {
return true;
}
private boolean checkLocaliseDocument(Localize localiseDocument, GranularityHandler granularityHandler) {
// TODO Auto-generated method stub
return true;
}
/**
* Worker thread for exporting detections.
* Currently, it counts them first, then checks the user wants to export
@ -709,16 +900,16 @@ public class DetectionsHandler extends CollectionHandler {
protected Integer doInBackground() throws Exception {
Integer ans = null;
try {
// int count = countDetections(dataBlock, exportParams, exportObserver);
// if (activeExport == false) {
// return 0;
// }
// String msg = String.format("Do you want to go ahead and output %d %s detections to Tethys?",
// count, exportParams.granularity);
// int doit = WarnOnce.showWarning("Tethys Detections Export", msg, WarnOnce.OK_CANCEL_OPTION);
// if (doit == WarnOnce.OK_OPTION) {
ans = exportDetections(dataBlock, exportParams, this);
// }
// int count = countDetections(dataBlock, exportParams, exportObserver);
// if (activeExport == false) {
// return 0;
// }
// String msg = String.format("Do you want to go ahead and output %d %s detections to Tethys?",
// count, exportParams.granularity);
// int doit = WarnOnce.showWarning("Tethys Detections Export", msg, WarnOnce.OK_CANCEL_OPTION);
// if (doit == WarnOnce.OK_OPTION) {
ans = exportDetections(dataBlock, exportParams, this);
// }
}
catch (Exception e) {
e.printStackTrace();
@ -728,7 +919,7 @@ public class DetectionsHandler extends CollectionHandler {
@Override
protected void done() {
// this.
// this.
DetectionExportProgress prog = new DetectionExportProgress(null, null, 0, 0, 0, 0, 0, 0, DetectionExportProgress.STATE_COMPLETE);
tethysControl.exportedDetections(dataBlock);
exportObserver.update(prog);

View File

@ -0,0 +1,11 @@
package tethys.localization;
/**
* Enumeration of the Name field in nilus.Localize.Effort.CoordinateReferenceSystem<br>
* Within Tethys, these are only ever used in their String form.
* @author dg50
*
*/
public enum CoordinateName {
WGS84, UTM, Cartesian, Polar, Spherical, Cylindrical, Range, PerpindicularRange;
}

View File

@ -1,17 +1,63 @@
package tethys.localization;
import java.util.ArrayList;
import PamguardMVC.PamDataBlock;
import nilus.CylindricalCoordinateType;
import nilus.LocalizationType;
import nilus.Localize.Effort.CoordinateReferenceSystem;
import tethys.Collection;
import tethys.CollectionHandler;
import tethys.TethysControl;
import tethys.detection.StreamDetectionsSummary;
import tethys.niluswraps.PDeployment;
public class LocalizationHandler {
public class LocalizationHandler extends CollectionHandler {
public LocalizationHandler(TethysControl tethysControl) {
super(tethysControl, Collection.Localizations);
// TODO Auto-generated constructor stub
}
public LocalizationType getLoc() {
LocalizationType lt = new LocalizationType();
CylindricalCoordinateType cct = new CylindricalCoordinateType();
// cct.set
CoordinateReferenceSystem cr;
// public LocalizationType getLoc() {
// LocalizationType lt = new LocalizationType();
// CylindricalCoordinateType cct = new CylindricalCoordinateType();
//// cct.set
// CoordinateReferenceSystem cr;
// return null;
// }
/**
* Get a list of Localization documents associated with a particular data block for the list of deployments
* documents. Group them by abstract or something
* @param dataBlock
* @param deployments
* @return
*/
public StreamDetectionsSummary getStreamLocalizations(PamDataBlock dataBlock, ArrayList<PDeployment> deployments) {
// get the basic data for each document including it's Description.
// ArrayList<PDetections> detectionsDocs = new ArrayList<>();
for (PDeployment aDep : deployments) {
ArrayList<String> someNames = tethysControl.getDbxmlQueries().getLocalizationDocuments(dataBlock, aDep.getDocumentId());
if (someNames == null) {
continue;
}
// // no have a list of all the Detections documents of interest for this datablock.
// for (String aDoc : someNames) {
// Detections detections = tethysControl.getDbxmlQueries().getDetectionsDocInfo(aDoc);
// int count = tethysControl.getDbxmlQueries().countDetections2(aDoc);
// PDetections pDetections = new PDetections(detections, dataBlock, aDep, count);
// detectionsDocs.add(pDetections);
// }
}
// return new StreamDetectionsSummary(detectionsDocs);
return null;
}
@Override
public String getHelpPoint() {
// TODO Auto-generated method stub
return null;
}
}

View File

@ -0,0 +1,10 @@
package tethys.localization;
/**
* Enumeration of the ReferenceFrame field in nilus.Localize.Effort.CoordinateReferenceSystem.Subtype <br>
* Within Tethys, these are only ever used in their String form.
* @author dg50
*
*/
public enum LocalizationSubType {
Geographic, Derived, Engineering;
}

View File

@ -0,0 +1,11 @@
package tethys.localization;
/**
* Enumeration of the ReferenceFrame field in nilus.Localize.Effort.CoordinateReferenceSystem.Subtype <br>
* Within Tethys, these are only ever used in their String form.
* @author dg50
*
*/
public enum LocalizationType {
Bearing, PerpindicularRange, Point, Range, Track;
}

View File

@ -0,0 +1,11 @@
package tethys.localization;
/**
* Enumeration of the ReferenceFrame field in nilus.Localize.Effort.CoordinateReferenceSystem <br>
* Within Tethys, these are only ever used in their String form.
* @author dg50
*
*/
public enum ReferenceFrame {
UTMZone, WGS84, instrument;
}

View File

@ -0,0 +1,10 @@
package tethys.localization;
/**
* Enumeration of the ReferenceFrame field in nilus.Localize.Effort.TimeReference <br>
* Within Tethys, these are only ever used in their String form.
* @author dg50
*
*/
public enum TimeReference {
absolute, channel, relative;
}

View File

@ -0,0 +1,27 @@
package tethys.niluswraps;
import PamguardMVC.PamDataBlock;
/**
* Wrapper for Nilus data objects. This means Detections and Localization documents which
* should have an associated datablock, a deployment wrapper and a data count.
* @author dg50
*
* @param <T>
*/
public class NilusDataWrapper<T> extends NilusDocumentWrapper<T> {
public Integer count;
public PDeployment deployment;
public PamDataBlock dataBlock;
public NilusDataWrapper(T nilusObject, PamDataBlock dataBlock, PDeployment deployment, Integer count) {
super(nilusObject);
this.dataBlock = dataBlock;
this.deployment = deployment;
this.count = count;
}
}

View File

@ -0,0 +1,24 @@
package tethys.niluswraps;
import PamguardMVC.PamDataBlock;
import tethys.dbxml.DBXMLConnect;
public class NilusDocumentWrapper<T> {
public T nilusObject;
public String documentName;
public NilusDocumentWrapper(T nilusDocument) {
super();
this.nilusObject = nilusDocument;
}
public String getDocumentId() {
if (nilusObject == null) {
return null;
}
return DBXMLConnect.getDocumentId(nilusObject);
}
}

View File

@ -12,18 +12,16 @@ import tethys.deployment.RecordingPeriod;
* @author dg50
*
*/
public class PDeployment {
public class PDeployment extends NilusDocumentWrapper<Deployment>{
public Deployment deployment;
private RecordingPeriod matchedPAMGaurdPeriod;
public PDeployment(Deployment deployment) {
super();
this.deployment = deployment;
super(deployment);
}
public Long getAudioStart() {
DeploymentRecoveryDetails detail = deployment.getDeploymentDetails();
DeploymentRecoveryDetails detail = nilusObject.getDeploymentDetails();
if (detail == null || detail.getAudioTimeStamp() == null) {
return null;
}
@ -31,7 +29,7 @@ public class PDeployment {
}
public Long getAudioEnd() {
DeploymentRecoveryDetails detail = deployment.getRecoveryDetails();
DeploymentRecoveryDetails detail = nilusObject.getRecoveryDetails();
if (detail == null || detail.getAudioTimeStamp() == null) {
return null;
}
@ -40,7 +38,7 @@ public class PDeployment {
@Override
public String toString() {
return String.format("%s:%d; %s - %s", deployment.getId(), deployment.getDeploymentId(),
return String.format("%s:%d; %s - %s", nilusObject.getId(), nilusObject.getDeploymentId(),
PamCalendar.formatDBDateTime(getAudioStart()), PamCalendar.formatDBDateTime(getAudioEnd()));
}
@ -55,10 +53,10 @@ public class PDeployment {
public String getShortDescription() {
Long audioStart = getAudioStart();
if (audioStart == null) {
return String.format("%s %s", deployment.getId(), "unknown start");
return String.format("%s %s", nilusObject.getId(), "unknown start");
}
else {
return String.format("%s %s", deployment.getId(), PamCalendar.formatDBDate(getAudioStart()));
return String.format("%s %s", nilusObject.getId(), PamCalendar.formatDBDate(getAudioStart()));
}
}

View File

@ -3,24 +3,29 @@ package tethys.niluswraps;
import PamguardMVC.PamDataBlock;
import nilus.Detections;
public class PDetections {
public Detections detections;
public Integer count;
public PDeployment deployment;
public PamDataBlock dataBlock;
public class PDetections extends NilusDataWrapper<Detections>{
public PDetections(Detections detections, PamDataBlock dataBlock, PDeployment deployment, Integer count) {
super();
this.dataBlock = dataBlock;
this.detections = detections;
this.deployment = deployment;
this.count = count;
super(detections, dataBlock, deployment, count);
// TODO Auto-generated constructor stub
}
// public Detections nilusObject;
//
// public Integer count;
//
// public PDeployment deployment;
//
// public PamDataBlock dataBlock;
//
// public PDetections(Detections detections, PamDataBlock dataBlock, PDeployment deployment, Integer count) {
// super();
// this.dataBlock = dataBlock;
// this.nilusObject = detections;
// this.deployment = deployment;
// this.count = count;
// }

View File

@ -62,7 +62,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
public DatablockDetectionsPanel(TethysControl tethysControl) {
super(tethysControl);
mainPanel = new JPanel(new BorderLayout());
mainPanel.add(BorderLayout.NORTH, dataBlockName = new JLabel("PAMGUard data stream", JLabel.LEFT));
mainPanel.add(BorderLayout.NORTH, dataBlockName = new JLabel("PAMGuard data stream", JLabel.LEFT));
mainPanel.setBorder(new TitledBorder("Data stream Tethys Detections documents"));
tableModel = new TableModel();
@ -193,7 +193,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
JMenuItem menuItem;
if (rows.length == 1) {
menuItem = new JMenuItem("Display document " + pDets.detections.getId());
menuItem = new JMenuItem("Display document " + pDets.getDocumentId());
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -202,7 +202,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
});
popMenu.add(menuItem);
menuItem = new JMenuItem("Export document " + pDets.detections.getId());
menuItem = new JMenuItem("Export document " + pDets.getDocumentId());
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -212,7 +212,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
popMenu.add(menuItem);
popMenu.addSeparator();
menuItem = new JMenuItem("Delete document " + pDets.detections.getId());
menuItem = new JMenuItem("Delete document " + pDets.getDocumentId());
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -255,7 +255,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
if (pDets == null) {
continue;
}
toDelete.add(pDets.detections);
toDelete.add(pDets.nilusObject);
}
DeleteDocs dd = new DeleteDocs(toDelete);
PamWorker<Integer> worker = new PamWorker(dd, getTethysControl().getGuiFrame(), 1, "Deleting Detections documents");
@ -293,13 +293,13 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
}
protected void deleteDocument(PDetections pDets) {
String msg = String.format("Are you sure you want to delete the Detections document %s ?", pDets.detections.getId());
String msg = String.format("Are you sure you want to delete the Detections document %s ?", pDets.getDocumentId());
int ans = WarnOnce.showWarning(PamGui.findComponentWindow(mainPanel), "Delete Document", msg, WarnOnce.OK_CANCEL_OPTION);
if (ans != WarnOnce.OK_OPTION) {
return;
}
try {
getTethysControl().getDbxmlConnect().deleteDocument(pDets.detections);
getTethysControl().getDbxmlConnect().deleteDocument(pDets.nilusObject);
} catch (TethysException e) {
getTethysControl().showException(e);
}
@ -308,12 +308,12 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
}
private void displayDocument(PDetections pDets) {
getTethysControl().displayDocument(Collection.Detections.collectionName(), pDets.detections.getId());
getTethysControl().displayDocument(Collection.Detections.collectionName(), pDets.getDocumentId());
}
private void exportDocument(PDetections pDets) {
getTethysControl().exportDocument(Collection.Detections.toString(), pDets.detections.getId());
getTethysControl().exportDocument(Collection.Detections.toString(), pDets.getDocumentId());
}
@ -359,7 +359,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
if (pDets == null) {
return null;
}
Detections dets = pDets.detections;
Detections dets = pDets.nilusObject;
if (dets == null) {
return "Error in doc";
}

View File

@ -124,10 +124,10 @@ public class DeploymentExportPanel extends TethysGUIPanel implements DeploymentT
return;
}
PDeployment deployment = tethysDeploys.get(row);
String msg = "Do you want to copy settings from deploymnet document " + deployment.deployment.getId();
String msg = "Do you want to copy settings from deploymnet document " + deployment.nilusObject.getId();
int ans = WarnOnce.showWarning("Deployment data", msg, WarnOnce.OK_CANCEL_OPTION);
if (ans == WarnOnce.OK_OPTION) {
copyDeploymentData(deployment.deployment);
copyDeploymentData(deployment.nilusObject);
}
}

View File

@ -229,14 +229,14 @@ private RecordingList masterList;
return;
}
for (PDeployment depl : matchedDeployments) {
if (depl.deployment == null) {
if (depl.nilusObject == null) {
continue;
}
try {
if (checkDetections(depl.deployment) == false) {
if (checkDetections(depl.nilusObject) == false) {
continue;
}
boolean gone = getTethysControl().getDbxmlConnect().deleteDocument(depl.deployment);
boolean gone = getTethysControl().getDbxmlConnect().deleteDocument(depl.nilusObject);
} catch (TethysException e) {
getTethysControl().showException(e);
}
@ -279,7 +279,7 @@ private RecordingList masterList;
}
protected void deleteDeployment(PDeployment pDeployment) {
Deployment dep = pDeployment.deployment;
Deployment dep = pDeployment.nilusObject;
if (dep == null) {
return;
}
@ -300,11 +300,11 @@ private RecordingList masterList;
}
protected void exportDeployment(PDeployment pDeployment) {
getTethysControl().exportDocument(Collection.Deployments.collectionName(), pDeployment.deployment.getId());
getTethysControl().exportDocument(Collection.Deployments.collectionName(), pDeployment.nilusObject.getId());
}
protected void displayDeployment(PDeployment pDeployment) {
getTethysControl().displayDocument(Collection.Deployments.collectionName(), pDeployment.deployment.getId());
getTethysControl().displayDocument(Collection.Deployments.collectionName(), pDeployment.nilusObject.getId());
}
@Override
@ -443,7 +443,7 @@ private RecordingList masterList;
if (deployment == null) {
return null;
}
return deployment.deployment.getId();
return deployment.nilusObject.getId();
// return makeDeplString(period, deployment);
case 8:
if (deployment == null) {

View File

@ -226,7 +226,7 @@ public class TethysConnectionPanel extends TethysGUIPanel {
*/
ArrayList<PDeployment> projectDeployments = getTethysControl().getDeploymentHandler().getProjectDeployments();
if (projectDeployments != null && projectDeployments.size() > 0) {
Deployment dep = projectDeployments.get(0).deployment;
Deployment dep = projectDeployments.get(0).nilusObject;
globDeployment.setProject(dep.getProject());
globDeployment.setRegion(dep.getRegion());
getTethysControl().sendStateUpdate(new TethysState(TethysState.StateType.NEWPROJECTSELECTION));