mirror of
https://github.com/PAMGuard/PAMGuard.git
synced 2024-11-22 07:02:29 +00:00
up[dated exporter
This commit is contained in:
parent
0fad7c6cfa
commit
3991a87102
@ -1,12 +1,10 @@
|
||||
package tethys.output;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
@ -15,9 +13,7 @@ import javax.xml.bind.Marshaller;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import Acquisition.AcquisitionControl;
|
||||
import Acquisition.AcquisitionParameters;
|
||||
import Acquisition.AcquisitionProcess;
|
||||
import Acquisition.DaqStatusDataUnit;
|
||||
import Array.ArrayManager;
|
||||
import Array.Hydrophone;
|
||||
import Array.PamArray;
|
||||
@ -30,26 +26,17 @@ import PamUtils.PamCalendar;
|
||||
import PamguardMVC.PamDataBlock;
|
||||
import PamguardMVC.PamDataUnit;
|
||||
import PamguardMVC.dataSelector.DataSelector;
|
||||
import dataMap.OfflineDataMap;
|
||||
import dataMap.OfflineDataMapPoint;
|
||||
import generalDatabase.DBControlUnit;
|
||||
import generalDatabase.DBSchemaWriter;
|
||||
import generalDatabase.SQLLogging;
|
||||
import dbxml.uploader.Importer;
|
||||
import metadata.MetaDataContol;
|
||||
import metadata.deployment.DeploymentData;
|
||||
import nilus.Deployment;
|
||||
import nilus.DeploymentRecoveryDetails;
|
||||
import tethys.TethysControl;
|
||||
import tethys.TethysLocationFuncs;
|
||||
import tethys.TethysTimeFuncs;
|
||||
import tethys.dbxml.DBXMLConnect;
|
||||
import tethys.deployment.DeploymentHandler;
|
||||
import tethys.deployment.DeploymentRecoveryPair;
|
||||
import tethys.pamdata.TethysDataProvider;
|
||||
import tethys.pamdata.TethysSchema;
|
||||
|
||||
import dbxml.uploader.Importer;
|
||||
import nilus.Deployment;
|
||||
import nilus.MarshalXML;
|
||||
|
||||
/**
|
||||
* Class sitting at the centre of all operations. It will talk to PAMGuard
|
||||
* objects to get schemas and data and talk to the database connection to move
|
||||
@ -210,7 +197,9 @@ public class TethysExporter {
|
||||
//get list of deployment recovery details (start, stop times and lat/long)
|
||||
//deployment details and recovery details are same structure
|
||||
//per pair, go through a loop to fill in each deployment
|
||||
ArrayList<DeploymentRecoveryPair> deployRecover = getSamplingDetails();
|
||||
DeploymentHandler deploymentHandler = new DeploymentHandler();
|
||||
|
||||
ArrayList<DeploymentRecoveryPair> deployRecover = deploymentHandler.getDeployments();
|
||||
if (deployRecover == null) {
|
||||
return false;
|
||||
}
|
||||
@ -221,15 +210,14 @@ public class TethysExporter {
|
||||
int i = 0;
|
||||
for (DeploymentRecoveryPair drd : deployRecover) {
|
||||
|
||||
Deployment deployment = createDeploymentDocument(i++, drd);
|
||||
Deployment deployment = deploymentHandler.createDeploymentDocument(i++, drd);
|
||||
// System.out.println(deployment.toString());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Call some general export function
|
||||
*/
|
||||
exportGeneralData(tethysExportParams);
|
||||
|
||||
|
||||
/*
|
||||
* go through the export params and call something for every data block that's
|
||||
* enabled.
|
||||
@ -237,7 +225,7 @@ public class TethysExporter {
|
||||
ArrayList<PamDataBlock> allDataBlocks = PamController.getInstance().getDataBlocks();
|
||||
for (PamDataBlock aDataBlock : allDataBlocks) {
|
||||
StreamExportParams streamExportParams = tethysExportParams.getStreamParams(aDataBlock);
|
||||
if (streamExportParams == null || streamExportParams.selected == false) {
|
||||
if (streamExportParams == null || !streamExportParams.selected) {
|
||||
continue; // not interested in this one.
|
||||
}
|
||||
exportDataStream(aDataBlock, tethysExportParams, streamExportParams);
|
||||
@ -251,18 +239,6 @@ public class TethysExporter {
|
||||
return true;
|
||||
}
|
||||
|
||||
private Deployment createDeploymentDocument(int i, DeploymentRecoveryPair drd) {
|
||||
Deployment deployment = new Deployment();
|
||||
deployment.setDeploymentDetails(drd.deploymentDetails);
|
||||
deployment.setRecoveryDetails(drd.recoveryDetails);
|
||||
|
||||
TethysLocationFuncs.getTrackAndPositionData(deployment);
|
||||
|
||||
|
||||
|
||||
return deployment;
|
||||
}
|
||||
|
||||
/**
|
||||
* find Deployment data. This is stored in a separate PAMGuard module, which may
|
||||
* not be present.
|
||||
@ -332,115 +308,7 @@ public class TethysExporter {
|
||||
return currentGeometry;
|
||||
}
|
||||
|
||||
// in each channel
|
||||
private ArrayList<DeploymentRecoveryPair> getSamplingDetails() {
|
||||
// first find an acquisition module.
|
||||
PamControlledUnit aModule = PamController.getInstance().findControlledUnit(AcquisitionControl.class, null);
|
||||
if (aModule instanceof AcquisitionControl == false) {
|
||||
// will return if it's null. Impossible for it to be the wrong type.
|
||||
// but it's good practice to check anyway before casting.
|
||||
return null;
|
||||
}
|
||||
// cast it to the right type.
|
||||
AcquisitionControl daqControl = (AcquisitionControl) aModule;
|
||||
AcquisitionParameters daqParams = daqControl.getAcquisitionParameters();
|
||||
/**
|
||||
* The daqParams class has most of what we need about the set up in terms of
|
||||
* sample rate, number of channels, instrument type, ADC input range (part of
|
||||
* calibration), etc. It also has a hydrophone list, which maps the input
|
||||
* channel numbers to the hydrophon numbers. Realistically, this list is always
|
||||
* 0,1,2,etc or it goes horribly wrong !
|
||||
*/
|
||||
// so write functions here to get information from the daqParams.
|
||||
System.out.printf("Sample regime: %s input with rate %3.1fHz, %d channels, gain %3.1fdB, ADCp-p %3.1fV\n",
|
||||
daqParams.getDaqSystemType(), daqParams.getSampleRate(), daqParams.getNChannels(),
|
||||
daqParams.preamplifier.getGain(), daqParams.voltsPeak2Peak);
|
||||
/**
|
||||
* then there is the actual sampling. This is a bit harder to find. I thought it
|
||||
* would be in the data map but the datamap is a simple count of what's in the
|
||||
* databasase which is not quite what we want. we're going to have to query the
|
||||
* database to get more detailed informatoin I think. I'll do that here for now,
|
||||
* but we may want to move this when we better organise the code. It also seems
|
||||
* that there are 'bad' dates in the database when it starts new files, which
|
||||
* are the date data were analysed at. So we really need to check the start and
|
||||
* stop records only.
|
||||
*/
|
||||
PamDataBlock<DaqStatusDataUnit> daqInfoDataBlock = daqControl.getAcquisitionProcess().getDaqStatusDataBlock();
|
||||
// just load everything. Probably OK for the acqusition, but will bring down
|
||||
daqInfoDataBlock.loadViewerData(0, Long.MAX_VALUE, null);
|
||||
ArrayList<DaqStatusDataUnit> allStatusData = daqInfoDataBlock.getDataCopy();
|
||||
long dataStart = Long.MAX_VALUE;
|
||||
long dataEnd = Long.MIN_VALUE;
|
||||
if (allStatusData != null && allStatusData.size() > 0) {
|
||||
// find the number of times it started and stopped ....
|
||||
int nStart = 0, nStop = 0, nFile = 0;
|
||||
for (DaqStatusDataUnit daqStatus : allStatusData) {
|
||||
switch (daqStatus.getStatus()) {
|
||||
case "Start":
|
||||
nStart++;
|
||||
dataStart = Math.min(dataStart, daqStatus.getTimeMilliseconds());
|
||||
break;
|
||||
case "Stop":
|
||||
nStop++;
|
||||
dataEnd = Math.max(dataEnd, daqStatus.getEndTimeInMilliseconds());
|
||||
break;
|
||||
case "NextFile":
|
||||
nFile++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.printf(
|
||||
"Input map of sound data indicates data from %s to %s with %d starts and %d stops over %d files\n",
|
||||
PamCalendar.formatDateTime(dataStart), PamCalendar.formatDateTime(dataEnd), nStart, nStop,
|
||||
nFile + 1);
|
||||
|
||||
}
|
||||
|
||||
// // and we find the datamap within that ...
|
||||
// OfflineDataMap daqMap = daqInfoDataBlock.getOfflineDataMap(DBControlUnit.findDatabaseControl());
|
||||
// if (daqMap != null) {
|
||||
// // iterate through it.
|
||||
// long dataStart = daqMap.getFirstDataTime();
|
||||
// long dataEnd = daqMap.getLastDataTime();
|
||||
// List<OfflineDataMapPoint> mapPoints = daqMap.getMapPoints();
|
||||
// System.out.printf("Input map of sound data indicates data from %s to %s with %d individual files\n",
|
||||
// PamCalendar.formatDateTime(dataStart), PamCalendar.formatDateTime(dataEnd), mapPoints.size());
|
||||
// /*
|
||||
// * clearly in the first database I've been looking at of Tinas data, this is NOT getting sensible start and
|
||||
// * end times. Print them out to see what's going on.
|
||||
// */
|
||||
//// for ()
|
||||
// }
|
||||
|
||||
|
||||
DeploymentRecoveryPair pair = new DeploymentRecoveryPair();
|
||||
DeploymentRecoveryDetails deployment = new DeploymentRecoveryDetails();
|
||||
DeploymentRecoveryDetails recovery = new DeploymentRecoveryDetails();
|
||||
pair.deploymentDetails = deployment;
|
||||
pair.recoveryDetails = recovery;
|
||||
|
||||
deployment.setTimeStamp(TethysTimeFuncs.xmlGregCalFromMillis(dataStart));
|
||||
deployment.setAudioTimeStamp(TethysTimeFuncs.xmlGregCalFromMillis(dataStart));
|
||||
recovery.setTimeStamp(TethysTimeFuncs.xmlGregCalFromMillis(dataEnd));
|
||||
recovery.setAudioTimeStamp(TethysTimeFuncs.xmlGregCalFromMillis(dataEnd));
|
||||
|
||||
ArrayList<DeploymentRecoveryPair> drPairs = new ArrayList<>();
|
||||
drPairs.add(pair);
|
||||
return drPairs;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* No idea if we need this or not. May want to return something different to
|
||||
* void, e.g. a reference to the main object for a tethys export. I've no idea !
|
||||
*
|
||||
* @param tethysExportParams2
|
||||
*/
|
||||
private void exportGeneralData(TethysExportParams tethysExportParams) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Here is where we export data for a specific data stream to Tethys.
|
||||
|
Loading…
Reference in New Issue
Block a user