-
Notifications
You must be signed in to change notification settings - Fork 1
Sourcery refactored main branch #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,16 +94,15 @@ def retrieve_search_to_df(keyword): | |
| rsp = json.loads(rsp.text) | ||
| if rsp['hits']['total']==0: | ||
| return 'Nothing matching yet' | ||
| else: | ||
| df_search=pd.DataFrame.from_dict(rsp['hits']['hits']) | ||
| df_search=pd.concat([df_search['_source'].apply(pd.Series)['pennsieve'].apply(pd.Series)[['identifier']], | ||
| df_search[['_id']],#df_search[['_id','_score']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)[['name','description']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)['published'].apply(pd.Series)['status'], | ||
| ], axis=1) | ||
| df_search['link']= 'https://sparc.science/datasets/'+df_search['identifier'] | ||
| df_search=df_search[['_id','name','description','status','link']] | ||
| return df_search | ||
| df_search=pd.DataFrame.from_dict(rsp['hits']['hits']) | ||
| df_search=pd.concat([df_search['_source'].apply(pd.Series)['pennsieve'].apply(pd.Series)[['identifier']], | ||
| df_search[['_id']],#df_search[['_id','_score']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)[['name','description']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)['published'].apply(pd.Series)['status'], | ||
| ], axis=1) | ||
| df_search['link']= 'https://sparc.science/datasets/'+df_search['identifier'] | ||
| df_search=df_search[['_id','name','description','status','link']] | ||
| return df_search | ||
|
Comment on lines
-97
to
+105
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| ### Sending Email with the results | ||
| def send_email_alert_withtable(emaillist, keyword): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,10 @@ def loadMain(): | |
| """ | ||
| fileName = os.path.join(os.path.dirname(__file__), 'main.html') | ||
| try: | ||
| f = open(fileName, "r") | ||
| htmlText = f.read() | ||
| f.close() | ||
| with open(fileName, "r") as f: | ||
| htmlText = f.read() | ||
| except: | ||
| return html("We are sorry,there was an error ..., %s is not found" % fileName) | ||
| return html(f"We are sorry,there was an error ..., {fileName} is not found") | ||
|
Comment on lines
-21
to
+24
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return html(htmlText) | ||
|
|
||
|
|
||
|
|
@@ -59,7 +58,8 @@ def getSearch(request): | |
| """ | ||
| # initialise query run | ||
| summary = {} | ||
| url = 'https://scicrunch.org/api/1/elastic/SPARC_PortalDatasets_pr/_search?api_key='+api_key | ||
| url = f'https://scicrunch.org/api/1/elastic/SPARC_PortalDatasets_pr/_search?api_key={api_key}' | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| size = '200' | ||
| includes = ["item.keywords.keyword", | ||
| "item.name", | ||
|
|
@@ -131,7 +131,7 @@ def getSearch(request): | |
| ## extract from contributors | ||
| firsts = __find('_source.contributors.first.name', hit) | ||
| lasts = __find('_source.contributors.last.name', hit) | ||
| for name in [first+' '+last for first, last in (zip(firsts, lasts))]: | ||
| for name in [f'{first} {last}' for first, last in (zip(firsts, lasts))]: | ||
| if name not in summary['filters']['authors']: | ||
| summary['filters']['authors'][name] = [] | ||
| summary['filters']['authors'][name] += [idx] | ||
|
|
@@ -149,22 +149,28 @@ def getSearch(request): | |
| names += [str(__find('_source.item.name', hit))] | ||
| srtNames += [str(idx)] | ||
| # set hit | ||
| ht = {'url': 'https://sparc.science/datasets/'+idx, | ||
| 'banner': __find('_source.pennsieve.banner.uri', hit), | ||
| '_id': hit['_id'], | ||
| '_score': hit['_score'], | ||
| 'firstPublishedAt': __find('_source.pennsieve.firstPublishedAt.timestamp', hit), | ||
| 'updatedAt': __find('_source.pennsieve.updatedAt.timestamp', hit), | ||
| 'name': __find('_source.item.name', hit), | ||
| 'description': __find('_source.item.description', hit), | ||
| 'readme': __find('_source.item.readme.description', hit), | ||
| 'samples': __find('_source.item.statistics.samples.count', hit), | ||
| 'subjects': __find('_source.item.statistics.subjects.count', hit), | ||
| 'anatomy': __find('_source.anatomy.organ.name', hit), | ||
| 'organisms': __find('_source.organisms.primary.species.originalName', hit), | ||
| 'publication': __find('_source.item.published.boolean', hit), | ||
| 'techniques': __find('_source.item.techniques.keyword', hit), | ||
| } | ||
| ht = { | ||
| 'url': f'https://sparc.science/datasets/{idx}', | ||
| 'banner': __find('_source.pennsieve.banner.uri', hit), | ||
| '_id': hit['_id'], | ||
| '_score': hit['_score'], | ||
| 'firstPublishedAt': __find( | ||
| '_source.pennsieve.firstPublishedAt.timestamp', hit | ||
| ), | ||
| 'updatedAt': __find('_source.pennsieve.updatedAt.timestamp', hit), | ||
| 'name': __find('_source.item.name', hit), | ||
| 'description': __find('_source.item.description', hit), | ||
| 'readme': __find('_source.item.readme.description', hit), | ||
| 'samples': __find('_source.item.statistics.samples.count', hit), | ||
| 'subjects': __find('_source.item.statistics.subjects.count', hit), | ||
| 'anatomy': __find('_source.anatomy.organ.name', hit), | ||
| 'organisms': __find( | ||
| '_source.organisms.primary.species.originalName', hit | ||
| ), | ||
| 'publication': __find('_source.item.published.boolean', hit), | ||
| 'techniques': __find('_source.item.techniques.keyword', hit), | ||
| } | ||
|
|
||
| if 'highlight' in hit: | ||
| ht['highlight'] = {} | ||
| for type, value in hit['highlight'].items(): | ||
|
|
@@ -199,7 +205,7 @@ def __getSuggestions(query, limit): | |
| # get possible correction | ||
| correction = __getCorrection(query) | ||
| # get suggestion from SciGraph | ||
| url = 'https://scicrunch.org/api/1/scigraph/vocabulary/suggestions/'+query | ||
| url = f'https://scicrunch.org/api/1/scigraph/vocabulary/suggestions/{query}' | ||
|
Comment on lines
-202
to
+208
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| params = {'api_key': api_key, 'limit': limit} | ||
| rsp = requests.get(url, params=params) | ||
| # return the correction and suggestions | ||
|
|
@@ -223,7 +229,7 @@ def __getAutoComplete_sc(query, limit, verbose): | |
| """ | ||
| To get autocomplete as a list data type. | ||
| """ | ||
| url = 'https://scicrunch.org/api/1/scigraph/vocabulary/autocomplete/'+query | ||
| url = f'https://scicrunch.org/api/1/scigraph/vocabulary/autocomplete/{query}' | ||
|
Comment on lines
-226
to
+232
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| params = {'api_key': api_key, 'limit': limit, 'searchSynonyms': 'true', | ||
| 'searchAbbreviations': 'false', 'searchAcronyms': 'false', | ||
| 'includeDeprecated': 'false'} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -89,17 +89,16 @@ def retrieve_search_to_df(keyword): | |
| rsp = json.loads(rsp.text) | ||
| if rsp['hits']['total']==0: | ||
| return 'Nothing matching yet' | ||
| else: | ||
| df_search=pd.DataFrame.from_dict(rsp['hits']['hits']) | ||
| df_search=pd.concat([ | ||
| df_search['_source'].apply(pd.Series)['pennsieve'].apply(pd.Series)[['identifier']], | ||
| df_search[['_id','_score']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)[['name','description']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)['published'].apply(pd.Series)['status'], | ||
| ], axis=1) | ||
| df_search['link']= 'https://sparc.science/datasets/'+df_search['identifier'] | ||
|
|
||
| return df_search | ||
| df_search=pd.DataFrame.from_dict(rsp['hits']['hits']) | ||
| df_search=pd.concat([ | ||
| df_search['_source'].apply(pd.Series)['pennsieve'].apply(pd.Series)[['identifier']], | ||
| df_search[['_id','_score']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)[['name','description']], | ||
| df_search['_source'].apply(pd.Series)['item'].apply(pd.Series)['published'].apply(pd.Series)['status'], | ||
| ], axis=1) | ||
| df_search['link']= 'https://sparc.science/datasets/'+df_search['identifier'] | ||
|
|
||
| return df_search | ||
|
Comment on lines
-92
to
+101
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| # Sending Email with the results | ||
| def send_email_alert_withtable(emaillist, keyword): | ||
| msg = MIMEMultipart() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
plot_most_freq_search_termrefactored with the following changes:use-fstring-for-concatenation)