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

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

commit 5e0fbb2521cc8ce2fa33281707aeb28950384a6b
Author: skorper <[email protected]>
AuthorDate: Mon Sep 25 15:45:41 2023 -0700

    Add # of primaries/avergae secondaries to job output
---
 analysis/webservice/algorithms/doms/ExecutionStatus.py | 12 +++++++++++-
 analysis/webservice/algorithms/doms/ResultsStorage.py  |  4 ++--
 analysis/webservice/webmodel/NexusExecutionResults.py  | 13 +++++++++++--
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/analysis/webservice/algorithms/doms/ExecutionStatus.py 
b/analysis/webservice/algorithms/doms/ExecutionStatus.py
index 1bae455..2add7b1 100644
--- a/analysis/webservice/algorithms/doms/ExecutionStatus.py
+++ b/analysis/webservice/algorithms/doms/ExecutionStatus.py
@@ -53,6 +53,14 @@ class 
ExecutionStatusHandler(BaseDomsHandler.BaseDomsQueryCalcHandler):
                     code=404
                 )
 
+        # Get execution stats. This call will raise an exception if the
+        # execution is not done.
+        with ResultsRetrieval(self.config) as retrieval:
+            try:
+                execution_stats = retrieval.retrieveStats(execution_id)
+            except NexusProcessingException:
+                execution_stats = {}
+
         job_status = 
NexusExecutionResults.ExecutionStatus(execution_details['status'])
         host = 
f'{request.requestHandler.request.protocol}://{request.requestHandler.request.host}'
 
@@ -63,5 +71,7 @@ class 
ExecutionStatusHandler(BaseDomsHandler.BaseDomsQueryCalcHandler):
             execution_id=execution_id,
             message=execution_details['message'],
             params=execution_params,
-            host=host
+            host=host,
+            num_primary_matched=execution_stats.get('numPrimaryMatched'),
+            num_secondary_matched=execution_stats.get('numSecondaryMatched')
         )
diff --git a/analysis/webservice/algorithms/doms/ResultsStorage.py 
b/analysis/webservice/algorithms/doms/ResultsStorage.py
index 39db27b..99e3c6b 100644
--- a/analysis/webservice/algorithms/doms/ResultsStorage.py
+++ b/analysis/webservice/algorithms/doms/ResultsStorage.py
@@ -286,7 +286,7 @@ class ResultsRetrieval(AbstractResultsContainer):
             execution_id = uuid.UUID(execution_id)
 
         params = self.retrieveParams(execution_id)
-        stats = self.__retrieveStats(execution_id)
+        stats = self.retrieveStats(execution_id)
         data = self.__retrieveData(execution_id, trim_data=trim_data, 
page_num=page_num, page_size=page_size)
         return params, stats, data
 
@@ -357,7 +357,7 @@ class ResultsRetrieval(AbstractResultsContainer):
 
         return entry
 
-    def __retrieveStats(self, id):
+    def retrieveStats(self, id):
         cql = "SELECT num_gridded_matched, num_insitu_matched, 
time_to_complete FROM doms_execution_stats where execution_id = %s limit 1"
         rows = self._session.execute(cql, (id,))
         for row in rows:
diff --git a/analysis/webservice/webmodel/NexusExecutionResults.py 
b/analysis/webservice/webmodel/NexusExecutionResults.py
index d5c1204..7cf9abb 100644
--- a/analysis/webservice/webmodel/NexusExecutionResults.py
+++ b/analysis/webservice/webmodel/NexusExecutionResults.py
@@ -44,7 +44,8 @@ def construct_job_status(job_state, created, updated, 
execution_id, params, host
     }
 
 
-def construct_done(status, created, completed, execution_id, params, host):
+def construct_done(status, created, completed, execution_id, params, host,
+                   num_primary_matched, num_secondary_matched):
     job_body = construct_job_status(
         status,
         created,
@@ -53,6 +54,9 @@ def construct_done(status, created, completed, execution_id, 
params, host):
         params,
         host
     )
+    # Add stats to body
+    job_body['totalPrimaryMatched'] = num_primary_matched
+    job_body['averageSecondaryMatched'] = 
round(num_secondary_matched/num_primary_matched)
 
     # Construct urls
     formats = [
@@ -112,7 +116,8 @@ def construct_cancelled(status, created, completed, 
execution_id, params, host):
 
 class NexusExecutionResults:
     def __init__(self, status=None, created=None, completed=None, 
execution_id=None, message='',
-                 params=None, host=None, status_code=200):
+                 params=None, host=None, status_code=200, 
num_primary_matched=None,
+                 num_secondary_matched=None):
         self.status_code = status_code
         self.status = status
         self.created = created
@@ -121,6 +126,8 @@ class NexusExecutionResults:
         self.message = message
         self.execution_params = params
         self.host = host
+        self.num_primary_matched = num_primary_matched
+        self.num_secondary_matched = num_secondary_matched
 
     def toJson(self):
         params = {
@@ -132,6 +139,8 @@ class NexusExecutionResults:
         }
         if self.status == ExecutionStatus.SUCCESS:
             params['completed'] = self.completed
+            params['num_primary_matched'] = self.num_primary_matched
+            params['num_secondary_matched'] = self.num_secondary_matched
             construct = construct_done
         elif self.status == ExecutionStatus.RUNNING:
             construct = construct_running

Reply via email to