climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lewi...@apache.org
Subject [1/2] climate git commit: CLIMATE-388 Make UI backend parameters endpoint more RESTful
Date Wed, 17 Jan 2018 02:05:22 GMT
Repository: climate
Updated Branches:
  refs/heads/master a9fbf74d5 -> 47940c4e1


CLIMATE-388 Make UI backend parameters endpoint more RESTful


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/410d8dc5
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/410d8dc5
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/410d8dc5

Branch: refs/heads/master
Commit: 410d8dc566a5cf3dd263694b4a585d22d1128e4d
Parents: 4cf79f3
Author: Michael Anderson <michaelanderson@Michaels-iMac.local>
Authored: Fri Jan 5 13:24:43 2018 -0500
Committer: Michael Anderson <michaelanderson@Michaels-iMac.local>
Committed: Fri Jan 5 13:24:43 2018 -0500

----------------------------------------------------------------------
 ocw-ui/backend/rcmed_helpers.py                 | 71 ++++++++++----------
 .../app/scripts/controllers/rcmedselection.js   |  4 +-
 .../test/spec/controllers/rcmedselection.js     |  8 +--
 3 files changed, 41 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/410d8dc5/ocw-ui/backend/rcmed_helpers.py
----------------------------------------------------------------------
diff --git a/ocw-ui/backend/rcmed_helpers.py b/ocw-ui/backend/rcmed_helpers.py
index 32e1af8..3c66007 100644
--- a/ocw-ui/backend/rcmed_helpers.py
+++ b/ocw-ui/backend/rcmed_helpers.py
@@ -15,19 +15,19 @@
 #  limitations under the License.
 #
 
-''' Services for interacting with NASA JPL's Regional Climate Model Evaluation Database.
'''
-
-import ocw.data_source.rcmed as rcmed
+""" Services for interacting with NASA JPL's Regional Climate Model Evaluation Database.
"""
 
+import requests
 from bottle import Bottle, request, response
 
-import requests
+import ocw.data_source.rcmed as rcmed
 
 rcmed_app = Bottle()
 
-@rcmed_app.route('/datasets/')
+
+@rcmed_app.get('/datasets/')
 def get_observation_dataset_data():
-    ''' Return a list of dataset information from JPL's RCMED.
+    """ Return a list of dataset information from JPL's RCMED.
 
     **Example Return JSON Format**
 
@@ -42,20 +42,21 @@ def get_observation_dataset_data():
             },
             ...
         ]
-    '''
-    r = requests.get('http://rcmes.jpl.nasa.gov/query-api/datasets.php')
+    """
+    result = requests.get('http://rcmes.jpl.nasa.gov/query-api/datasets.php')
 
-    if (request.query.callback):
-        return "%s(%s)" % (request.query.callback, r.text)
-    return r.text
+    if hasattr(request.query, 'callback'):
+        return "%s(%s)" % (request.query.callback, result.text)
+    return result.text
 
-@rcmed_app.route('/parameters/')
-def get_dataset_parameters():
-    ''' Return dataset specific parameter information from JPL's RCMED.
+
+@rcmed_app.get('/parameters/dataset/<name>')
+def get_dataset_parameters(name):
+    """ Return dataset specific parameter information from JPL's RCMED.
 
     **Example Call Format**
 
-    .. sourcecode:: javascript
+    .. sourcecode:: text
 
         /parameters/?dataset=<dataset's short name>
 
@@ -73,17 +74,18 @@ def get_dataset_parameters():
             }
         ]
 
-    '''
-    url = 'http://rcmes.jpl.nasa.gov/query-api/parameters.php?dataset=' + request.query.dataset
-    r = requests.get(url)
+    """
+
+    url = 'http://rcmes.jpl.nasa.gov/query-api/parameters.php?dataset=' + name
+    result = requests.get(url)
 
-    if (request.query.callback):
-        return "%s(%s)" % (request.query.callback, r.text)
-    return r.text
+    if hasattr(request.query, 'callback'):
+        return "%s(%s)" % (request.query.callback, result.text)
+    return result.text
 
 
 def extract_bounds(parameter):
-    ''' This will take a parameter dictionary and return the spatial and temporal bounds.
+    """ This will take a parameter dictionary and return the spatial and temporal bounds.
 
     :param parameter: Single parameter that is returned from rcmed.get_parameters_metadata().
     :type parameter: dictionary:
@@ -97,11 +99,9 @@ def extract_bounds(parameter):
               "lon_max": 179.75,
               "lon_min": -179.75
             }
-    '''
-    bounds_data = {}
-    bounds_data['start_date'] = str(parameter['start_date'])
-    bounds_data['end_date'] = str(parameter['end_date'])
-    spatial_bounds = parameter['bounding_box'].replace('(','').replace(')','')
+    """
+    bounds_data = {'start_date': str(parameter['start_date']), 'end_date': str(parameter['end_date'])}
+    spatial_bounds = parameter['bounding_box'].replace('(', '').replace(')', '')
     spatial_bounds = spatial_bounds.split(',')
     # spatial_bounds is in format:
     # [<lat_max>, <lon_max>, <lat_min>, <lon_max>, <lat_min>,
<lon_min>, <lat_max>, <lon_min>]
@@ -110,18 +110,18 @@ def extract_bounds(parameter):
     bounds_data['lat_min'] = float(spatial_bounds[2])
     bounds_data['lon_max'] = float(spatial_bounds[1])
     bounds_data['lon_min'] = float(spatial_bounds[5])
-    param_id =str(parameter['parameter_id'])
+    param_id = str(parameter['parameter_id'])
     return param_id, bounds_data
 
 
-@rcmed_app.route('/parameters/bounds/')
-@rcmed_app.route('/parameters/bounds')
+@rcmed_app.get('/parameters/bounds/')
+@rcmed_app.get('/parameters/bounds')
 def get_parameters_bounds():
-    ''' Return temporal and spatial bounds metadata for all of JPL's RCMED parameters.
+    """ Return temporal and spatial bounds metadata for all of JPL's RCMED parameters.
 
     **Example Call Format**
 
-    .. sourcecode:: javascript
+    .. sourcecode:: text
 
         /parameters/bounds/
 
@@ -148,19 +148,18 @@ def get_parameters_bounds():
           }
         }
 
-    '''
+    """
     parameter_bounds = {}
     raw_parameters = rcmed.get_parameters_metadata()
     for parameter in raw_parameters:
-        if parameter['bounding_box'] != None:
+        if parameter['bounding_box'] is not None:
             param_id, bounds_data = extract_bounds(parameter)
             parameter_bounds[param_id] = bounds_data
 
-
     return parameter_bounds
 
 
 @rcmed_app.hook('after_request')
 def enable_cors():
-    ''' Allow Cross-Origin Resource Sharing for all URLs. '''
+    """ Allow Cross-Origin Resource Sharing for all URLs. """
     response.headers['Access-Control-Allow-Origin'] = '*'

http://git-wip-us.apache.org/repos/asf/climate/blob/410d8dc5/ocw-ui/frontend/app/scripts/controllers/rcmedselection.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/app/scripts/controllers/rcmedselection.js b/ocw-ui/frontend/app/scripts/controllers/rcmedselection.js
index a3b3801..81d7d21 100644
--- a/ocw-ui/frontend/app/scripts/controllers/rcmedselection.js
+++ b/ocw-ui/frontend/app/scripts/controllers/rcmedselection.js
@@ -81,9 +81,9 @@ angular.module('ocwUiApp')
       };
 
       $scope.dataSelectUpdated = function() {
-        var urlString = $rootScope.baseURL + '/rcmed/parameters/?dataset=' +
+        var urlString = $rootScope.baseURL + '/rcmed/parameters/dataset/' +
                         $scope.datasetSelection["shortname"] +
-                        "&callback=JSON_CALLBACK";
+                        "?callback=JSON_CALLBACK";
         $http.jsonp(urlString)
           .success(function(data) {
             $scope.retrievedObsParams = data;

http://git-wip-us.apache.org/repos/asf/climate/blob/410d8dc5/ocw-ui/frontend/test/spec/controllers/rcmedselection.js
----------------------------------------------------------------------
diff --git a/ocw-ui/frontend/test/spec/controllers/rcmedselection.js b/ocw-ui/frontend/test/spec/controllers/rcmedselection.js
index 97011c7..ba041aa 100644
--- a/ocw-ui/frontend/test/spec/controllers/rcmedselection.js
+++ b/ocw-ui/frontend/test/spec/controllers/rcmedselection.js
@@ -84,9 +84,9 @@ describe('Controller: RcmedSelectionCtrl', function () {
       scope.datasetSelection = {shortname: 'TRMM'}
 
       // Test return with only single parameter
-      $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/parameters/?dataset=' +
+      $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/parameters/dataset/' +
                   scope.datasetSelection['shortname'] +
-                  '&callback=JSON_CALLBACK').
+                  '?callback=JSON_CALLBACK').
              respond(200, ['pcp']);
       scope.dataSelectUpdated();
       $httpBackend.flush();
@@ -94,9 +94,9 @@ describe('Controller: RcmedSelectionCtrl', function () {
       expect(scope.parameterSelection).toEqual('pcp');
 
       // Test return with multiple parameters
-      $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/parameters/?dataset=' +
+      $httpBackend.expectJSONP($rootScope.baseURL + '/rcmed/parameters/dataset/' +
                   scope.datasetSelection['shortname'] +
-                  '&callback=JSON_CALLBACK').
+                  '?callback=JSON_CALLBACK').
              respond(200, ['pcp', 'pcp2']);
       scope.dataSelectUpdated();
       $httpBackend.flush();


Mime
View raw message