This commit is contained in:
Douglas Gillespie 2023-05-26 09:46:33 +01:00
commit d350d5a765
4 changed files with 102 additions and 10 deletions

View File

@ -843,6 +843,30 @@ public class PamDataBlock<Tunit extends PamDataUnit> extends PamObservable {
return unitsInInterval;
}
/**
* Do data exist which cover the given time range ?
* @param startMillis
* @param endMillis
* @return true if data exist covering that time range.
*/
public boolean hasDataRange(long startMillis, long endMillis) {
PamDataUnit first = null, last = null;
synchronized (synchronizationLock) {
first = getFirstUnit();
last = getLastUnit();
}
if (first == null || last == null) {
return false;
}
if (first.getTimeMilliseconds() > startMillis) {
return false;
}
if (last.getEndTimeInMilliseconds() < endMillis) {
return false;
}
return true;
}
// recursive search for the correct unit
// private Tunit searchFirstUnitAfter(int i1, int i2, long timems) {
@ -1014,6 +1038,9 @@ public class PamDataBlock<Tunit extends PamDataUnit> extends PamObservable {
* @return true if we need to reload offline data.
*/
public boolean needViewerDataLoad(OfflineDataLoadInfo offlineDataLoadInfo) {
if (pamDataUnits.size() == 0) {
return true;
}
if (offlineDataLoadInfo.getStartMillis() == currentViewDataStart
&& offlineDataLoadInfo.getEndMillis() == currentViewDataEnd) {
return false;

View File

@ -527,7 +527,10 @@ public class OfflineDataLoading<T extends PamDataUnit> {
public void notifyOfflineObservers(T pamDataUnit) {
if (requestingObservers != null) {
for (int i = 0; i < requestingObservers.size(); i++) {
requestingObservers.get(i).addData(pamDataBlock, pamDataUnit);
PamObserver obs = requestingObservers.get(i);
if (obs != null) {
obs.addData(pamDataBlock, pamDataUnit);
}
}
}

View File

@ -4,6 +4,7 @@ import java.util.ListIterator;
import PamguardMVC.PamDataBlock;
import PamguardMVC.PamDataUnit;
import PamguardMVC.dataOffline.OfflineDataLoadInfo;
import bearinglocaliser.BearingLocaliserControl;
import bearinglocaliser.BearingProcess;
import dataMap.OfflineDataMapPoint;
@ -28,6 +29,9 @@ public class BLOfflineTask extends OfflineTask {
@Override
public String getName() {
if (bearingLocaliserControl == null) {
return null;
}
return bearingLocaliserControl.getUnitName();
}
@ -67,15 +71,21 @@ public class BLOfflineTask extends OfflineTask {
if (rawOrFFTBlock == null) {
return;
}
ListIterator it = rawOrFFTBlock.getListIterator(dataUnit.getTimeMilliseconds(), rawOrFFTBlock.getChannelMap(),
PamDataBlock.MATCH_BEFORE, PamDataBlock.POSITION_BEFORE);
if (it == null || it.hasNext() == false) {
long dataStart = dataUnit.getTimeMilliseconds();
long dataEnd = dataUnit.getEndTimeInMilliseconds();
if (dataEnd-dataStart <= 0) {
dataEnd = dataStart + 1000;
}
rawOrFFTBlock.loadViewerData(dataStart, dataEnd, null);
long dataStart = dataUnit.getTimeMilliseconds();
long dataEnd = dataUnit.getEndTimeInMilliseconds();
boolean haveData = rawOrFFTBlock.hasDataRange(dataStart, dataEnd);
if (haveData == false) {
// ListIterator it = rawOrFFTBlock.getListIterator(dataUnit.getTimeMilliseconds(), rawOrFFTBlock.getChannelMap(),
// PamDataBlock.MATCH_BEFORE, PamDataBlock.POSITION_BEFORE);
// if (it == null || it.hasNext() == false) {
// if (dataEnd-dataStart <= 0) {
// dataEnd = dataStart + 1000;
// }
OfflineDataLoadInfo offlineLoadInfo = new OfflineDataLoadInfo(dataStart, dataEnd);
offlineLoadInfo.setLoadKeepLayers(2);
rawOrFFTBlock.getOfflineData(offlineLoadInfo);
// System.out.printf("Loaded some FFT data I hope\n");
// rawOrFFTBlock.loadViewerData(dataStart, dataEnd, null);
}
}

View File

@ -4,6 +4,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
import PamController.PamController;
import PamController.SettingsNameProvider;
import PamDetection.RawDataUnit;
import PamUtils.PamUtils;
@ -143,6 +144,11 @@ public class FFTDataOrganiser {
if (rawOrFFTData == null) {
return null;
}
// if (PamController.getInstance().getRunMode() == PamController.RUN_PAMVIEW) {
// checkOfflineDataLoad(rawOrFFTData, pamDataUnit.getTimeMilliseconds(), pamDataUnit.getEndTimeInMilliseconds());
// }
switch (inputType) {
case FFTData:
return createFromFFTData(pamDataUnit, sampleRate, channelMap);
@ -157,6 +163,52 @@ public class FFTDataOrganiser {
}
}
/**
* Called when running offline to try to ensure required raw or fft data are in memory.
* @param sourceData
* @param timeMilliseconds
* @param endTimeInMilliseconds
*/
private boolean checkOfflineDataLoad(PamDataBlock sourceData, long startMilliseconds, long endMilliseconds) {
if (sourceData == null) {
return false;
}
boolean needData = needOfflineDataLoad(sourceData, startMilliseconds, endMilliseconds);
if (needData) {
sourceData.loadViewerData(startMilliseconds, endMilliseconds, null);
}
return needOfflineDataLoad(sourceData, startMilliseconds, endMilliseconds);
}
/**
* Test to see if we still need to load offline data.
* @param sourceData
* @param startMilliseconds
* @param endMilliseconds
* @return
*/
private boolean needOfflineDataLoad(PamDataBlock sourceData, long startMilliseconds, long endMilliseconds) {
if (sourceData == null) {
return false;
}
synchronized (sourceData.getSynchLock()) {
PamDataUnit first = sourceData.getFirstUnit();
PamDataUnit last = sourceData.getLastUnit();
if (first == null || last == null) {
return true;
}
if (first.getTimeMilliseconds() > startMilliseconds) {
return true;
}
if (last.getEndTimeInMilliseconds() < endMilliseconds) {
return true;
}
}
return false;
}
/**
* Get FFT data units matching in time from the source
* @param pamDataUnit data unit we need FFT data for (can be anything, just needs it's times)