You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sdap.apache.org by nc...@apache.org on 2018/03/14 22:43:09 UTC

[incubator-sdap-nexus] branch master updated: SDAP-47 Update NEXUS CLI to support datainbounds algorithm (#13)

This is an automated email from the ASF dual-hosted git repository.

nchung pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-sdap-nexus.git


The following commit(s) were added to refs/heads/master by this push:
     new a4f6f85  SDAP-47 Update NEXUS CLI to support datainbounds algorithm (#13)
a4f6f85 is described below

commit a4f6f850bef104a8df6c2f8f4687f1e09c9438d5
Author: Nga Quach <ng...@gmail.com>
AuthorDate: Wed Mar 14 15:43:07 2018 -0700

    SDAP-47 Update NEXUS CLI to support datainbounds algorithm (#13)
---
 data-access/nexustiles/dao/SolrProxy.pyx | 35 ++++++++++++++++++++++++++++++++
 data-access/nexustiles/nexustiles.py     | 12 +++++++++++
 data-access/tests/solrproxy_test.py      |  7 +++++++
 3 files changed, 54 insertions(+)

diff --git a/data-access/nexustiles/dao/SolrProxy.pyx b/data-access/nexustiles/dao/SolrProxy.pyx
index d99ebad..13c9c81 100644
--- a/data-access/nexustiles/dao/SolrProxy.pyx
+++ b/data-access/nexustiles/dao/SolrProxy.pyx
@@ -565,6 +565,41 @@ class SolrProxy(object):
                           )
         return time_clause
 
+    def get_tile_count(self, ds, bounding_polygon=None, start_time=0, end_time=-1, metadata=None, **kwargs):
+        """
+        Return number of tiles that match search criteria.
+        :param ds: The dataset name to search
+        :param bounding_polygon: The polygon to search for tiles
+        :param start_time: The start time to search for tiles
+        :param end_time: The end time to search for tiles
+        :param metadata: List of metadata values to search for tiles e.g ["river_id_i:1", "granule_s:granule_name"]
+        :return: number of tiles that match search criteria
+        """
+        search = 'dataset_s:%s' % ds
+
+        additionalparams = {
+            'fq': [
+                "tile_count_i:[1 TO *]"
+            ],
+            'rows': 0
+        }
+
+        if bounding_polygon:
+            min_lon, min_lat, max_lon, max_lat = bounding_polygon.bounds
+            additionalparams['fq'].append("geo:[%s,%s TO %s,%s]" % (min_lat, min_lon, max_lat, max_lon))
+
+        if 0 < start_time <= end_time:
+            additionalparams['fq'].append(self.get_formatted_time_clause(start_time, end_time))
+
+        if metadata:
+            additionalparams['fq'].extend(metadata)
+
+        self._merge_kwargs(additionalparams, **kwargs)
+
+        results, start, found = self.do_query(*(search, None, None, True, None), **additionalparams)
+
+        return found
+
     def do_query(self, *args, **params):
 
         response = self.do_query_raw(*args, **params)
diff --git a/data-access/nexustiles/nexustiles.py b/data-access/nexustiles/nexustiles.py
index 1330c03..90622ae 100644
--- a/data-access/nexustiles/nexustiles.py
+++ b/data-access/nexustiles/nexustiles.py
@@ -364,6 +364,18 @@ class NexusTileService(object):
 
         return tiles
 
+    def get_tile_count(self, ds, bounding_polygon=None, start_time=0, end_time=-1, metadata=None, **kwargs):
+        """
+        Return number of tiles that match search criteria.
+        :param ds: The dataset name to search
+        :param bounding_polygon: The polygon to search for tiles
+        :param start_time: The start time to search for tiles
+        :param end_time: The end time to search for tiles
+        :param metadata: List of metadata values to search for tiles e.g ["river_id_i:1", "granule_s:granule_name"]
+        :return: number of tiles that match search criteria
+        """
+        return self._metadatastore.get_tile_count(ds, bounding_polygon, start_time, end_time, metadata, **kwargs)
+
     def fetch_data_for_tiles(self, *tiles):
 
         nexus_tile_ids = set([tile.tile_id for tile in tiles])
diff --git a/data-access/tests/solrproxy_test.py b/data-access/tests/solrproxy_test.py
index 6490baa..73936a7 100644
--- a/data-access/tests/solrproxy_test.py
+++ b/data-access/tests/solrproxy_test.py
@@ -76,3 +76,10 @@ class TestQuery(unittest.TestCase):
         result = self.proxy.find_all_tiles_by_metadata(['granule_s:19811114120000-NCEI-L4_GHRSST-SSTblend-AVHRR_OI-GLOB-v02.0-fv02.0.nc'], ds="AVHRR_OI_L4_GHRSST_NCEI")
 
         print len(result)
+
+    def test_get_tile_count(self):
+        tile_count = self.proxy.get_tile_count("AVHRR_OI_L4_GHRSST_NCEI", bounding_polygon=box(-180, -90, 180, 90),
+                                               start_time=1, end_time=time.time(),
+                                               metadata=['granule_s:19811114120000-NCEI-L4_GHRSST-SSTblend-AVHRR_OI-GLOB-v02.0-fv02.0.nc'])
+
+        print(tile_count)

-- 
To stop receiving notification emails like this one, please contact
nchung@apache.org.