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

tloubrieu 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 3ad938f  Add toJson in data-in-bounds api (#154)
3ad938f is described below

commit 3ad938f715e60fc5fc185836220fb697014d71d3
Author: Jason Min-Liang Kang <[email protected]>
AuthorDate: Thu Mar 10 10:46:22 2022 -0800

    Add toJson in data-in-bounds api (#154)
---
 analysis/webservice/algorithms/DataInBoundsSearch.py | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/analysis/webservice/algorithms/DataInBoundsSearch.py 
b/analysis/webservice/algorithms/DataInBoundsSearch.py
index 0b6c055..2df061f 100644
--- a/analysis/webservice/algorithms/DataInBoundsSearch.py
+++ b/analysis/webservice/algorithms/DataInBoundsSearch.py
@@ -14,8 +14,10 @@
 # limitations under the License.
 
 
-from datetime import datetime
+import json
+import numpy
 
+from datetime import datetime
 from pytz import timezone
 
 from webservice.NexusHandler import nexus_handler
@@ -225,3 +227,14 @@ class DataInBoundsResult(NexusResults):
             rows.append(",".join(cols))
 
         return "\r\n".join(rows)
+
+    def toJson(self):
+        return json.dumps(self.results(), indent=4, cls=NpEncoder)
+
+class NpEncoder(json.JSONEncoder):
+    def default(self, obj):
+        if isinstance(obj, numpy.integer):
+            return int(obj)
+        if isinstance(obj, numpy.floating):
+            return float(obj)
+        return super(NpEncoder, self).default(obj)

Reply via email to