Issue #2108 - Refactor DataSizeUtils
Change-Id: I0e633fcd69edbbb25b930ac4797ae0934655bd0f Former-commit-id:a90c9e25b0
[formerly0411daa2b5
] [formerly532af54aae
] [formerlya90c9e25b0
[formerly0411daa2b5
] [formerly532af54aae
] [formerly9d66579fb9
[formerly532af54aae
[formerly b6fffb21340d210a5a63d5f060f1dfe97b4868fb]]]] Former-commit-id:9d66579fb9
Former-commit-id:d4dfd34da0
[formerlyb790996fec
] [formerly 6e58c059f2d008cb387068a9b1efd3ce8f57906e [formerlyed2ef22679
]] Former-commit-id: 167b66212b70b269c0d11e2c74a5e11a727a99e1 [formerly4205a90084
] Former-commit-id:6a36caa011
This commit is contained in:
parent
0cfc77b577
commit
ec8343f132
9 changed files with 465 additions and 256 deletions
|
@ -95,6 +95,7 @@ import com.raytheon.viz.ui.widgets.duallist.IUpdate;
|
|||
* May 15, 2013 1040 mpduff OfficeID is now a list so need to add it rather than set it.
|
||||
* May 23, 2013 1650 djohnson Fix creation of new GroupDefinitions.
|
||||
* May 28, 2013 1650 djohnson More information when failing to schedule subscriptions.
|
||||
* Jun 13, 2013 2108 mpduff Refactored DataSizeUtils.
|
||||
* </pre>
|
||||
*
|
||||
* @author jpiatt
|
||||
|
@ -367,7 +368,7 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay,
|
|||
}
|
||||
|
||||
for (Subscription subscription : groupSubscriptions) {
|
||||
|
||||
DataSizeUtils<?> sizeUtils = null;
|
||||
// Apply group properties to subscription definition
|
||||
subscription.setGroupName(groupName);
|
||||
|
||||
|
@ -399,22 +400,21 @@ public class UserSelectComp extends Composite implements IUpdate, IDisplay,
|
|||
DataSet dataset = MetaDataManager.getInstance().getDataSet(
|
||||
subscription.getDataSetName(),
|
||||
subscription.getProvider());
|
||||
DataSizeUtils u = new DataSizeUtils(dataset);
|
||||
u.setEnvelope(groupDefinition.getEnvelope());
|
||||
u.setNumFcstHours(subscription.getTime()
|
||||
.getSelectedTimeIndices().size());
|
||||
u.setNumEnsembleMembers(subscription.getEnsemble());
|
||||
u.determineNumberRequestedGrids(subscription.getParameter());
|
||||
|
||||
sizeUtils = DataSizeUtils.getInstance(dataset, subscription);
|
||||
|
||||
Coverage cov = new GriddedCoverage();
|
||||
cov.setEnvelope(groupDefinition.getEnvelope());
|
||||
|
||||
subscription.setDataSetSize(u.getDataSetSize());
|
||||
subscription.setCoverage(cov);
|
||||
}
|
||||
|
||||
subscription.addOfficeID(LocalizationManager.getInstance()
|
||||
.getCurrentSite());
|
||||
if (sizeUtils != null) {
|
||||
subscription.setDataSetSize(sizeUtils
|
||||
.getDataSetSizeInKb(subscription));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
@ -59,6 +59,7 @@ import com.raytheon.uf.common.datadelivery.registry.SiteSubscription;
|
|||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Time;
|
||||
import com.raytheon.uf.common.datadelivery.registry.handlers.DataDeliveryHandlers;
|
||||
import com.raytheon.uf.common.datadelivery.retrieval.util.GriddedDataSizeUtils;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
|
||||
import com.raytheon.uf.common.serialization.JAXBManager;
|
||||
|
@ -98,6 +99,7 @@ import com.raytheon.uf.viz.datadelivery.utils.DataDeliveryUtils;
|
|||
* Mar 29, 2013 1841 djohnson Subscription is now UserSubscription.
|
||||
* May 21, 2013 2020 mpduff Rename UserSubscription to SiteSubscription.
|
||||
* Jun 04, 2013 223 mpduff Added grid specific items to this class.
|
||||
* Jun 14, 2013 2108 mpduff Refactored DataSizeUtils.
|
||||
*
|
||||
*
|
||||
* </pre>
|
||||
|
@ -143,6 +145,9 @@ public class GriddedSubsetManagerDlg
|
|||
|
||||
private TabItem timingTab;
|
||||
|
||||
/** Gridded data size utility */
|
||||
private GriddedDataSizeUtils dataSize;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -460,28 +465,24 @@ public class GriddedSubsetManagerDlg
|
|||
return;
|
||||
}
|
||||
|
||||
// Update the data set size label text.
|
||||
|
||||
// Get the number of requested grids
|
||||
dataSize.determineNumberRequestedGrids(vTab.getParameters());
|
||||
|
||||
// Get the temporal data
|
||||
int numFcstHours = this.timingTabControls.getSelectedFcstHours().length;
|
||||
dataSize.setNumFcstHours(numFcstHours);
|
||||
if (ensembleTab != null) {
|
||||
dataSize.setNumEnsembleMembers(ensembleTab
|
||||
.getEnsembleWithSelection());
|
||||
} else {
|
||||
dataSize.setNumEnsembleMembers(dataSet.getEnsemble());
|
||||
if (dataSize == null) {
|
||||
this.dataSize = new GriddedDataSizeUtils(dataSet);
|
||||
}
|
||||
// Get the Areal data
|
||||
|
||||
// Update the data set size label text.
|
||||
List<Parameter> params = vTab.getParameters();
|
||||
int numFcstHrs = this.timingTabControls.getSelectedFcstHours().length;
|
||||
ReferencedEnvelope envelope = this.spatialTabControls.getEnvelope();
|
||||
int ensembleCount = 1;
|
||||
if (ensembleTab != null) {
|
||||
ensembleCount = ensembleTab.getEnsembleWithSelection()
|
||||
.getMemberCount();
|
||||
}
|
||||
|
||||
dataSize.setEnvelope(envelope);
|
||||
long numBytes = dataSize.getDataSetSizeInBytes(params, numFcstHrs,
|
||||
ensembleCount, envelope);
|
||||
|
||||
this.sizeLbl.setText(SizeUtil.prettyByteSize(dataSize
|
||||
.getDataSetSizeInBytes())
|
||||
+ " of "
|
||||
this.sizeLbl.setText(SizeUtil.prettyByteSize(numBytes) + " of "
|
||||
+ SizeUtil.prettyByteSize(dataSize.getFullSizeInBytes()));
|
||||
}
|
||||
|
||||
|
@ -628,6 +629,11 @@ public class GriddedSubsetManagerDlg
|
|||
|
||||
setCoverage(sub, cov);
|
||||
|
||||
// Pass a fully populated subscription in to get the size
|
||||
if (dataSize == null) {
|
||||
sub.setDataSetSize(dataSize.getDataSetSizeInKb(sub));
|
||||
}
|
||||
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.swt.widgets.Composite;
|
|||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.TabFolder;
|
||||
import org.eclipse.swt.widgets.TabItem;
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.Coverage;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Parameter;
|
||||
|
@ -38,6 +39,8 @@ import com.raytheon.uf.common.datadelivery.registry.PointDataSet;
|
|||
import com.raytheon.uf.common.datadelivery.registry.PointTime;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Time;
|
||||
import com.raytheon.uf.common.datadelivery.retrieval.util.PointDataSizeUtils;
|
||||
import com.raytheon.uf.common.util.SizeUtil;
|
||||
import com.raytheon.uf.viz.datadelivery.subscription.subset.presenter.PointTimeSubsetPresenter;
|
||||
import com.raytheon.uf.viz.datadelivery.subscription.subset.xml.PointTimeXML;
|
||||
import com.raytheon.uf.viz.datadelivery.subscription.subset.xml.SubsetXML;
|
||||
|
@ -52,6 +55,8 @@ import com.raytheon.uf.viz.datadelivery.subscription.subset.xml.SubsetXML;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 04, 2013 223 mpduff Initial creation.
|
||||
* Jun 14, 2013 2108 mpduff Refactored DataSizeUtils and
|
||||
* implement subset size.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -64,6 +69,9 @@ public class PointSubsetManagerDlg extends
|
|||
|
||||
private static final String TIMING_TAB_TEXT = "Retrieval Interval";
|
||||
|
||||
/** Point data size utility */
|
||||
private PointDataSizeUtils dataSize;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
|
@ -125,9 +133,25 @@ public class PointSubsetManagerDlg extends
|
|||
timingTabControls.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public void updateDataSize() {
|
||||
// Not used for point
|
||||
if (!initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (dataSize == null) {
|
||||
this.dataSize = new PointDataSizeUtils(dataSet);
|
||||
}
|
||||
|
||||
ReferencedEnvelope env = spatialTabControls.getEnvelope();
|
||||
int interval = timingTabControls.getDataRetrievalInterval();
|
||||
|
||||
// Update the data set size label text.
|
||||
this.sizeLbl.setText(SizeUtil.prettyByteSize(dataSize
|
||||
.getDataSetSizeInBytes(env, interval)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -189,6 +213,13 @@ public class PointSubsetManagerDlg extends
|
|||
}
|
||||
|
||||
sub.setParameter(paramList);
|
||||
|
||||
if (dataSize == null) {
|
||||
this.dataSize = new PointDataSizeUtils(dataSet);
|
||||
}
|
||||
|
||||
sub.setDataSetSize(dataSize.getDataSetSizeInKb(sub));
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
|
@ -45,7 +47,8 @@ import com.raytheon.uf.viz.datadelivery.subscription.subset.presenter.IPointData
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* May 29, 2013 223 mpduff Initial creation.
|
||||
* Jun 06, 2013 2038 djohnson Place refresh intervals into PointTime so BandwidthManager has access.
|
||||
* Jun 06, 2013 2038 djohnson Place refresh intervals into PointTime so BandwidthManager has access.
|
||||
* Jun 13, 2013 2108 mpduff Update data set size on change.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -112,6 +115,12 @@ public class PointTimeSubsetTab extends DataTimingSubsetTab implements
|
|||
intervalCombo.setLayoutData(comboData);
|
||||
intervalCombo.setItems(INTERVALS);
|
||||
intervalCombo.select(0);
|
||||
intervalCombo.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
handleSelection();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,4 +146,11 @@ public class PointTimeSubsetTab extends DataTimingSubsetTab implements
|
|||
return Integer.parseInt(intervalCombo.getItem(intervalCombo
|
||||
.getSelectionIndex()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a selection change.
|
||||
*/
|
||||
protected void handleSelection() {
|
||||
selectionChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,6 @@ import com.raytheon.uf.common.datadelivery.registry.SiteSubscription;
|
|||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Time;
|
||||
import com.raytheon.uf.common.datadelivery.request.DataDeliveryPermission;
|
||||
import com.raytheon.uf.common.datadelivery.retrieval.util.DataSizeUtils;
|
||||
import com.raytheon.uf.common.geospatial.MapUtil;
|
||||
import com.raytheon.uf.common.registry.ebxml.RegistryUtil;
|
||||
import com.raytheon.uf.common.registry.handler.RegistryHandlerException;
|
||||
|
@ -132,6 +131,8 @@ import com.raytheon.viz.ui.presenter.IDisplay;
|
|||
* May 21, 2013 2020 mpduff Rename UserSubscription to SiteSubscription.
|
||||
* May 28, 2013 1650 djohnson More information when failing to schedule subscriptions.
|
||||
* Jun 04, 2013 223 mpduff Moved data type specific code to sub classes.
|
||||
* Jun 11, 2013 2064 mpduff Fix editing of subscriptions.
|
||||
* Jun 14, 2013 2108 mpduff Refactored DataSizeUtils.
|
||||
* </pre>
|
||||
*
|
||||
* @author mpduff
|
||||
|
@ -190,9 +191,6 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
|
|||
/** Subscription object */
|
||||
protected Subscription subscription;
|
||||
|
||||
/** Utility for calculating bandwidth */
|
||||
protected DataSizeUtils dataSize = null;
|
||||
|
||||
/** Dialog initialized flag */
|
||||
protected boolean initialized = false;
|
||||
|
||||
|
@ -231,8 +229,6 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
|
|||
this.dataSet = dataSet;
|
||||
this.subsetXml = subsetXml;
|
||||
this.loadDataSet = loadDataSet;
|
||||
|
||||
this.dataSize = new DataSizeUtils(dataSet);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -270,8 +266,6 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
|
|||
subscription.getDataSetName(), subscription.getProvider());
|
||||
this.subscription = subscription;
|
||||
setText(DD_SUBSET_MANAGER + "Edit: " + subscription.getName());
|
||||
|
||||
this.dataSize = new DataSizeUtils(dataSet);
|
||||
}
|
||||
|
||||
abstract void createTabs(TabFolder tabFolder);
|
||||
|
@ -419,8 +413,7 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
|
|||
/** Create the buttons */
|
||||
private void createButtons() {
|
||||
GridData gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
|
||||
final int numColumns = 4;
|
||||
GridLayout gl = new GridLayout(numColumns, false);
|
||||
GridLayout gl = new GridLayout(3, false);
|
||||
|
||||
Composite bottomComp = new Composite(shell, SWT.NONE);
|
||||
bottomComp.setLayout(gl);
|
||||
|
@ -446,6 +439,8 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
|
|||
launchCreateSubscriptionGui(createSubscription(
|
||||
new SiteSubscription(), Network.OPSNET));
|
||||
} else {
|
||||
setupCommonSubscriptionAttributes(subscription,
|
||||
subscription.getRoute());
|
||||
launchCreateSubscriptionGui(subscription);
|
||||
}
|
||||
}
|
||||
|
@ -548,8 +543,8 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
|
|||
* The subscription object reference type
|
||||
* @param sub
|
||||
* The subscription to populate
|
||||
* @param the
|
||||
* route for the subscription
|
||||
* @param defaultRoute
|
||||
* the route for the subscription
|
||||
*
|
||||
* @return the populated subscription
|
||||
*/
|
||||
|
@ -604,7 +599,6 @@ public abstract class SubsetManagerDlg<DATASET extends DataSet, PRESENTER extend
|
|||
}
|
||||
sub.setProvider(dataSet.getProviderName());
|
||||
sub.setDataSetName(dataSet.getDataSetName());
|
||||
sub.setDataSetSize(dataSize.getDataSetSize());
|
||||
sub.setDataSetType(dataSet.getDataSetType());
|
||||
|
||||
// Catch the case where the user closes this dialog.
|
||||
|
|
|
@ -35,6 +35,7 @@ import com.raytheon.uf.viz.datadelivery.subscription.subset.xml.PointTimeXML;
|
|||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* May 29, 2013 223 mpduff Initial creation.
|
||||
* Jun 13, 2013 2108 mpduff Get the retrieval interval from the view.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -93,4 +94,13 @@ public class PointTimeSubsetPresenter
|
|||
public void updateSettings(PointTimeXML time) {
|
||||
view.setDataRetrievalInterval(time.getDataRetrievalInterval());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data retrieval interval.
|
||||
*
|
||||
* @return the data retrieval interval
|
||||
*/
|
||||
public int getDataRetrievalInterval() {
|
||||
return view.getDataRetrievalInterval();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,24 +19,18 @@
|
|||
**/
|
||||
package com.raytheon.uf.common.datadelivery.retrieval.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.Coverage;
|
||||
import com.raytheon.uf.common.datadelivery.registry.DataSet;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Ensemble;
|
||||
import com.raytheon.uf.common.datadelivery.registry.DataType;
|
||||
import com.raytheon.uf.common.datadelivery.registry.EnvelopeUtils;
|
||||
import com.raytheon.uf.common.datadelivery.registry.GriddedCoverage;
|
||||
import com.raytheon.uf.common.datadelivery.registry.GriddedDataSet;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Levels;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Parameter;
|
||||
import com.raytheon.uf.common.datadelivery.registry.PointDataSet;
|
||||
import com.raytheon.uf.common.datadelivery.registry.PointTime;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Provider.ServiceType;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.raytheon.uf.common.datadelivery.retrieval.xml.RetrievalAttribute;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.util.CollectionUtil;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
|
||||
/**
|
||||
|
@ -53,6 +47,7 @@ import com.vividsolutions.jts.geom.Coordinate;
|
|||
* Oct 31, 2012 1278 mpduff Clarified a Javadoc comment.
|
||||
* Dec 10, 2012 1259 bsteffen Switch Data Delivery from LatLon to referenced envelopes.
|
||||
* Jun 11, 2013 2021 dhladky WFS semi-scientific sizing.
|
||||
* Jun 14, 2013 2108 mpduff Abstracted the class.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
|
@ -60,16 +55,38 @@ import com.vividsolutions.jts.geom.Coordinate;
|
|||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class DataSizeUtils {
|
||||
public abstract class DataSizeUtils<DS extends DataSet> {
|
||||
|
||||
/**
|
||||
* Get data size
|
||||
* Factory method to get a DataSizeUtils.
|
||||
*
|
||||
* @param dataSet
|
||||
* The data set
|
||||
* @param subscription
|
||||
* The subscription
|
||||
* @return The correct implementation of DataSizeUtils
|
||||
*/
|
||||
public static DataSizeUtils<?> getInstance(DataSet dataSet,
|
||||
Subscription subscription) {
|
||||
DataSizeUtils<?> dsu = null;
|
||||
if (subscription.getDataSetType() == DataType.GRID) {
|
||||
dsu = new GriddedDataSizeUtils((GriddedDataSet) dataSet);
|
||||
} else if (subscription.getDataSetType() == DataType.POINT) {
|
||||
dsu = new PointDataSizeUtils((PointDataSet) dataSet);
|
||||
}
|
||||
|
||||
return dsu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data size.
|
||||
*
|
||||
* @param ra
|
||||
* RetrievalAttribute
|
||||
* @param st
|
||||
* @return
|
||||
* ServiceType
|
||||
* @return dataset size
|
||||
*/
|
||||
|
||||
public static long calculateSize(RetrievalAttribute ra, ServiceType st) {
|
||||
|
||||
if (st == ServiceType.OPENDAP) {
|
||||
|
@ -89,15 +106,16 @@ public class DataSizeUtils {
|
|||
}
|
||||
|
||||
} else if (st == ServiceType.WFS) {
|
||||
|
||||
|
||||
ReferencedEnvelope re = ra.getCoverage().getRequestEnvelope();
|
||||
Coordinate ur = EnvelopeUtils.getUpperRightLatLon(re);
|
||||
Coordinate ll = EnvelopeUtils.getLowerLeftLatLon(re);
|
||||
double lonSpan = Math.abs(ll.x - ur.x);
|
||||
double latSpan = Math.abs(ll.y - ur.y);
|
||||
PointTime time = (PointTime)ra.getTime();
|
||||
long l = st.getRequestBytesPerLatLonBoxAndTime(latSpan, lonSpan, time.getInterval());
|
||||
|
||||
PointTime time = (PointTime) ra.getTime();
|
||||
long l = st.getRequestBytesPerLatLonBoxAndTime(latSpan, lonSpan,
|
||||
time.getInterval());
|
||||
|
||||
return l;
|
||||
} else {
|
||||
throw new IllegalStateException(
|
||||
|
@ -107,234 +125,65 @@ public class DataSizeUtils {
|
|||
}
|
||||
|
||||
/** Bytes per Kilobyte */
|
||||
private static final int bytesPerKilobyte = 1024;
|
||||
protected static final int bytesPerKilobyte = 1024;
|
||||
|
||||
/** Data Set Object */
|
||||
private DataSet dataSet = null;
|
||||
protected DS dataSet;
|
||||
|
||||
/** Data Set Size */
|
||||
private long size = 0;
|
||||
protected final long size = 0;
|
||||
|
||||
/** Full Data Set Size in bytes */
|
||||
private long fullSize = -999;
|
||||
|
||||
/** Number of requested grids */
|
||||
private int numRequestedGrids = 0;
|
||||
|
||||
/** Number of forecast hours */
|
||||
private int numFcstHours = 0;
|
||||
|
||||
private int numEnsembleMembers = 0;
|
||||
|
||||
/** Envelope */
|
||||
private ReferencedEnvelope envelope = null;
|
||||
|
||||
/** Number of grid cells */
|
||||
private int numberOfGridCells = 0;
|
||||
|
||||
/** Default Constructor */
|
||||
public DataSizeUtils() {
|
||||
|
||||
}
|
||||
protected long fullSize = -999;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Returns the estimated full data set size in bytes.
|
||||
*
|
||||
* @param dataSetName
|
||||
* The data set name
|
||||
* @return full data set size in bytes
|
||||
*/
|
||||
public DataSizeUtils(DataSet dataSet) {
|
||||
this.dataSet = dataSet;
|
||||
}
|
||||
public abstract long getFullSizeInBytes();
|
||||
|
||||
private void calculateGridCells() {
|
||||
if (dataSet != null) {
|
||||
Coverage cov = dataSet.getCoverage();
|
||||
if (cov instanceof GriddedCoverage) {
|
||||
GriddedCoverage griddedCov = (GriddedCoverage) cov;
|
||||
|
||||
GridCoverage subgridCov = griddedCov
|
||||
.getRequestGridCoverage(envelope);
|
||||
if (subgridCov == null) {
|
||||
subgridCov = griddedCov.getGridCoverage();
|
||||
}
|
||||
int nx = subgridCov.getNx();
|
||||
int ny = subgridCov.getNy();
|
||||
|
||||
numberOfGridCells = nx * ny;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the data set size for the provided subscription.
|
||||
*
|
||||
* @param subscription
|
||||
* Subscription for calculating the size
|
||||
* @return Data size in bytes
|
||||
*/
|
||||
protected abstract long getDataSetSizeInBytes(Subscription subscription);
|
||||
|
||||
/**
|
||||
* @return the dataSet
|
||||
*/
|
||||
public DataSet getDataSet() {
|
||||
public DS getDataSet() {
|
||||
return dataSet;
|
||||
}
|
||||
|
||||
public long getDataSetSizeInBytes() {
|
||||
long l = numRequestedGrids
|
||||
* numFcstHours
|
||||
* numEnsembleMembers
|
||||
* dataSet.getServiceType().getRequestBytesPerParameterPerLevel(
|
||||
numberOfGridCells);
|
||||
return l;
|
||||
/**
|
||||
* Returns the estimated data set size in kB.
|
||||
*
|
||||
* @param subscription
|
||||
* The subscription to size
|
||||
*
|
||||
* @return the size in kB
|
||||
*/
|
||||
public long getDataSetSizeInKb(Subscription subscription) {
|
||||
return getDataSetSizeInBytes(subscription) / bytesPerKilobyte;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimated data set size in KB.
|
||||
* Returns the estimated full dataset size in kB.
|
||||
*
|
||||
* @return
|
||||
* @return full data set size in kB
|
||||
*/
|
||||
public long getDataSetSize() {
|
||||
return getDataSetSizeInBytes() / bytesPerKilobyte;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimated full dataset size in bytes.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getFullSizeInBytes() {
|
||||
if (dataSet != null) {
|
||||
if (fullSize == -999) {
|
||||
Coverage cov = dataSet.getCoverage();
|
||||
if (cov instanceof GriddedCoverage) {
|
||||
GriddedCoverage griddedCov = (GriddedCoverage) cov;
|
||||
long numCells = griddedCov.getGridCoverage().getNx()
|
||||
* griddedCov.getGridCoverage().getNy();
|
||||
// Default to 1 forecast hour if not a gridded data set
|
||||
long numEns = 1;
|
||||
long fcstHrs = 1;
|
||||
if (dataSet instanceof GriddedDataSet) {
|
||||
GriddedDataSet gDataSet = (GriddedDataSet) dataSet;
|
||||
fcstHrs = gDataSet.getForecastHours().size();
|
||||
if (gDataSet.getEnsemble() != null) {
|
||||
numEns = gDataSet.getEnsemble().getMemberCount();
|
||||
}
|
||||
}
|
||||
Map<String, Parameter> paramMap = dataSet.getParameters();
|
||||
|
||||
// get the number of grids available
|
||||
long numGridsAvailable = 0;
|
||||
|
||||
for (Parameter p : paramMap.values()) {
|
||||
int numLevels = p.getLevels().getLevel().size();
|
||||
|
||||
// parameter is always at least on one level, level just
|
||||
// may not be named/enumerated
|
||||
numGridsAvailable += (numLevels > 0 ? numLevels : 1);
|
||||
}
|
||||
|
||||
fullSize = numEns
|
||||
* fcstHrs
|
||||
* numGridsAvailable
|
||||
* dataSet.getServiceType()
|
||||
.getRequestBytesPerParameterPerLevel(
|
||||
numCells);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fullSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the estimated full dataset size in KB.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getFullSize() {
|
||||
public long getFullSizeInKb() {
|
||||
return getFullSizeInBytes() / bytesPerKilobyte;
|
||||
}
|
||||
|
||||
public int getNumberOfGridCells() {
|
||||
return numberOfGridCells;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the numFcstHours
|
||||
*/
|
||||
public int getNumFcstHours() {
|
||||
return numFcstHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the size
|
||||
*/
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the state of this object
|
||||
*/
|
||||
public void reset() {
|
||||
numRequestedGrids = 0;
|
||||
size = 0;
|
||||
dataSet = null;
|
||||
}
|
||||
|
||||
public void setEnvelope(ReferencedEnvelope envelope) {
|
||||
this.envelope = envelope;
|
||||
if (envelope != null) {
|
||||
calculateGridCells();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataSet
|
||||
* the dataSet to set
|
||||
*/
|
||||
public void setDataSet(DataSet dataSet) {
|
||||
this.dataSet = dataSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numFcstHours
|
||||
* the numFcstHours to set
|
||||
*/
|
||||
public void setNumFcstHours(int numFcstHours) {
|
||||
this.numFcstHours = numFcstHours;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param numRequestedGrids
|
||||
* the numRequestedGrids to set
|
||||
*/
|
||||
public void determineNumberRequestedGrids(List<Parameter> parameterList) {
|
||||
int numGrids = 0;
|
||||
|
||||
// Get the number of requested grids
|
||||
if (!CollectionUtil.isNullOrEmpty(parameterList)) {
|
||||
for (Parameter par : parameterList) {
|
||||
Levels parLevels = par.getLevels();
|
||||
int numSelectedLevels = parLevels.getSelectedLevelIndices()
|
||||
.size();
|
||||
if (numSelectedLevels < 1) {
|
||||
// if parameter is not available on more than level, then by
|
||||
// default the single level is selected
|
||||
if (parLevels.size() <= 1) {
|
||||
numSelectedLevels = 1;
|
||||
}
|
||||
// else user did not select any levels for this parameter
|
||||
}
|
||||
|
||||
numGrids += numSelectedLevels;
|
||||
}
|
||||
}
|
||||
|
||||
this.numRequestedGrids = numGrids;
|
||||
}
|
||||
|
||||
public void setNumEnsembleMembers(Ensemble ensemble) {
|
||||
if (ensemble == null) {
|
||||
this.numEnsembleMembers = 1;
|
||||
} else {
|
||||
this.numEnsembleMembers = ensemble.getSelectedMemberCount();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.datadelivery.retrieval.util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.Coverage;
|
||||
import com.raytheon.uf.common.datadelivery.registry.GriddedCoverage;
|
||||
import com.raytheon.uf.common.datadelivery.registry.GriddedDataSet;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Levels;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Parameter;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.raytheon.uf.common.gridcoverage.GridCoverage;
|
||||
import com.raytheon.uf.common.util.CollectionUtil;
|
||||
|
||||
/**
|
||||
* Gridded implementation of DataSizeUtils
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 13, 2013 2108 mpduff Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mpduff
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class GriddedDataSizeUtils extends DataSizeUtils<GriddedDataSet> {
|
||||
|
||||
/**
|
||||
* Gridded constructor.
|
||||
*
|
||||
* @param dataSet
|
||||
* the data set
|
||||
*/
|
||||
public GriddedDataSizeUtils(GriddedDataSet dataSet) {
|
||||
this.dataSet = dataSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the number of grid cells for the envelope.
|
||||
*
|
||||
* @param envelope
|
||||
* The areal envelope
|
||||
* @return number of grid cells
|
||||
*/
|
||||
private int calculateGridCells(ReferencedEnvelope envelope) {
|
||||
if (dataSet != null) {
|
||||
Coverage cov = dataSet.getCoverage();
|
||||
if (cov instanceof GriddedCoverage) {
|
||||
GriddedCoverage griddedCov = (GriddedCoverage) cov;
|
||||
|
||||
GridCoverage subgridCov = griddedCov
|
||||
.getRequestGridCoverage(envelope);
|
||||
if (subgridCov == null) {
|
||||
subgridCov = griddedCov.getGridCoverage();
|
||||
}
|
||||
int nx = subgridCov.getNx();
|
||||
int ny = subgridCov.getNy();
|
||||
|
||||
return nx * ny;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of grids for the request.
|
||||
*
|
||||
* @param parameterList
|
||||
* the list of parameters
|
||||
*
|
||||
* @return number of grids
|
||||
*/
|
||||
private int getNumberRequestedGrids(List<Parameter> parameterList) {
|
||||
int numGrids = 0;
|
||||
|
||||
// Get the number of requested grids
|
||||
if (!CollectionUtil.isNullOrEmpty(parameterList)) {
|
||||
for (Parameter par : parameterList) {
|
||||
Levels parLevels = par.getLevels();
|
||||
int numSelectedLevels = parLevels.getSelectedLevelIndices()
|
||||
.size();
|
||||
if (numSelectedLevels < 1) {
|
||||
// if parameter is not available on more than level, then by
|
||||
// default the single level is selected
|
||||
if (parLevels.size() <= 1) {
|
||||
numSelectedLevels = 1;
|
||||
}
|
||||
// else user did not select any levels for this parameter
|
||||
}
|
||||
|
||||
numGrids += numSelectedLevels;
|
||||
}
|
||||
}
|
||||
|
||||
return numGrids;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long getFullSizeInBytes() {
|
||||
if (dataSet != null) {
|
||||
if (fullSize == -999) {
|
||||
GriddedCoverage griddedCov = (GriddedCoverage) dataSet
|
||||
.getCoverage();
|
||||
long numCells = griddedCov.getGridCoverage().getNx()
|
||||
* griddedCov.getGridCoverage().getNy();
|
||||
long numEns = 1;
|
||||
long fcstHrs = 1;
|
||||
if (dataSet instanceof GriddedDataSet) {
|
||||
GriddedDataSet gDataSet = dataSet;
|
||||
fcstHrs = gDataSet.getForecastHours().size();
|
||||
if (gDataSet.getEnsemble() != null) {
|
||||
numEns = gDataSet.getEnsemble().getMemberCount();
|
||||
}
|
||||
}
|
||||
Map<String, Parameter> paramMap = dataSet.getParameters();
|
||||
|
||||
// get the number of grids available
|
||||
long numGridsAvailable = 0;
|
||||
|
||||
for (Parameter p : paramMap.values()) {
|
||||
int numLevels = p.getLevels().getLevel().size();
|
||||
|
||||
// parameter is always at least on one level, level
|
||||
// just may not be named/enumerated
|
||||
numGridsAvailable += (numLevels > 0 ? numLevels : 1);
|
||||
}
|
||||
|
||||
fullSize = numEns
|
||||
* fcstHrs
|
||||
* numGridsAvailable
|
||||
* dataSet.getServiceType()
|
||||
.getRequestBytesPerParameterPerLevel(numCells);
|
||||
}
|
||||
}
|
||||
|
||||
return fullSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long getDataSetSizeInBytes(Subscription subscription) {
|
||||
return getDataSetSizeInBytes(subscription.getParameter(), subscription
|
||||
.getTime().getSelectedTimeIndices().size(), subscription
|
||||
.getEnsemble().getMemberCount(), subscription.getCoverage()
|
||||
.getRequestEnvelope());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data set size in bytes.
|
||||
*
|
||||
* @param params
|
||||
* List of parameters
|
||||
* @param numFcstHrs
|
||||
* Number of forecast hours
|
||||
* @param numEnsembleMembers
|
||||
* Number of ensemble members
|
||||
* @param envelope
|
||||
* ReferencedEnvelope
|
||||
* @return Number of bytes
|
||||
*/
|
||||
public long getDataSetSizeInBytes(List<Parameter> params, int numFcstHrs,
|
||||
int numEnsembleMembers, ReferencedEnvelope envelope) {
|
||||
int numberOfGridCells = calculateGridCells(envelope);
|
||||
|
||||
int numRequestedGrids = getNumberRequestedGrids(params);
|
||||
|
||||
long l = numRequestedGrids
|
||||
* numFcstHrs
|
||||
* numEnsembleMembers
|
||||
* dataSet.getServiceType().getRequestBytesPerParameterPerLevel(
|
||||
numberOfGridCells);
|
||||
return l;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* This software was developed and / or modified by Raytheon Company,
|
||||
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
|
||||
*
|
||||
* U.S. EXPORT CONTROLLED TECHNICAL DATA
|
||||
* This software product contains export-restricted data whose
|
||||
* export/transfer/disclosure is restricted by U.S. law. Dissemination
|
||||
* to non-U.S. persons whether in the United States or abroad requires
|
||||
* an export license or other authorization.
|
||||
*
|
||||
* Contractor Name: Raytheon Company
|
||||
* Contractor Address: 6825 Pine Street, Suite 340
|
||||
* Mail Stop B8
|
||||
* Omaha, NE 68106
|
||||
* 402.291.0100
|
||||
*
|
||||
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
|
||||
* further licensing information.
|
||||
**/
|
||||
package com.raytheon.uf.common.datadelivery.retrieval.util;
|
||||
|
||||
import org.geotools.geometry.jts.ReferencedEnvelope;
|
||||
|
||||
import com.raytheon.uf.common.datadelivery.registry.EnvelopeUtils;
|
||||
import com.raytheon.uf.common.datadelivery.registry.PointDataSet;
|
||||
import com.raytheon.uf.common.datadelivery.registry.PointTime;
|
||||
import com.raytheon.uf.common.datadelivery.registry.Subscription;
|
||||
import com.vividsolutions.jts.geom.Coordinate;
|
||||
|
||||
/**
|
||||
* Point implementation for DataSizeUtils.
|
||||
*
|
||||
* <pre>
|
||||
*
|
||||
* SOFTWARE HISTORY
|
||||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jun 13, 2013 2108 mpduff Initial creation.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author mpduff
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class PointDataSizeUtils extends DataSizeUtils<PointDataSet> {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param dataSet
|
||||
* The dataSet
|
||||
*/
|
||||
public PointDataSizeUtils(PointDataSet dataSet) {
|
||||
this.dataSet = dataSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long getFullSizeInBytes() {
|
||||
// Not applicable for point data sets
|
||||
return -999;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@Override
|
||||
public long getDataSetSizeInBytes(Subscription subscription) {
|
||||
return getDataSetSizeInBytes(subscription.getCoverage()
|
||||
.getRequestEnvelope(),
|
||||
((PointTime) subscription.getTime()).getInterval());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data set size.
|
||||
*
|
||||
* @param envelope
|
||||
* The areal envelope
|
||||
* @param interval
|
||||
* The data retrieval interval
|
||||
* @return Data set size in bytes
|
||||
*/
|
||||
public long getDataSetSizeInBytes(ReferencedEnvelope envelope, int interval) {
|
||||
Coordinate ur = EnvelopeUtils.getUpperRightLatLon(envelope);
|
||||
Coordinate ll = EnvelopeUtils.getLowerLeftLatLon(envelope);
|
||||
double lonSpan = Math.abs(ll.x - ur.x);
|
||||
double latSpan = Math.abs(ll.y - ur.y);
|
||||
|
||||
return dataSet.getServiceType().getRequestBytesPerLatLonBoxAndTime(
|
||||
latSpan, lonSpan, interval);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue