mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-25 08:32:32 +00:00
More output
More changes to Detections output.
This commit is contained in:
parent
85fd84d18a
commit
db1cc75bc1
@ -76,8 +76,10 @@ import PamguardMVC.background.BackgroundDataBlock;
|
||||
import PamguardMVC.background.BackgroundManager;
|
||||
import PamguardMVC.dataOffline.OfflineDataLoadInfo;
|
||||
import PamguardMVC.dataOffline.OfflineDataLoading;
|
||||
import PamguardMVC.dataSelector.DataSelectParams;
|
||||
import PamguardMVC.dataSelector.DataSelector;
|
||||
import PamguardMVC.dataSelector.DataSelectorCreator;
|
||||
import PamguardMVC.dataSelector.DataSelectorSettings;
|
||||
import PamguardMVC.dataSelector.NullDataSelectorCreator;
|
||||
import PamguardMVC.datamenus.DataMenuParent;
|
||||
import PamguardMVC.nanotime.NanoTimeCalculator;
|
||||
@ -2840,7 +2842,7 @@ public class PamDataBlock<Tunit extends PamDataUnit> extends PamObservable {
|
||||
* @return temporary copy of the data
|
||||
*/
|
||||
public ArrayList<Tunit> getDataCopy(long t1, long t2, boolean assumeOrder, DataSelector dataSelector) {
|
||||
if (dataSelector == null) {
|
||||
if (dataSelector == null || dataSelector.getParams().getCombinationFlag() == DataSelectParams.DATA_SELECT_DISABLE) {
|
||||
return getDataCopy(t1, t2, assumeOrder);
|
||||
}
|
||||
else {
|
||||
|
@ -7,7 +7,10 @@ import PamguardMVC.dataOffline.OfflineDataLoadInfo;
|
||||
import PamguardMVC.dataSelector.DataSelectorCreator;
|
||||
import RightWhaleEdgeDetector.datasel.RWDataSelCreator;
|
||||
import RightWhaleEdgeDetector.species.RWSpeciesManager;
|
||||
import RightWhaleEdgeDetector.species.RWTethysDataProvider;
|
||||
import pamScrollSystem.ViewLoadObserver;
|
||||
import tethys.TethysControl;
|
||||
import tethys.pamdata.TethysDataProvider;
|
||||
import tethys.species.DataBlockSpeciesManager;
|
||||
import whistlesAndMoans.AbstractWhistleDataBlock;
|
||||
|
||||
@ -19,6 +22,7 @@ public class RWEDataBlock extends AbstractWhistleDataBlock<RWEDataUnit> implemen
|
||||
private RWDataSelCreator dataSelCreator;
|
||||
|
||||
private RWSpeciesManager rwSpeciesManager;
|
||||
private RWTethysDataProvider rwTethysDataProvider;
|
||||
|
||||
public RWEDataBlock(RWEControl rweControl, String dataName,
|
||||
RWEProcess rweProcess, int channelMap) {
|
||||
@ -65,4 +69,12 @@ public class RWEDataBlock extends AbstractWhistleDataBlock<RWEDataUnit> implemen
|
||||
return rwSpeciesManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TethysDataProvider getTethysDataProvider(TethysControl tethysControl) {
|
||||
if (rwTethysDataProvider == null) {
|
||||
rwTethysDataProvider = new RWTethysDataProvider(tethysControl, rweProcess.getRweDataBlock());
|
||||
}
|
||||
return rwTethysDataProvider;
|
||||
}
|
||||
|
||||
}
|
||||
|
37
src/RightWhaleEdgeDetector/species/RWTethysDataProvider.java
Normal file
37
src/RightWhaleEdgeDetector/species/RWTethysDataProvider.java
Normal file
@ -0,0 +1,37 @@
|
||||
package RightWhaleEdgeDetector.species;
|
||||
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import PamguardMVC.PamDataUnit;
|
||||
import RightWhaleEdgeDetector.RWEDataUnit;
|
||||
import nilus.Detection;
|
||||
import nilus.Detection.Parameters;
|
||||
import tethys.TethysControl;
|
||||
import tethys.output.StreamExportParams;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.pamdata.AutoTethysProvider;
|
||||
|
||||
public class RWTethysDataProvider extends AutoTethysProvider {
|
||||
|
||||
public RWTethysDataProvider(TethysControl tethysControl, PamDataBlock pamDataBlock) {
|
||||
super(tethysControl, pamDataBlock);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detection createDetection(PamDataUnit dataUnit, TethysExportParams tethysExportParams,
|
||||
StreamExportParams streamExportParams) {
|
||||
Detection detection = super.createDetection(dataUnit, tethysExportParams, streamExportParams);
|
||||
if (detection == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RWEDataUnit rweDataUnit = (RWEDataUnit) dataUnit;
|
||||
|
||||
Parameters parameters = detection.getParameters();
|
||||
parameters.setScore((double) rweDataUnit.rweSound.soundType);
|
||||
double snr = 20.*Math.log10(rweDataUnit.rweSound.signal/rweDataUnit.rweSound.noise);
|
||||
parameters.setSNRDB(snr);
|
||||
|
||||
return detection;
|
||||
}
|
||||
|
||||
}
|
@ -1639,6 +1639,9 @@ InternalFrameListener, DisplayPanelContainer, SpectrogramParametersUser, PamSett
|
||||
return;
|
||||
}
|
||||
long t1 = dataUnit.getTimeMilliseconds()-viewerScroller.getValueMillis();
|
||||
if (timeAxis == null) {
|
||||
return;
|
||||
}
|
||||
int x1 = (int) Math.floor(timeAxis.getPosition(t1/1000));
|
||||
int x2 = x1;
|
||||
if (dataUnit.getDurationInMilliseconds() != null) {
|
||||
|
@ -751,7 +751,16 @@ public class DataStreamPanel extends JPanel implements DataMapObserver {
|
||||
} else if (endTimeArrow != null && endTimeArrow.contains(me.getPoint())) {
|
||||
tipText = "Data End: " + PamCalendar.formatDateTime(dataBlock.getCurrentViewDataEnd(), false);
|
||||
} else {
|
||||
tipText = "Cursor: " + PamCalendar.formatDateTime(tm, true);
|
||||
OfflineDataMap dMap = dataBlock.getPrimaryDataMap();
|
||||
if (dMap != null) {
|
||||
tipText = String.format("%s Data from<p>%s to %s<p>Cursor: %s", dataBlock.getDataName(),
|
||||
PamCalendar.formatDateTime(dMap.getFirstDataTime(), false),
|
||||
PamCalendar.formatDateTime(dMap.getLastDataTime(), false),
|
||||
PamCalendar.formatDateTime(tm, true));
|
||||
}
|
||||
else {
|
||||
tipText = "Cursor: " + PamCalendar.formatDateTime(tm, true);
|
||||
}
|
||||
}
|
||||
|
||||
// tipText += "<br>Panel height = " + getHeight();
|
||||
|
@ -84,6 +84,8 @@ abstract public class OfflineDataMap<TmapPoint extends OfflineDataMapPoint> {
|
||||
public static final int POINT_END = 0x8; // 8
|
||||
public static final int IN_DATA = 0x10; // 16
|
||||
public static final int NO_DATA = 0x20; // 32
|
||||
|
||||
private static final long oneDayInMillis = 3600L*24L*1000L;
|
||||
|
||||
public OfflineDataMap(OfflineDataStore offlineDataStore, PamDataBlock parentDataBlock) {
|
||||
super();
|
||||
@ -145,10 +147,10 @@ abstract public class OfflineDataMap<TmapPoint extends OfflineDataMapPoint> {
|
||||
*/
|
||||
synchronized public void addDataPoint(TmapPoint mapPoint) {
|
||||
boolean first = (mapPoints.size() == 0);
|
||||
if (mapPoint.getStartTime() > 0) {
|
||||
if (mapPoint.getStartTime() > oneDayInMillis) {
|
||||
firstDataTime = Math.min(firstDataTime, mapPoint.getStartTime());
|
||||
}
|
||||
if (mapPoint.getEndTime() > 0) {
|
||||
if (mapPoint.getEndTime() > oneDayInMillis) {
|
||||
lastDataTime = Math.max(lastDataTime, mapPoint.getEndTime());
|
||||
// if (mapPoint.getEndTime() > System.currentTimeMillis()) {
|
||||
// System.out.println("Stupid large data time in " + mapPoint.getName());
|
||||
@ -273,10 +275,10 @@ abstract public class OfflineDataMap<TmapPoint extends OfflineDataMapPoint> {
|
||||
|
||||
while (it.hasNext()) {
|
||||
aPoint = it.next();
|
||||
if (aPoint.getStartTime() > 0) {
|
||||
if (aPoint.getStartTime() > oneDayInMillis) {
|
||||
firstDataTime = Math.min(firstDataTime, aPoint.getStartTime());
|
||||
}
|
||||
if (aPoint.getEndTime() > 0) {
|
||||
if (aPoint.getEndTime() > oneDayInMillis) {
|
||||
lastDataTime = Math.max(lastDataTime, aPoint.getEndTime());
|
||||
}
|
||||
n = aPoint.getNDatas();
|
||||
|
@ -516,6 +516,15 @@ public class TethysControl extends PamControlledUnit implements PamSettings, Tet
|
||||
count += dbxmlQueries.countData(synchInfo.getDataBlock(), pDepl.deployment.getId());
|
||||
}
|
||||
synchInfo.setDataCount(count);
|
||||
// also count the actual number of Detectoin documents
|
||||
ArrayList<String> someNames = getDbxmlQueries().getDetectionsDocuments(synchInfo.getDataBlock(), null);
|
||||
if (someNames == null) {
|
||||
synchInfo.setDetectionDocumentCount(0);
|
||||
}
|
||||
else {
|
||||
synchInfo.setDetectionDocumentCount(someNames.size());
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
// int[] counts = dbxmlQueries.countDataForProject(deplData.getProject(), dataPrefixes);
|
||||
|
@ -47,7 +47,7 @@ public class DBXMLQueries {
|
||||
|
||||
private TethysControl tethysControl;
|
||||
private DBXMLConnect dbXMLConnect;
|
||||
|
||||
|
||||
private PamWarning queryWarning;
|
||||
|
||||
public DBXMLQueries(TethysControl tethysControl, DBXMLConnect dbXMLConnect) {
|
||||
@ -119,7 +119,7 @@ public class DBXMLQueries {
|
||||
queryWarning.setEndOfLife(t2+10000);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private DBQueryResult executeQueryT(String jsonQueryString) throws TethysQueryException {
|
||||
@ -136,7 +136,7 @@ public class DBXMLQueries {
|
||||
|
||||
try {
|
||||
JerseyClient jerseyClient = dbxmlConnect.getJerseyClient();
|
||||
// Queries queries = new Queries(jerseyClient);
|
||||
// Queries queries = new Queries(jerseyClient);
|
||||
|
||||
queryResult = jerseyClient.queryJSON(jsonQueryString, 0);
|
||||
schemaPlan = jerseyClient.queryJSON(jsonQueryString, 1);
|
||||
@ -148,7 +148,7 @@ public class DBXMLQueries {
|
||||
}
|
||||
return new DBQueryResult(System.currentTimeMillis()-t1, queryResult, schemaPlan);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether or not to strip of the s of one of the collection names.
|
||||
* This is caused by some daft thing whereby the Deployments colleciton is called Deployments
|
||||
@ -169,7 +169,7 @@ public class DBXMLQueries {
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of all documents in a collection.
|
||||
* @param collection
|
||||
@ -180,18 +180,18 @@ public class DBXMLQueries {
|
||||
return null;
|
||||
}
|
||||
collection = checkCollectionPlural(collection);
|
||||
// if (collection.endsWith("s")) {
|
||||
// collection = collection.substring(0, collection.length()-1);
|
||||
// }
|
||||
// if (collection.endsWith("s")) {
|
||||
// collection = collection.substring(0, collection.length()-1);
|
||||
// }
|
||||
String baseQuery = "{\"return\":[\"COLLECTIONNAME/Id\"],\"select\":[],\"enclose\":1}";
|
||||
baseQuery = baseQuery.replace("COLLECTIONNAME", collection);
|
||||
String tagName = "Id";
|
||||
|
||||
|
||||
if (collection.equals("SpeciesAbbreviations")) {
|
||||
baseQuery = "{\"return\":[\"Abbreviations/Name\"],\"select\":[],\"enclose\":1}";
|
||||
tagName = "Name";
|
||||
}
|
||||
|
||||
|
||||
DBQueryResult result;
|
||||
try {
|
||||
result = executeQuery(baseQuery);
|
||||
@ -216,7 +216,7 @@ public class DBXMLQueries {
|
||||
String docId = aNode.getTextContent();
|
||||
docIds.add(docId);
|
||||
}
|
||||
|
||||
|
||||
return docIds;
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ public class DBXMLQueries {
|
||||
return null;
|
||||
}
|
||||
|
||||
// System.out.println("Project query execution time millis = " + result.queryTimeMillis);
|
||||
// System.out.println("Project query execution time millis = " + result.queryTimeMillis);
|
||||
|
||||
ArrayList<String> projectNames = new ArrayList<>();
|
||||
// iterate through the document and make a list of names, then make them unique.
|
||||
@ -264,22 +264,22 @@ public class DBXMLQueries {
|
||||
projectNames.add(projName);
|
||||
}
|
||||
}
|
||||
// }
|
||||
// if (aNode instanceof Element) {
|
||||
// Node depEl = ((Element) aNode).getFirstChild();
|
||||
// if (depEl == null) {
|
||||
// continue;
|
||||
// }
|
||||
// if (depEl instanceof Element) {
|
||||
// Element projEl = (Element) ((Element) depEl).getFirstChild();
|
||||
// String projName = projEl.getTextContent();
|
||||
// if (projName != null) {
|
||||
// if (!projectNames.contains(projName)) {
|
||||
// projectNames.add(projName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (aNode instanceof Element) {
|
||||
// Node depEl = ((Element) aNode).getFirstChild();
|
||||
// if (depEl == null) {
|
||||
// continue;
|
||||
// }
|
||||
// if (depEl instanceof Element) {
|
||||
// Element projEl = (Element) ((Element) depEl).getFirstChild();
|
||||
// String projName = projEl.getTextContent();
|
||||
// if (projName != null) {
|
||||
// if (!projectNames.contains(projName)) {
|
||||
// projectNames.add(projName);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
Collections.sort(projectNames);
|
||||
@ -310,7 +310,7 @@ public class DBXMLQueries {
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
// System.out.println("Deployment query execution time millis = " + result.queryTimeMillis);
|
||||
// System.out.println("Deployment query execution time millis = " + result.queryTimeMillis);
|
||||
|
||||
PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter();
|
||||
|
||||
@ -319,19 +319,19 @@ public class DBXMLQueries {
|
||||
return null;
|
||||
}
|
||||
|
||||
// System.out.println(pamXMLWriter.getAsString(doc));
|
||||
// System.out.println(pamXMLWriter.getAsString(doc));
|
||||
|
||||
ArrayList<Deployment> deployments = new ArrayList<>();
|
||||
|
||||
NodeList returns = doc.getElementsByTagName("Deployment");
|
||||
// if (returns.getLength() == 0) {
|
||||
// // try REsult instead !
|
||||
// returns = doc.getElementsByTagName("Result");
|
||||
// }
|
||||
// if (returns.getLength() == 0) {
|
||||
// // try REsult instead !
|
||||
// returns = doc.getElementsByTagName("Result");
|
||||
// }
|
||||
// System.out.println("N projects = " + returns.getLength());
|
||||
int n = returns.getLength();
|
||||
|
||||
// Queries queries = new Queries(null)
|
||||
// Queries queries = new Queries(null)
|
||||
for (int i = 0; i < n; i++) {
|
||||
Node aNode = returns.item(i);
|
||||
if (aNode instanceof Element) {
|
||||
@ -357,8 +357,8 @@ public class DBXMLQueries {
|
||||
deployment.setDeploymentId(Integer.valueOf(DeploymentId));
|
||||
XMLGregorianCalendar gcStart = TethysTimeFuncs.fromGregorianXML(audioStart);
|
||||
XMLGregorianCalendar gcEnd = TethysTimeFuncs.fromGregorianXML(audioEnd);
|
||||
// System.out.printf("Converted %s to %s\n", audioStart,
|
||||
// PamCalendar.formatDBDateTime(TethysTimeFuncs.millisFromGregorianXML(gcStart), true));
|
||||
// System.out.printf("Converted %s to %s\n", audioStart,
|
||||
// PamCalendar.formatDBDateTime(TethysTimeFuncs.millisFromGregorianXML(gcStart), true));
|
||||
deployment.getDeploymentDetails().setAudioTimeStamp(gcStart);
|
||||
if (deployment.getRecoveryDetails() == null) {
|
||||
deployment.setRecoveryDetails(new DeploymentRecoveryDetails());
|
||||
@ -381,7 +381,7 @@ public class DBXMLQueries {
|
||||
/**
|
||||
* Get a list of Detections documents which associate with a datablock and a deploymentId.
|
||||
* @param dataBlock
|
||||
* @param deploymentId
|
||||
* @param deploymentId can be null to get all docs for data block
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<String> getDetectionsDocuments(PamDataBlock dataBlock, String deploymentId) {
|
||||
@ -422,9 +422,9 @@ public class DBXMLQueries {
|
||||
ArrayList<String> detectionsNames = new ArrayList();
|
||||
int count = 0;
|
||||
NodeList returns = doc.getElementsByTagName("Detections");
|
||||
// if (returns.getLength() == 0) {
|
||||
// returns = doc.getElementsByTagName("Result");
|
||||
// }
|
||||
// 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();
|
||||
@ -433,80 +433,81 @@ public class DBXMLQueries {
|
||||
return detectionsNames;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the names of all detection documents for a given deployment for all data streams.
|
||||
* @param deploymentId
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<String> getDetectionsDocuments(String deploymentId) {
|
||||
String queryBase = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"SomeDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}";
|
||||
String queryStr = queryBase.replace("SomeDeploymentId", deploymentId);
|
||||
DBQueryResult queryResult = null;
|
||||
try {
|
||||
queryResult = executeQuery(queryStr);
|
||||
} catch (TethysQueryException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (queryResult == null || queryResult.queryException != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter();
|
||||
|
||||
Document doc = convertStringToXMLDocument(queryResult.queryResult);
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<String> detectionDocs = new ArrayList<>();
|
||||
|
||||
NodeList returns = doc.getElementsByTagName("Return");
|
||||
if (returns.getLength() == 0) {
|
||||
returns = doc.getElementsByTagName("Result");
|
||||
}
|
||||
for (int i = 0; i < returns.getLength(); i++) {
|
||||
Node aNode = returns.item(i);
|
||||
detectionDocs.add(aNode.getTextContent());
|
||||
}
|
||||
return detectionDocs;
|
||||
* Get the names of all detection documents for a given deployment for all data streams.
|
||||
* @param deploymentId
|
||||
* @return
|
||||
*/
|
||||
public ArrayList<String> getDetectionsDocuments(String deploymentId) {
|
||||
String queryBase = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"SomeDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}";
|
||||
String queryStr = queryBase.replace("SomeDeploymentId", deploymentId);
|
||||
DBQueryResult queryResult = null;
|
||||
try {
|
||||
queryResult = executeQuery(queryStr);
|
||||
} catch (TethysQueryException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (queryResult == null || queryResult.queryException != null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter();
|
||||
|
||||
Document doc = convertStringToXMLDocument(queryResult.queryResult);
|
||||
if (doc == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<String> detectionDocs = new ArrayList<>();
|
||||
|
||||
NodeList returns = doc.getElementsByTagName("Return");
|
||||
if (returns.getLength() == 0) {
|
||||
returns = doc.getElementsByTagName("Result");
|
||||
}
|
||||
for (int i = 0; i < returns.getLength(); i++) {
|
||||
Node aNode = returns.item(i);
|
||||
detectionDocs.add(aNode.getTextContent());
|
||||
}
|
||||
return detectionDocs;
|
||||
}
|
||||
|
||||
public int countData(PamDataBlock dataBlock, String deploymentId) {
|
||||
// /**
|
||||
// * first query for Detections documents associated with this deployment and datablock.
|
||||
// */
|
||||
// String queryNoDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}";
|
||||
// String queryWithDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"TheDeploymentId\"],\"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 = executeQuery(query);
|
||||
// if (queryResult ==null) {
|
||||
// return 0;
|
||||
// }
|
||||
// Document doc;
|
||||
// try {
|
||||
// doc = queryResult.getDocument();
|
||||
// } catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int count = 0;
|
||||
// NodeList returns = doc.getElementsByTagName("Return");
|
||||
// /**
|
||||
// * first query for Detections documents associated with this deployment and datablock.
|
||||
// */
|
||||
// String queryNoDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"}],\"enclose\":1}";
|
||||
// String queryWithDepl = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/Id\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Algorithm/Software\",\"LongDataName\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"TheDeploymentId\"],\"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 = executeQuery(query);
|
||||
// if (queryResult ==null) {
|
||||
// return 0;
|
||||
// }
|
||||
// Document doc;
|
||||
// try {
|
||||
// doc = queryResult.getDocument();
|
||||
// } catch (ParserConfigurationException | SAXException | IOException e) {
|
||||
// e.printStackTrace();
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// int count = 0;
|
||||
// NodeList returns = doc.getElementsByTagName("Return");
|
||||
ArrayList<String> documentNames = getDetectionsDocuments(dataBlock, deploymentId);
|
||||
if (documentNames == null) {
|
||||
return 0;
|
||||
}
|
||||
int count = 0;
|
||||
for (String docName : documentNames) {
|
||||
// System.out.println(aNode.getTextContent());
|
||||
// System.out.println(aNode.getTextContent());
|
||||
int count2 = countDetections2(docName);
|
||||
count += count2; //countDetecionsData(docName);
|
||||
|
||||
@ -515,22 +516,22 @@ public class DBXMLQueries {
|
||||
}
|
||||
|
||||
public String getDocument(String collection, String documentId) {
|
||||
// String queryBase = "return:(collection(\"replaceCollectionName\")/Detections[Id=\"ReplaceDocumentId\"])";
|
||||
// queryBase = queryBase.replace("replaceCollectionName", collection);
|
||||
// queryBase = queryBase.replace("ReplaceDocumentId", documentId);
|
||||
//
|
||||
// String result = null;
|
||||
// try {
|
||||
// Queries queries = dbXMLConnect.getTethysQueries();
|
||||
// result = queries.QueryTethys(queryBase);
|
||||
//// System.out.println(result);
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// System.out.println("Error executing " + queryBase);
|
||||
//// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// return result;
|
||||
// String queryBase = "return:(collection(\"replaceCollectionName\")/Detections[Id=\"ReplaceDocumentId\"])";
|
||||
// queryBase = queryBase.replace("replaceCollectionName", collection);
|
||||
// queryBase = queryBase.replace("ReplaceDocumentId", documentId);
|
||||
//
|
||||
// String result = null;
|
||||
// try {
|
||||
// Queries queries = dbXMLConnect.getTethysQueries();
|
||||
// result = queries.QueryTethys(queryBase);
|
||||
//// System.out.println(result);
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// System.out.println("Error executing " + queryBase);
|
||||
//// e.printStackTrace();
|
||||
// return null;
|
||||
// }
|
||||
// return result;
|
||||
|
||||
Queries queries = dbXMLConnect.getTethysQueries();
|
||||
String result = null;
|
||||
@ -542,9 +543,9 @@ public class DBXMLQueries {
|
||||
}
|
||||
return result;
|
||||
|
||||
// String queryBase = "{\"return\":[\"Deployment/Project\"],\"select\":[],\"enclose\":1}";
|
||||
// String queryBase = "{\"return\":[\"Deployment/Project\"],\"select\":[],\"enclose\":1}";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Find out if a document exists ?
|
||||
* @param collection
|
||||
@ -562,10 +563,10 @@ public class DBXMLQueries {
|
||||
if (result == null || result.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return result.contains(documentId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Count on effort detections in a Detections document
|
||||
* @param docName
|
||||
@ -580,16 +581,16 @@ public class DBXMLQueries {
|
||||
try {
|
||||
Queries queries = dbXMLConnect.getTethysQueries();
|
||||
result = queries.QueryTethys(query);
|
||||
// System.out.println(result);
|
||||
// System.out.println(result);
|
||||
}
|
||||
catch (Exception e) {
|
||||
System.out.println("Error executing " + query);
|
||||
// e.printStackTrace();
|
||||
// e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
int count = 0;
|
||||
try {
|
||||
count = Integer.valueOf(result);
|
||||
count = Integer.valueOf(result);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
System.out.println("Unable to interpret count data " + result);
|
||||
@ -598,67 +599,67 @@ public class DBXMLQueries {
|
||||
return count;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get a count of the detections in a detections document.
|
||||
// * Only looking in onEffort so far.
|
||||
// * @param deploymentId
|
||||
// * @param detectionDocId
|
||||
// * @param dataBlock
|
||||
// * @return
|
||||
// */
|
||||
// public int getDetectionsDetectionCount(String deploymentId, String detectionDocId, PamDataBlock dataBlock) {
|
||||
// String queryBase = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/OnEffort/Detection/Start\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Id\",\"SomeDetectionsId\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"SomeDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}";
|
||||
// String queryStr = queryBase.replace("SomeDetectionsId", detectionDocId);
|
||||
// queryStr = queryStr.replace("SomeDeploymentId", deploymentId);
|
||||
// DBQueryResult queryResult = executeQuery(queryStr);
|
||||
// if (queryResult == null || queryResult.queryException != null) {
|
||||
// return 0;
|
||||
// }
|
||||
//// System.out.println("Detections query time ms = " + queryResult.queryTimeMillis);
|
||||
//
|
||||
// PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter();
|
||||
//
|
||||
// Document doc = convertStringToXMLDocument(queryResult.queryResult);
|
||||
// if (doc == null) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
//// System.out.println(pamXMLWriter.getAsString(doc));
|
||||
//
|
||||
//// ArrayList<String> detectionDocs = new ArrayList<>();
|
||||
//
|
||||
// NodeList returns = doc.getElementsByTagName("Start");
|
||||
// int n = returns.getLength();
|
||||
// return n;
|
||||
// }
|
||||
// /**
|
||||
// * Get a count of the detections in a detections document.
|
||||
// * Only looking in onEffort so far.
|
||||
// * @param deploymentId
|
||||
// * @param detectionDocId
|
||||
// * @param dataBlock
|
||||
// * @return
|
||||
// */
|
||||
// public int getDetectionsDetectionCount(String deploymentId, String detectionDocId, PamDataBlock dataBlock) {
|
||||
// String queryBase = "{\"species\":{\"query\":{\"op\":\"lib:abbrev2tsn\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]},\"return\":{\"op\":\"lib:tsn2abbrev\",\"optype\":\"function\",\"operands\":[\"%s\",\"SIO.SWAL.v1\"]}},\"return\":[\"Detections/OnEffort/Detection/Start\"],\"select\":[{\"op\":\"=\",\"operands\":[\"Detections/Id\",\"SomeDetectionsId\"],\"optype\":\"binary\"},{\"op\":\"=\",\"operands\":[\"Detections/DataSource/DeploymentId\",\"SomeDeploymentId\"],\"optype\":\"binary\"}],\"enclose\":1}";
|
||||
// String queryStr = queryBase.replace("SomeDetectionsId", detectionDocId);
|
||||
// queryStr = queryStr.replace("SomeDeploymentId", deploymentId);
|
||||
// DBQueryResult queryResult = executeQuery(queryStr);
|
||||
// if (queryResult == null || queryResult.queryException != null) {
|
||||
// return 0;
|
||||
// }
|
||||
//// System.out.println("Detections query time ms = " + queryResult.queryTimeMillis);
|
||||
//
|
||||
// PamguardXMLWriter pamXMLWriter = PamguardXMLWriter.getXMLWriter();
|
||||
//
|
||||
// Document doc = convertStringToXMLDocument(queryResult.queryResult);
|
||||
// if (doc == null) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
//// System.out.println(pamXMLWriter.getAsString(doc));
|
||||
//
|
||||
//// ArrayList<String> detectionDocs = new ArrayList<>();
|
||||
//
|
||||
// NodeList returns = doc.getElementsByTagName("Start");
|
||||
// int n = returns.getLength();
|
||||
// return n;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * This is the quickest way of counting data in a project, but it will load the start
|
||||
// * times for every detection in a project at once, so might use a lot of memory. Also
|
||||
// * it wll probably get data for all deployments in a project, which may not be what we want.
|
||||
// * @param projectName
|
||||
// * @param dataPrefixes
|
||||
// * @return
|
||||
// */
|
||||
// public int[] countDataForProject(String projectName, String[] dataPrefixes) {
|
||||
// int[] n = new int[dataPrefixes.length];
|
||||
// ArrayList<PDeployment> matchedDeployments = tethysControl.getDeploymentHandler().getMatchedDeployments();
|
||||
//// ArrayList<nilus.Deployment> deployments = getProjectDeployments(projectName);
|
||||
// if (matchedDeployments == null) {
|
||||
// return null;
|
||||
// }
|
||||
// for (PDeployment aDeployment : matchedDeployments) {
|
||||
//// ArrayList<String> detectionsIds = getDetectionsDocsIds(aDeployment.getId());
|
||||
//// for (String detId : detectionsIds) {
|
||||
//// n += getDetectionsDetectionCount(aDeployment.getId(), detId, dataBlock);
|
||||
//// }
|
||||
// int[] newN = countDataForDeployment(projectName, aDeployment.deployment.getId(), dataPrefixes);
|
||||
// for (int i = 0; i < n.length; i++) {
|
||||
// n[i] += newN[i];
|
||||
// }
|
||||
// }
|
||||
// return n;
|
||||
// }
|
||||
// /**
|
||||
// * This is the quickest way of counting data in a project, but it will load the start
|
||||
// * times for every detection in a project at once, so might use a lot of memory. Also
|
||||
// * it wll probably get data for all deployments in a project, which may not be what we want.
|
||||
// * @param projectName
|
||||
// * @param dataPrefixes
|
||||
// * @return
|
||||
// */
|
||||
// public int[] countDataForProject(String projectName, String[] dataPrefixes) {
|
||||
// int[] n = new int[dataPrefixes.length];
|
||||
// ArrayList<PDeployment> matchedDeployments = tethysControl.getDeploymentHandler().getMatchedDeployments();
|
||||
//// ArrayList<nilus.Deployment> deployments = getProjectDeployments(projectName);
|
||||
// if (matchedDeployments == null) {
|
||||
// return null;
|
||||
// }
|
||||
// for (PDeployment aDeployment : matchedDeployments) {
|
||||
//// ArrayList<String> detectionsIds = getDetectionsDocsIds(aDeployment.getId());
|
||||
//// for (String detId : detectionsIds) {
|
||||
//// n += getDetectionsDetectionCount(aDeployment.getId(), detId, dataBlock);
|
||||
//// }
|
||||
// int[] newN = countDataForDeployment(projectName, aDeployment.deployment.getId(), dataPrefixes);
|
||||
// for (int i = 0; i < n.length; i++) {
|
||||
// n[i] += newN[i];
|
||||
// }
|
||||
// }
|
||||
// return n;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Count data within a deployment document which is associated with a set of datablocks
|
||||
@ -688,14 +689,14 @@ public class DBXMLQueries {
|
||||
return null;
|
||||
}
|
||||
|
||||
// System.out.println(pamXMLWriter.getAsString(doc));
|
||||
// System.out.println(pamXMLWriter.getAsString(doc));
|
||||
|
||||
NodeList detsDocs = doc.getElementsByTagName("Detections");
|
||||
int[] blockCounts = new int[dataPrefixes.length];
|
||||
|
||||
// String detDocPrefix = projectId + "_" + dataBlock.getDataName();
|
||||
// String detDocPrefix = projectId + "_" + dataBlock.getDataName();
|
||||
|
||||
// int totalCalls = 0;
|
||||
// int totalCalls = 0;
|
||||
int detCount = 0;
|
||||
int dataIndex;
|
||||
for (int i = 0; i < detsDocs.getLength(); i++) {
|
||||
@ -716,17 +717,17 @@ public class DBXMLQueries {
|
||||
dataIndex = j;
|
||||
}
|
||||
}
|
||||
// if (id != null && id.startsWith(detDocPrefix) == false) {
|
||||
// detCount = 0;
|
||||
// break;
|
||||
// }
|
||||
// if (id != null && id.startsWith(detDocPrefix) == false) {
|
||||
// detCount = 0;
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dataIndex >= 0) {
|
||||
blockCounts[dataIndex] += detCount;
|
||||
}
|
||||
// System.out.printf("%d Added %d for new total %d\n",i, detCount, totalCalls);
|
||||
// System.out.printf("%d Added %d for new total %d\n",i, detCount, totalCalls);
|
||||
}
|
||||
|
||||
return blockCounts;
|
||||
@ -818,7 +819,7 @@ public class DBXMLQueries {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
// System.out.println(queryResult.queryResult);
|
||||
// System.out.println(queryResult.queryResult);
|
||||
|
||||
Detections detections = new Detections();
|
||||
try {
|
||||
@ -844,7 +845,7 @@ public class DBXMLQueries {
|
||||
description.setAbstract(getElementData(result, "Description.Abstract"));
|
||||
description.setMethod(getElementData(result, "Description.Method"));
|
||||
description.setObjectives(getElementData(result, "Description.Objectives"));
|
||||
|
||||
|
||||
// try to find the granularity.
|
||||
String granularityString = getElementData(result, "Effort.Kind.Granularity");
|
||||
GranularityEnumType granularity = null;
|
||||
@ -869,10 +870,10 @@ public class DBXMLQueries {
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
}
|
||||
|
||||
|
||||
kinds.add(kind);
|
||||
}
|
||||
// String
|
||||
// String
|
||||
|
||||
|
||||
|
||||
|
@ -8,6 +8,7 @@ import javax.swing.SwingWorker;
|
||||
import PamController.PamControlledUnit;
|
||||
import PamController.PamguardVersionInfo;
|
||||
import PamModel.PamPluginInterface;
|
||||
import PamView.dialog.warn.WarnOnce;
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import PamguardMVC.PamDataUnit;
|
||||
import PamguardMVC.PamProcess;
|
||||
@ -84,7 +85,7 @@ public class DetectionsHandler {
|
||||
for (String aDoc : someNames) {
|
||||
Detections detections = tethysControl.getDbxmlQueries().getDetectionsDocInfo(aDoc);
|
||||
int count = tethysControl.getDbxmlQueries().countDetections2(aDoc);
|
||||
PDetections pDetections = new PDetections(detections, null, count);
|
||||
PDetections pDetections = new PDetections(detections, dataBlock, aDep, count);
|
||||
detectionsDocs.add(pDetections);
|
||||
}
|
||||
}
|
||||
@ -364,6 +365,98 @@ public class DetectionsHandler {
|
||||
* @param exportObserver
|
||||
* @return
|
||||
*/
|
||||
private int countDetections(PamDataBlock dataBlock, StreamExportParams streamExportParams, DetectionExportObserver exportObserver) {
|
||||
/*
|
||||
* This is currently called for the entire dataset, but we will need to loop over specific Deployment documents
|
||||
* and export the content of each separately.
|
||||
*/
|
||||
TethysExportParams exportParams = tethysControl.getTethysExportParams();
|
||||
DBXMLConnect dbxmlConnect = tethysControl.getDbxmlConnect();
|
||||
DeploymentHandler depHandler = tethysControl.getDeploymentHandler();
|
||||
ArrayList<PDeployment> deployments = depHandler.getMatchedDeployments();
|
||||
// Detections currentDetections = null;
|
||||
OfflineDataMap dataMap = dataBlock.getPrimaryDataMap();
|
||||
DataSelector dataSelector = dataBlock.getDataSelector(tethysControl.getDataSelectName(), false);
|
||||
int totalCount = dataMap.getDataCount();
|
||||
int skipCount = 0;
|
||||
int exportCount = 0;
|
||||
long lastUnitTime = 0;
|
||||
DetectionExportProgress prog;
|
||||
GranularityHandler granularityHandler = GranularityHandler.getHandler(streamExportParams.granularity, tethysControl, dataBlock, exportParams, streamExportParams);
|
||||
for (PDeployment deployment : deployments) {
|
||||
int documentCount = 0;
|
||||
prog = new DetectionExportProgress(deployment, null,
|
||||
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_GATHERING);
|
||||
exportObserver.update(prog);
|
||||
granularityHandler.prepare(deployment.getAudioStart());
|
||||
// export everything in that deployment.
|
||||
// need to loop through all map points in this interval.
|
||||
List<OfflineDataMapPoint> mapPoints = dataMap.getMapPoints();
|
||||
for (OfflineDataMapPoint mapPoint : mapPoints) {
|
||||
if (!activeExport) {
|
||||
prog = new DetectionExportProgress(deployment, null,
|
||||
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_CANCELED);
|
||||
exportObserver.update(prog);
|
||||
}
|
||||
|
||||
if (mapPoint.getEndTime() < deployment.getAudioStart()) {
|
||||
continue;
|
||||
}
|
||||
if (mapPoint.getStartTime() >= deployment.getAudioEnd()) {
|
||||
break;
|
||||
}
|
||||
dataBlock.loadViewerData(mapPoint.getStartTime(), mapPoint.getEndTime(), null);
|
||||
ArrayList<PamDataUnit> dataCopy = dataBlock.getDataCopy(deployment.getAudioStart(), deployment.getAudioEnd(), true, dataSelector);
|
||||
skipCount += dataBlock.getUnitsCount() - dataCopy.size();
|
||||
for (PamDataUnit dataUnit : dataCopy) {
|
||||
/*
|
||||
* Here is where we need to handle the different granularities.
|
||||
*/
|
||||
Detection dets[] = granularityHandler.addDataUnit(dataUnit);
|
||||
if (dets != null) {
|
||||
exportCount+=dets.length;
|
||||
documentCount+=dets.length;
|
||||
}
|
||||
// Detection det = dataProvider.createDetection(dataUnit, exportParams, streamExportParams);
|
||||
// exportCount++;
|
||||
// documentCount++;
|
||||
// onEffort.getDetection().add(det);
|
||||
lastUnitTime = dataUnit.getTimeMilliseconds();
|
||||
}
|
||||
|
||||
prog = new DetectionExportProgress(deployment, null,
|
||||
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_GATHERING);
|
||||
exportObserver.update(prog);
|
||||
|
||||
// if (documentCount > 500000 && mapPoint != dataMap.getLastMapPoint()) {
|
||||
// prog = new DetectionExportProgress(deployment, currentDetections,
|
||||
// lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_WRITING);
|
||||
// exportObserver.update(prog);
|
||||
// closeDetectionsDocument(currentDetections, mapPoint.getEndTime());
|
||||
// try {
|
||||
// dbxmlConnect.postToTethys(currentDetections);
|
||||
// } catch (TethysException e) {
|
||||
// tethysControl.showException(e);
|
||||
// }
|
||||
// currentDetections = null;
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
prog = new DetectionExportProgress(null, null,
|
||||
lastUnitTime, totalCount, exportCount, skipCount, DetectionExportProgress.STATE_COMPLETE);
|
||||
exportObserver.update(prog);
|
||||
return exportCount;
|
||||
}/**
|
||||
* Export detections in all deployments for this PAMGuard dataset.
|
||||
* @param dataBlock
|
||||
* @param streamExportParams
|
||||
* @param exportObserver
|
||||
* @return
|
||||
*/
|
||||
private int exportDetections(PamDataBlock dataBlock, StreamExportParams streamExportParams, DetectionExportObserver exportObserver) {
|
||||
/*
|
||||
* This is currently called for the entire dataset, but we will need to loop over specific Deployment documents
|
||||
@ -559,7 +652,13 @@ public class DetectionsHandler {
|
||||
protected Integer doInBackground() throws Exception {
|
||||
Integer ans = null;
|
||||
try {
|
||||
ans = exportDetections(dataBlock, exportParams, this);
|
||||
int count = countDetections(dataBlock, exportParams, exportObserver);
|
||||
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();
|
||||
|
@ -1,36 +1,152 @@
|
||||
package tethys.detection;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import PamguardMVC.PamDataUnit;
|
||||
import nilus.Detection;
|
||||
import nilus.SpeciesIDType;
|
||||
import tethys.TethysControl;
|
||||
import tethys.TethysTimeFuncs;
|
||||
import tethys.output.StreamExportParams;
|
||||
import tethys.output.TethysExportParams;
|
||||
import tethys.pamdata.TethysDataProvider;
|
||||
import tethys.species.DataBlockSpeciesManager;
|
||||
import tethys.species.SpeciesMapItem;
|
||||
|
||||
/**
|
||||
* As with the binned Detections, this may generate multiple encounters
|
||||
* at the same time for different types of sounds.
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
public class EncounterGranularityHandler extends GranularityHandler {
|
||||
|
||||
|
||||
private HashMap<String, Detection> currentDetections;
|
||||
private TethysDataProvider dataProvider;
|
||||
private DataBlockSpeciesManager speciesManager;
|
||||
private long maxGapMillis;
|
||||
|
||||
public EncounterGranularityHandler(TethysControl tethysControl, PamDataBlock dataBlock,
|
||||
TethysExportParams tethysExportParams, StreamExportParams streamExportParams) {
|
||||
super(tethysControl, dataBlock, tethysExportParams, streamExportParams);
|
||||
// TODO Auto-generated constructor stub
|
||||
|
||||
dataProvider = dataBlock.getTethysDataProvider(tethysControl);
|
||||
speciesManager = dataBlock.getDatablockSpeciesManager();
|
||||
|
||||
maxGapMillis = (long) (streamExportParams.encounterGapS*1000);
|
||||
|
||||
currentDetections = new HashMap<String, Detection>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(long timeMillis) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Detection[] addDataUnit(PamDataUnit dataUnit) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
Detection[] completeDetections = checkCurrentEncounters(dataUnit.getTimeMilliseconds());
|
||||
// now look for new ones. First get the species of the dataUnit and find it in the hashmap
|
||||
String speciesCode = speciesManager.getSpeciesCode(dataUnit);
|
||||
Detection det = currentDetections.get(speciesCode);
|
||||
if (det == null) {
|
||||
// need to make a new one.
|
||||
det = new Detection();
|
||||
det.setStart(TethysTimeFuncs.xmlGregCalFromMillis(dataUnit.getTimeMilliseconds()));
|
||||
det.setEnd(TethysTimeFuncs.xmlGregCalFromMillis(dataUnit.getEndTimeInMilliseconds()));
|
||||
det.setCount(BigInteger.ONE);
|
||||
det.setChannel(BigInteger.valueOf(dataUnit.getChannelBitmap()));
|
||||
// this should always return something, so am going to crash if it doesn't.
|
||||
// may revisit this later on if we've unassigned things we don't want to label
|
||||
// in which case they should be rejected earlier than this.
|
||||
SpeciesMapItem speciesStuff = speciesManager.getSpeciesItem(dataUnit);
|
||||
SpeciesIDType species = new SpeciesIDType();
|
||||
species.setValue(BigInteger.valueOf(speciesStuff.getItisCode()));
|
||||
det.setSpeciesId(species);
|
||||
if (speciesStuff.getCallType() != null) {
|
||||
det.getCall().add(speciesStuff.getCallType());
|
||||
}
|
||||
currentDetections.put(speciesCode, det);
|
||||
}
|
||||
else {
|
||||
// add to current detection. Set new end time and increment count
|
||||
det.setEnd(TethysTimeFuncs.xmlGregCalFromMillis(dataUnit.getEndTimeInMilliseconds()));
|
||||
int count = det.getCount().intValue() + 1;
|
||||
det.setCount(BigInteger.valueOf(count));
|
||||
int chan = det.getChannel().intValue();
|
||||
chan |= dataUnit.getChannelBitmap();
|
||||
det.setChannel(BigInteger.valueOf(chan));
|
||||
}
|
||||
|
||||
|
||||
return completeDetections;
|
||||
}
|
||||
|
||||
/**
|
||||
* See if it's time to close off any encounters.
|
||||
* @param timeMilliseconds current time
|
||||
* @return list of complete encounters.
|
||||
*/
|
||||
private Detection[] checkCurrentEncounters(long timeMilliseconds) {
|
||||
Set<String> keys = currentDetections.keySet();
|
||||
int nGood = 0;
|
||||
Detection[] newDetections = new Detection[currentDetections.size()];
|
||||
for (String aKey : keys) {
|
||||
Detection aDet = currentDetections.get(aKey);
|
||||
Long detEnd = TethysTimeFuncs.millisFromGregorianXML(aDet.getEnd());
|
||||
if (timeMilliseconds-detEnd > maxGapMillis) {
|
||||
// only keep if it's got a min number of calls.
|
||||
if (aDet.getCount().intValue() >= streamExportParams.minBinCount) {
|
||||
newDetections[nGood++] = aDet;
|
||||
}
|
||||
// remove from set. A new one will be created only when required.
|
||||
currentDetections.remove(aKey);
|
||||
}
|
||||
}
|
||||
|
||||
if (nGood == 0) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return Arrays.copyOf(newDetections, nGood);
|
||||
}
|
||||
}
|
||||
|
||||
// private Detection[] checkCurrentEncounters(long timeMilliseconds) {
|
||||
// if (currentDetections == null || currentDetections.size() == 0) {
|
||||
// return null;
|
||||
// }
|
||||
// int nGood = 0;
|
||||
// Detection[] newDetections = new Detection[currentDetections.size()];
|
||||
// Iterator<Detection> detIt = currentDetections.iterator();
|
||||
// while (detIt.hasNext()) {
|
||||
// Detection aDet = detIt.next();
|
||||
// Long detEnd = TethysTimeFuncs.millisFromGregorianXML(aDet.getEnd());
|
||||
// if (timeMilliseconds-detEnd > maxGapMillis) {
|
||||
// detIt.remove();
|
||||
// newDetections[nGood++] = aDet;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (nGood == 0) {
|
||||
// return null;
|
||||
// }
|
||||
// else {
|
||||
// return Arrays.copyOf(newDetections, nGood);
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public Detection[] cleanup(long timeMillis) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
// get everything still on the go.
|
||||
return checkCurrentEncounters(timeMillis + maxGapMillis);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ public abstract class GranularityHandler {
|
||||
case CALL:
|
||||
return new CallGranularityHandler(tethysControl, dataBlock, tethysExportParams, streamExportParams);
|
||||
case ENCOUNTER:
|
||||
new EncounterGranularityHandler(tethysControl, dataBlock, tethysExportParams, streamExportParams);
|
||||
return new EncounterGranularityHandler(tethysControl, dataBlock, tethysExportParams, streamExportParams);
|
||||
case GROUPED:
|
||||
return new GroupedGranularityHandler(tethysControl, dataBlock, tethysExportParams, streamExportParams);
|
||||
default:
|
||||
|
@ -73,7 +73,7 @@ public class PDeployment {
|
||||
}
|
||||
Double gap = granularity.getEncounterGapM();
|
||||
if (gap != null) {
|
||||
str += String.format( " (%3.1f s)", gap);
|
||||
str += String.format( " (%3.1f s)", gap*60.);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package tethys.niluswraps;
|
||||
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import nilus.Detections;
|
||||
|
||||
public class PDetections {
|
||||
@ -10,8 +11,11 @@ public class PDetections {
|
||||
|
||||
public PDeployment deployment;
|
||||
|
||||
public PDetections(Detections detections, PDeployment deployment, Integer count) {
|
||||
public PamDataBlock dataBlock;
|
||||
|
||||
public PDetections(Detections detections, PamDataBlock dataBlock, PDeployment deployment, Integer count) {
|
||||
super();
|
||||
this.dataBlock = dataBlock;
|
||||
this.detections = detections;
|
||||
this.deployment = deployment;
|
||||
this.count = count;
|
||||
|
@ -16,18 +16,28 @@ import tethys.TethysControl;
|
||||
public class DatablockSynchInfo {
|
||||
|
||||
private PamDataBlock dataBlock;
|
||||
public PamDataBlock getDataBlock() {
|
||||
return dataBlock;
|
||||
}
|
||||
|
||||
private TethysControl tethysControl;
|
||||
/**
|
||||
* Count of individual datas in all Detections documents
|
||||
*/
|
||||
private int setDataCount;
|
||||
|
||||
/**
|
||||
* Count of the number of Detections documents
|
||||
*/
|
||||
private int detectionDocumentCount;
|
||||
|
||||
|
||||
public DatablockSynchInfo(TethysControl tethysControl, PamDataBlock dataBlock) {
|
||||
super();
|
||||
this.tethysControl = tethysControl;
|
||||
this.dataBlock = dataBlock;
|
||||
}
|
||||
|
||||
public PamDataBlock getDataBlock() {
|
||||
return dataBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stored export params for this data block
|
||||
@ -44,5 +54,19 @@ public class DatablockSynchInfo {
|
||||
public int getDataCount() {
|
||||
return setDataCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the detectionDocumentCount
|
||||
*/
|
||||
public int getDetectionDocumentCount() {
|
||||
return detectionDocumentCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param detectionDocumentCount the detectionDocumentCount to set
|
||||
*/
|
||||
public void setDetectionDocumentCount(int detectionDocumentCount) {
|
||||
this.detectionDocumentCount = detectionDocumentCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,14 +20,17 @@ import PamguardMVC.PamDataUnit;
|
||||
import PamguardMVC.PamProcess;
|
||||
import PamguardMVC.TFContourData;
|
||||
import PamguardMVC.TFContourProvider;
|
||||
import binaryFileStorage.DataUnitFileInformation;
|
||||
import generalDatabase.DBSchemaWriter;
|
||||
import generalDatabase.SQLLogging;
|
||||
import nilus.AlgorithmType;
|
||||
import nilus.AlgorithmType.Parameters;
|
||||
import nilus.Deployment;
|
||||
import nilus.DescriptionType;
|
||||
import nilus.Detection;
|
||||
import nilus.Detection.Parameters;
|
||||
import nilus.Detection.Parameters.UserDefined;
|
||||
import nilus.DetectionEffortKind;
|
||||
import nilus.Helper;
|
||||
import nilus.SpeciesIDType;
|
||||
import tethys.TethysControl;
|
||||
import tethys.TethysTimeFuncs;
|
||||
@ -42,6 +45,7 @@ import tethys.species.SpeciesMapItem;
|
||||
import whistleClassifier.WhistleContour;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
@ -54,7 +58,9 @@ import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Automatically provides Tethys data based on the SQL database interface
|
||||
* for a data block.
|
||||
* for a data block. does most of what needs to be done, though individual modules
|
||||
* may want to override this, call the base createDetection function and then add a
|
||||
* few more bespoke elements.
|
||||
* @author dg50
|
||||
*
|
||||
*/
|
||||
@ -119,7 +125,7 @@ public class AutoTethysProvider implements TethysDataProvider {
|
||||
// algorithm.setMethod(this.getAlgorithmMethod());
|
||||
// algorithm.setSoftware("PAMGuard");
|
||||
// algorithm.setVersion(PamguardVersionInfo.version);
|
||||
Parameters algoParameters = this.getAlgorithmParameters();
|
||||
nilus.AlgorithmType.Parameters algoParameters = this.getAlgorithmParameters();
|
||||
if (algoParameters != null) {
|
||||
algorithm.setParameters(algoParameters);
|
||||
}
|
||||
@ -128,12 +134,12 @@ public class AutoTethysProvider implements TethysDataProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Parameters getAlgorithmParameters() {
|
||||
public nilus.AlgorithmType.Parameters getAlgorithmParameters() {
|
||||
if (pamControlledUnit instanceof PamSettings == false) {
|
||||
return null;
|
||||
}
|
||||
PamSettings pamSettings = (PamSettings) pamControlledUnit;
|
||||
Parameters parameters = new Parameters();
|
||||
nilus.AlgorithmType.Parameters parameters = new nilus.AlgorithmType.Parameters();
|
||||
List<Element> paramList = parameters.getAny();
|
||||
Object settings = pamSettings.getSettingsReference();
|
||||
TethysParameterPacker paramPacker = null;
|
||||
@ -343,9 +349,38 @@ public class AutoTethysProvider implements TethysDataProvider {
|
||||
detParams.setReceivedLevelDB(ampli);
|
||||
// DataUnitBaseData basicData = dataUnit.getBasicData();
|
||||
gotTonalContour(dataUnit, detParams);
|
||||
|
||||
String uid = BigInteger.valueOf(dataUnit.getUID()).toString();
|
||||
Element el = addUserDefined(detParams,"PAMGuardUID", uid);
|
||||
DataUnitFileInformation fileInf = dataUnit.getDataUnitFileInformation();
|
||||
if (fileInf != null) {
|
||||
el.setAttribute("BinaryFile", fileInf.getShortFileName(2048));
|
||||
el.setAttribute("FileIndex", Long.valueOf(fileInf.getIndexInFile()).toString());
|
||||
}
|
||||
|
||||
return detection;
|
||||
}
|
||||
|
||||
private Element addUserDefined(Parameters parameters, String parameterName, String parameterValue) {
|
||||
UserDefined userDefined = parameters.getUserDefined();
|
||||
if (userDefined == null) {
|
||||
userDefined = new UserDefined();
|
||||
parameters.setUserDefined(userDefined);
|
||||
}
|
||||
Helper helper;
|
||||
Element el = null;
|
||||
try {
|
||||
helper = new Helper();
|
||||
el = helper.AddAnyElement(userDefined.getAny(), parameterName, parameterValue);
|
||||
} catch (JAXBException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (ParserConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return el;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tonal sounds contour. Sadly there are two slightly different interfaces in use
|
||||
|
@ -16,6 +16,7 @@ import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.table.JTableHeader;
|
||||
|
||||
import PamView.PamGui;
|
||||
import PamView.dialog.warn.WarnOnce;
|
||||
@ -26,7 +27,6 @@ import nilus.Detections;
|
||||
import nilus.GranularityType;
|
||||
import tethys.TethysControl;
|
||||
import tethys.TethysState;
|
||||
import tethys.TethysState.StateType;
|
||||
import tethys.dbxml.TethysException;
|
||||
import tethys.detection.StreamDetectionsSummary;
|
||||
import tethys.niluswraps.PDeployment;
|
||||
@ -61,7 +61,21 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
mainPanel.setBorder(new TitledBorder("Data stream Tethys Detections documents"));
|
||||
|
||||
tableModel = new TableModel();
|
||||
table = new JTable(tableModel);
|
||||
table = new JTable(tableModel) {
|
||||
@Override
|
||||
public String getToolTipText(MouseEvent event) {
|
||||
return getToolTip(event);
|
||||
}
|
||||
|
||||
protected JTableHeader createDefaultTableHeader() {
|
||||
return new JTableHeader(columnModel) {
|
||||
public String getToolTipText(MouseEvent e) {
|
||||
return getToolTip(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
};
|
||||
JScrollPane scrollPane = new JScrollPane(table);
|
||||
mainPanel.add(BorderLayout.CENTER, scrollPane);
|
||||
|
||||
@ -70,6 +84,29 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
table.addMouseListener(new MouseActions());
|
||||
}
|
||||
|
||||
protected String getToolTip(MouseEvent event) {
|
||||
java.awt.Point p = event.getPoint();
|
||||
int rowIndex = table.rowAtPoint(p);
|
||||
// if (rowIndex < 0) {
|
||||
// return null;
|
||||
// }
|
||||
int colIndex = table.columnAtPoint(p);
|
||||
switch (colIndex) {
|
||||
case 0:
|
||||
return "Tethys Detections document name";
|
||||
case 1:
|
||||
return "Name of PAMGuard data stream";
|
||||
case 2:
|
||||
return "Output granularity";
|
||||
case 3:
|
||||
return "Number of detection elements in document";
|
||||
case 4:
|
||||
return "Document abstract";
|
||||
|
||||
}
|
||||
return "No tip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getComponent() {
|
||||
return mainPanel;
|
||||
@ -192,7 +229,7 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
|
||||
private class TableModel extends AbstractTableModel {
|
||||
|
||||
private String[] colNames = {"Document", "Granularity", "Count", "Abstract"};
|
||||
private String[] colNames = {"Document", "Detector", "Granularity", "Count", "Abstract"};
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
@ -230,6 +267,11 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
case 0:
|
||||
return dets.getId();
|
||||
case 1:
|
||||
if (pDets.dataBlock == null) {
|
||||
return null;
|
||||
}
|
||||
return pDets.dataBlock.getDataName();
|
||||
case 2:
|
||||
List<DetectionEffortKind> kinds = dets.getEffort().getKind();
|
||||
if (kinds == null) {
|
||||
return null;
|
||||
@ -244,9 +286,9 @@ public class DatablockDetectionsPanel extends TethysGUIPanel implements StreamTa
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
return pDets.count;
|
||||
case 3:
|
||||
return pDets.count;
|
||||
case 4:
|
||||
return dets.getDescription().getAbstract();
|
||||
}
|
||||
return null;
|
||||
|
@ -156,7 +156,7 @@ public class DatablockSynchPanel extends TethysGUIPanel {
|
||||
|
||||
private class SynchTableModel extends AbstractTableModel {
|
||||
|
||||
String[] columnNames = {"Data Stream", "N PAM Datas", "PAMGuard Time", "N Tethys Datas", "Tethys Time", "Options"};
|
||||
String[] columnNames = {"Data Stream", "N PAM Datas", "PAMGuard Time", "Tethys Documents", "Tethys Time", "Options"};
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
@ -200,7 +200,7 @@ public class DatablockSynchPanel extends TethysGUIPanel {
|
||||
long stop = synchInfo.getDataBlock().getPrimaryDataMap().getLastDataTime();
|
||||
return String.format("%s - %s", PamCalendar.formatDBDateTime(start), PamCalendar.formatDBDateTime(stop));
|
||||
case 3:
|
||||
return synchInfo.getDataCount();
|
||||
return synchInfo.getDetectionDocumentCount();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class DetectionsExportPanel extends TethysGUIPanel implements StreamTable
|
||||
mainPanel = new PamAlignmentPanel(BorderLayout.NORTH);
|
||||
mainPanel.setLayout(new GridBagLayout());
|
||||
mainPanel.setBorder(new TitledBorder("Export"));
|
||||
exportButton = new JButton("Export");
|
||||
exportButton = new JButton("<html>Export<p>>>>></html>");
|
||||
exportButton.setToolTipText("Export PAMGaurd data to Tethys");
|
||||
exportButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@ -38,6 +38,7 @@ public class DetectionsExportPanel extends TethysGUIPanel implements StreamTable
|
||||
doExport();
|
||||
}
|
||||
});
|
||||
exportButton.setToolTipText("Select a Data Block on the left to enable export");
|
||||
exportButton.setEnabled(false);
|
||||
GridBagConstraints c = new PamGridBagContraints();
|
||||
mainPanel.add(exportButton, c);
|
||||
|
@ -52,7 +52,7 @@ public class TethysMainPanel extends TethysGUIPanel {
|
||||
southwestSplit.add(datablockSynchPanel.getComponent());
|
||||
southwestSplit.add(southEastPanel);
|
||||
southEastPanel.add(datablockDetectionsPanel.getComponent(), BorderLayout.CENTER);
|
||||
southEastPanel.add(detectionsExportPanel.getComponent(), BorderLayout.EAST);
|
||||
southEastPanel.add(detectionsExportPanel.getComponent(), BorderLayout.WEST);
|
||||
splitPane.add(southwestSplit);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
// these only work if called after display is visible
|
||||
|
Loading…
Reference in New Issue
Block a user