From a05c51539576a7949eb2a9e422af48fa43dc93e6 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Thu, 14 Sep 2017 15:46:03 -0700 Subject: [PATCH 1/5] update schema to take user ratings of files --- dockereve-master/eve-app/settings.py | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/dockereve-master/eve-app/settings.py b/dockereve-master/eve-app/settings.py index 463e053..f28a814 100644 --- a/dockereve-master/eve-app/settings.py +++ b/dockereve-master/eve-app/settings.py @@ -561,6 +561,7 @@ 'RESOURCE_METHODS': ['GET', 'POST'], 'ITEM_METHODS': ['GET'], 'X_DOMAINS': '*', + 'X_HEADERS': ['Authorization', 'Content-Type'], 'DOMAIN': { 'bold': { 'item_title': 'bold', @@ -575,6 +576,39 @@ } } +settings['DOMAIN']['rating'] = {} +settings['DOMAIN']['rating']['schema'] = { + 'rating': { + 'type': 'string', + 'required': True + }, + 'name': { + 'type': 'string', + 'required': False + }, + 'comment': { + 'type': 'string', + 'required': False + }, + 'md5sum': { + 'type': 'string', + 'required': True + } +} + +settings['DOMAIN']['rating_counts'] = { + 'datasource':{ + 'source' : 'rating', + 'aggregation' : { + 'pipeline': [ + {"$match": {"md5sum": "$value"}}, + {"$unwind": "$rating"}, + {"$group": {"_id": "$rating", "count": {"$sum": 1}}}, + ], + } + } +} + settings['DOMAIN']['bold']['schema'] = deepcopy(bold_iqms_schema) settings['DOMAIN']['bold']['schema'].update( From ad69bece419278e09d2962b45568ed629b12011a Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Wed, 8 Nov 2017 23:21:04 -0800 Subject: [PATCH 2/5] move rating into bold schema, still need to update aggregate function --- dockereve-master/eve-app/settings.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dockereve-master/eve-app/settings.py b/dockereve-master/eve-app/settings.py index f28a814..82c5d96 100644 --- a/dockereve-master/eve-app/settings.py +++ b/dockereve-master/eve-app/settings.py @@ -576,8 +576,7 @@ } } -settings['DOMAIN']['rating'] = {} -settings['DOMAIN']['rating']['schema'] = { +rating_schema = { 'rating': { 'type': 'string', 'required': True @@ -622,7 +621,12 @@ 'type': 'dict', 'required': True, 'schema': deepcopy(prov_schema) - } + }, + 'rating': { + 'type': 'dict', + 'required': False + 'schema': deepcopy(rating_schema) + }, } ) From 7ea1749e936e48ece842047bddc41c0ad6a12edd Mon Sep 17 00:00:00 2001 From: oesteban Date: Tue, 13 Mar 2018 11:53:51 -0700 Subject: [PATCH 3/5] fix syntax --- dockereve-master/eve-app/settings.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dockereve-master/eve-app/settings.py b/dockereve-master/eve-app/settings.py index 47562ba..5d8e469 100644 --- a/dockereve-master/eve-app/settings.py +++ b/dockereve-master/eve-app/settings.py @@ -595,9 +595,9 @@ } settings['DOMAIN']['rating_counts'] = { - 'datasource':{ - 'source' : 'rating', - 'aggregation' : { + 'datasource': { + 'source': 'rating', + 'aggregation': { 'pipeline': [ {"$match": {"md5sum": "$value"}}, {"$unwind": "$rating"}, @@ -624,7 +624,7 @@ }, 'rating': { 'type': 'dict', - 'required': False + 'required': False, 'schema': deepcopy(rating_schema) }, } @@ -651,9 +651,13 @@ 'type': 'dict', 'required': True, 'schema': deepcopy(prov_schema) - } + }, + 'rating': { + 'type': 'dict', + 'required': False, + 'schema': deepcopy(rating_schema) + }, } ) settings['DOMAIN']['T2w']['schema'] = deepcopy(settings['DOMAIN']['T1w']['schema']) - From 8b88e1616a3d3bd62a430c72f0ff5b64ebd00b19 Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Wed, 21 Mar 2018 15:58:44 -0700 Subject: [PATCH 4/5] add test for rating and rating aggregation --- dockereve-master/eve-app/settings.py | 1 - test/rating/validData/sub-50137_rating.json | 4 +++ test/rating/validData/sub-50137_rating_1.json | 4 +++ test/rating/validData/sub-50137_rating_2.json | 4 +++ test/rating/validData/sub-50137_rating_3.json | 4 +++ test/testGetPost.py | 25 +++++++++++++++++++ 6 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 test/rating/validData/sub-50137_rating.json create mode 100644 test/rating/validData/sub-50137_rating_1.json create mode 100644 test/rating/validData/sub-50137_rating_2.json create mode 100644 test/rating/validData/sub-50137_rating_3.json diff --git a/dockereve-master/eve-app/settings.py b/dockereve-master/eve-app/settings.py index a7c9a3f..0cf73a9 100644 --- a/dockereve-master/eve-app/settings.py +++ b/dockereve-master/eve-app/settings.py @@ -608,7 +608,6 @@ } } - settings['DOMAIN']['bold']['schema'] = deepcopy(bold_iqms_schema) settings['DOMAIN']['bold']['schema'].update( { diff --git a/test/rating/validData/sub-50137_rating.json b/test/rating/validData/sub-50137_rating.json new file mode 100644 index 0000000..239f672 --- /dev/null +++ b/test/rating/validData/sub-50137_rating.json @@ -0,0 +1,4 @@ +{ + "rating": "good", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/rating/validData/sub-50137_rating_1.json b/test/rating/validData/sub-50137_rating_1.json new file mode 100644 index 0000000..239f672 --- /dev/null +++ b/test/rating/validData/sub-50137_rating_1.json @@ -0,0 +1,4 @@ +{ + "rating": "good", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/rating/validData/sub-50137_rating_2.json b/test/rating/validData/sub-50137_rating_2.json new file mode 100644 index 0000000..239f672 --- /dev/null +++ b/test/rating/validData/sub-50137_rating_2.json @@ -0,0 +1,4 @@ +{ + "rating": "good", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/rating/validData/sub-50137_rating_3.json b/test/rating/validData/sub-50137_rating_3.json new file mode 100644 index 0000000..3f4b479 --- /dev/null +++ b/test/rating/validData/sub-50137_rating_3.json @@ -0,0 +1,4 @@ +{ + "rating": "bad", + "md5sum": "57cd35190da3c813a3c3dadccd8a4ad7" +} diff --git a/test/testGetPost.py b/test/testGetPost.py index a6003ec..ca37f23 100644 --- a/test/testGetPost.py +++ b/test/testGetPost.py @@ -9,6 +9,7 @@ # test data directory boldPattern = os.path.join('test/bold/validData', '*.json') T1wPattern = os.path.join('test/T1w/validData', '*.json') +ratingPattern = os.path.join('test/rating/validData', '*.json') # missing field data directory boldMissingPattern = os.path.join('test/bold/missingField', '*.json') @@ -35,6 +36,8 @@ def getRequest(post_resp, url): numOfTestData = 84 urlBold = "http://0.0.0.0:80/api/v1/bold" urlT1w = "http://0.0.0.0:80/api/v1/T1w" +urlRating = "http://0.0.0.0:80/api/v1/rating" +urlRatingCounts = 'http://0.0.0.0:80/api/v1/rating_counts?{}' codeForInvalid = 422 @@ -208,6 +211,28 @@ def test_09_failedAuth(self): headers=header) self.assertTrue(postResponse.status_code == 401) # **************** + def test_10_ratingDataValid(self): + for file_name in glob(ratingPattern): + with open(file_name) as fp: + input_data = json.load(fp) + + # 2. POST request + post_resp = requests.post( + urlRating, data=json.dumps(input_data), + headers=authenticated_header) + self.assertTrue(post_resp.raise_for_status() is None) + + # retrive counts of ratings we just submitted + get_resp = requests.get( + urlRatingCounts.format('aggregate={"$value":"57cd35190da3c813a3c3dadccd8a4ad7"}'), + headers=authenticated_header + ) + data = get_resp.json() + for elem in data['_items']: + if elem['_id'] == "good": + self.assertTrue(elem['count'] == 3) + if elem['_id'] == "bad": + self.assertTrue(elem['count'] == 1) if __name__ == '__main__': logging.basicConfig(stream=sys.stderr) From e17b8567464184b6ddaed163f4dbf0d7d96dac0f Mon Sep 17 00:00:00 2001 From: Ross Blair Date: Wed, 21 Mar 2018 16:52:01 -0700 Subject: [PATCH 5/5] move rating schema to top level of settings dict --- dockereve-master/eve-app/settings.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/dockereve-master/eve-app/settings.py b/dockereve-master/eve-app/settings.py index 9e783ad..1eff30e 100644 --- a/dockereve-master/eve-app/settings.py +++ b/dockereve-master/eve-app/settings.py @@ -593,6 +593,11 @@ 'required': True } } +settings['DOMAIN']['rating'] ={ + 'type': 'dict', + 'required': False, + 'schema': deepcopy(rating_schema) +} settings['DOMAIN']['rating_counts'] = { 'datasource': { @@ -651,11 +656,6 @@ 'required': True, 'schema': deepcopy(prov_schema) }, - 'rating': { - 'type': 'dict', - 'required': False, - 'schema': deepcopy(rating_schema) - }, } )