mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-22 07:02:29 +00:00
Data export
A few fixes in Detections export.
This commit is contained in:
parent
3688719e25
commit
fb00a757cd
@ -163,8 +163,9 @@ public class DBXMLConnect {
|
||||
* Quite hard to see much common structure in this, so just look for
|
||||
* two words, <Success> and <Error>
|
||||
*/
|
||||
boolean error = importReturn.contains("<Error>");
|
||||
boolean error = importReturn.contains("<Error");
|
||||
boolean success = importReturn.contains("<Success>");
|
||||
// error = !success; might be a better options.
|
||||
if (error) {
|
||||
throw new TethysException("Error posting to Tethys", importReturn);
|
||||
}
|
||||
|
@ -262,30 +262,19 @@ public class DetectionsHandler {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
private DetectionEffort getDetectorEffort(Deployment deployment, long effortStart, long effortEnd) {
|
||||
private DetectionEffort getDetectorEffort(PDeployment pDeployment, PamDataBlock dataBlock, StreamExportParams exportParams) {
|
||||
DetectionEffort effort = new DetectionEffort();
|
||||
Deployment deployment = pDeployment.deployment;
|
||||
Long effortStart = pDeployment.getAudioStart();
|
||||
Long effortEnd = pDeployment.getAudioEnd();
|
||||
effort.setStart(TethysTimeFuncs.xmlGregCalFromMillis(effortStart));
|
||||
effort.setEnd(TethysTimeFuncs.xmlGregCalFromMillis(effortEnd));
|
||||
// effort.set // no setter for DetectionEffortKind
|
||||
List<DetectionEffortKind> effortKinds = effort.getKind();
|
||||
DetectionEffortKind kind = new DetectionEffortKind();
|
||||
try {
|
||||
nilus.Helper.createRequiredElements(kind);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
kind.getSpeciesId().setValue(BigInteger.valueOf(180537));
|
||||
kind.getGranularity().setValue(nilus.GranularityEnumType.CALL);
|
||||
TethysDataProvider dataProvider = dataBlock.getTethysDataProvider();
|
||||
dataProvider.getEffortKinds(pDeployment, effortKinds, exportParams);
|
||||
|
||||
effortKinds.add(kind);
|
||||
|
||||
return effort;
|
||||
}
|
||||
@ -508,7 +497,7 @@ public class DetectionsHandler {
|
||||
supSoft.add(supportSoft);
|
||||
detections.setAlgorithm(algorithm);
|
||||
detections.setUserId("Unknown user");
|
||||
detections.setEffort(getDetectorEffort(deployment.deployment, deployment.getAudioStart(), deployment.getAudioEnd()));
|
||||
detections.setEffort(getDetectorEffort(deployment, dataBlock, exportParams));
|
||||
|
||||
return detections;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package tethys.pamdata;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
@ -26,12 +27,15 @@ import nilus.AlgorithmType.Parameters;
|
||||
import nilus.Deployment;
|
||||
import nilus.DescriptionType;
|
||||
import nilus.Detection;
|
||||
import nilus.DetectionEffortKind;
|
||||
import nilus.SpeciesIDType;
|
||||
import tethys.TethysControl;
|
||||
import tethys.TethysTimeFuncs;
|
||||
import tethys.niluswraps.PDeployment;
|
||||
import tethys.output.StreamExportParams;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.species.DataBlockSpeciesManager;
|
||||
import tethys.species.DataBlockSpeciesMap;
|
||||
import tethys.species.ITISTypes;
|
||||
import tethys.species.SpeciesMapItem;
|
||||
import whistleClassifier.WhistleContour;
|
||||
@ -136,7 +140,7 @@ public class AutoTethysProvider implements TethysDataProvider {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<Element> genList = paramPacker.packParameters(settings);
|
||||
List<Element> genList = paramPacker.packParameters(pamControlledUnit);
|
||||
if (genList == null || genList.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
@ -389,4 +393,45 @@ public class AutoTethysProvider implements TethysDataProvider {
|
||||
return species;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getEffortKinds(PDeployment pDeployment, List<DetectionEffortKind> effortKinds, StreamExportParams exportParams) {
|
||||
|
||||
DataBlockSpeciesManager speciesManager = pamDataBlock.getDatablockSpeciesManager();
|
||||
if (speciesManager == null) {
|
||||
return;
|
||||
}
|
||||
DataBlockSpeciesMap speciesMap = speciesManager.getDatablockSpeciesMap();
|
||||
ArrayList<String> speciesCodes = speciesManager.getAllSpeciesCodes();
|
||||
if (speciesCodes == null || speciesMap == null) {
|
||||
return;
|
||||
}
|
||||
for (String speciesCode : speciesCodes) {
|
||||
|
||||
SpeciesMapItem mapItem = speciesMap.getItem(speciesCode);
|
||||
|
||||
DetectionEffortKind kind = new DetectionEffortKind();
|
||||
try {
|
||||
nilus.Helper.createRequiredElements(kind);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
kind.getSpeciesId().setValue(BigInteger.valueOf(mapItem.getItisCode()));
|
||||
kind.getGranularity().setValue(exportParams.granularity);
|
||||
kind.setCall(mapItem.getCallType());
|
||||
|
||||
|
||||
effortKinds.add(kind);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package tethys.pamdata;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import PamguardMVC.PamDataUnit;
|
||||
import nilus.AlgorithmType;
|
||||
import nilus.AlgorithmType.Parameters;
|
||||
import nilus.Deployment;
|
||||
import nilus.DescriptionType;
|
||||
import nilus.Detection;
|
||||
import nilus.DetectionEffortKind;
|
||||
import tethys.niluswraps.PDeployment;
|
||||
import tethys.output.StreamExportParams;
|
||||
import tethys.output.TethysExportParams;
|
||||
|
||||
@ -65,7 +69,22 @@ public interface TethysDataProvider {
|
||||
StreamExportParams streamExportParams);
|
||||
|
||||
|
||||
/**
|
||||
* Get the algorithm parameters.
|
||||
* @return
|
||||
*/
|
||||
public Parameters getAlgorithmParameters();
|
||||
|
||||
|
||||
/**
|
||||
* Fill in the effort kind list for the top of a Detections document. This must contain a list
|
||||
* of every species that's going to be output within this effort period. Any species assigned
|
||||
* to an actual detection must be in this list, or the document will be rejected.
|
||||
* @param pDeployment
|
||||
* @param effortKinds tethys object list to add to.
|
||||
* @param exportParams
|
||||
*/
|
||||
public void getEffortKinds(PDeployment pDeployment, List<DetectionEffortKind> effortKinds, StreamExportParams exportParams);
|
||||
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ import javax.xml.transform.dom.DOMResult;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import PamController.PamControlledUnit;
|
||||
import PamController.PamSettings;
|
||||
import PamController.settings.output.xml.PamguardXMLWriter;
|
||||
import PamModel.parametermanager.ManagedParameters;
|
||||
import PamModel.parametermanager.PamParameterData;
|
||||
@ -68,6 +70,8 @@ public class TethysParameterPacker {
|
||||
|
||||
private MarshalXML marshaller;
|
||||
|
||||
private PamguardXMLWriter xmlWriter;
|
||||
|
||||
/**
|
||||
* @throws JAXBException
|
||||
*
|
||||
@ -78,11 +82,20 @@ public class TethysParameterPacker {
|
||||
marshaller = new MarshalXML();
|
||||
} catch (JAXBException e) {
|
||||
}
|
||||
xmlWriter = PamguardXMLWriter.getXMLWriter();
|
||||
}
|
||||
|
||||
|
||||
public List<Element> packParameters(Object data) {
|
||||
public List<Element> packParameters(PamControlledUnit pamControlledUnit) {
|
||||
if (pamControlledUnit instanceof PamSettings == false) {
|
||||
return null;
|
||||
}
|
||||
PamSettings pamSettings = (PamSettings) pamControlledUnit;
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// public List<Element> packParameters(Object data) {
|
||||
List<Element> elList = new ArrayList<Element>();
|
||||
Object data = pamSettings.getSettingsReference();
|
||||
|
||||
ArrayList<Object> objectHierarchy = new ArrayList<>();
|
||||
|
||||
@ -121,15 +134,16 @@ public class TethysParameterPacker {
|
||||
try {
|
||||
Object paramData = pamParam.getData();
|
||||
boolean ok = createElement(doc, el, paramData, pamParam, objectHierarchy);
|
||||
// if (newEl != null) {
|
||||
// elList.add(newEl);
|
||||
// }
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
elList.add(el);
|
||||
Element pgEl = xmlWriter.writeUnitSettings(doc, el, pamSettings);
|
||||
if (pgEl != null) {
|
||||
el.appendChild(pgEl);
|
||||
// elList.add(pgEl);
|
||||
}
|
||||
return elList;
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import tethys.TethysControl;
|
||||
import tethys.dbxml.TethysException;
|
||||
import tethys.detection.StreamDetectionsSummary;
|
||||
import tethys.niluswraps.PDetections;
|
||||
import tethys.niluswraps.TethysCollections;
|
||||
|
||||
/**
|
||||
* Table of Detections documents for a single PAMGuard datablock.
|
||||
@ -104,6 +105,8 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
return;
|
||||
}
|
||||
|
||||
JPopupMenu popMenu = new JPopupMenu();
|
||||
|
||||
JMenuItem menuItem = new JMenuItem("Delete " + pDets.detections.getId());
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@ -111,8 +114,19 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
deleteDocument(pDets);
|
||||
}
|
||||
});
|
||||
JPopupMenu popMenu = new JPopupMenu();
|
||||
popMenu.add(menuItem);
|
||||
|
||||
menuItem = new JMenuItem("Display " + pDets.detections.getId());
|
||||
menuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
displayDocument(pDets);
|
||||
}
|
||||
});
|
||||
popMenu.add(menuItem);
|
||||
|
||||
|
||||
|
||||
popMenu.show(e.getComponent(), e.getX(), e.getY());
|
||||
|
||||
}
|
||||
@ -126,6 +140,11 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
selectDataBlock(dataBlock); // force table update.
|
||||
}
|
||||
|
||||
private void displayDocument(PDetections pDets) {
|
||||
getTethysControl().displayDocument(TethysCollections.Detections.toString(), pDets.detections.getId());
|
||||
|
||||
}
|
||||
|
||||
private PDetections detectionsForRow(int iRow) {
|
||||
if (streamDetectionsSummary == null || streamDetectionsSummary.detectionsDocs == null) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user