Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
44bde70b
Commit
44bde70b
authored
Dec 22, 2016
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove redundant qtype test (in main and in extractDataCustom)
parent
aecb7e86
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
31 deletions
+18
-31
extractDataCustom.py
services/db_to_tina_api/extractDataCustom.py
+17
-24
main.py
services/main.py
+1
-7
No files found.
services/db_to_tina_api/extractDataCustom.py
View file @
44bde70b
...
...
@@ -9,9 +9,9 @@ from traceback import format_tb
from
.converter
import
CountryConverter
if
__package__
==
"services.db_to_tina_api"
:
from
services.tools
import
mlog
,
restparse
from
services.tools
import
mlog
else
:
from
tools
import
mlog
,
restparse
from
tools
import
mlog
whoswhofilters_to_sqlnames
=
{
...
...
@@ -48,37 +48,34 @@ class MyExtractor:
else
:
return
cooc
*
cooc
/
float
(
occ1
*
occ2
)
def
getScholarsList
(
self
,
qtype
,
queryargs
):
def
getScholarsList
(
self
,
qtype
,
filter_dict
):
"""
select one or more scholars to map in the graph
returns a dict of scholar's uids
method1 (
case unique_id
)
-
unique_id
defines our starting point (scholar_0)
method1 (
qtype "uid"
)
-
filter_dict['unique_id']
defines our starting point (scholar_0)
- we follow all 2 step coupling paths (scholar_0 <=> keyword_X <=> scholar_i)
method2 (case filter constraints)
- in progress
method2 (qtype "filters" constraints)
- filter_thing is a dict of all the whoswho filters
ex: {'countries':[France,USA], 'keywords':[blabla]}
- they are converted to WHERE-clauses in an SQL query
"""
scholar_array
=
{}
sql_query
=
None
# debug
#
mlog("DEBUG", "=> getScholarsList.qtype", qtype)
# mlog("DEBUG", "=> getScholarsList.queryargs", queryargs
)
mlog
(
"DEBUG"
,
"=> getScholarsList.qtype"
,
qtype
)
mlog
(
"DEBUG"
,
"=> getScholarsList.filter_dict"
,
filter_dict
)
try
:
if
qtype
==
"u
nique_
id"
:
if
qtype
==
"uid"
:
# remove quotes from id
unique_id
=
sub
(
r'^"|"$'
,
''
,
queryargs
)
unique_id
=
sub
(
r'^"|"$'
,
''
,
filter_dict
[
'unique_id'
]
)
# old way
# sql1="SELECT * FROM scholars WHERE doors_uid='"+unique_id+"'" ## <= starting point (scholar_0)
# sql2 = "SELECT * FROM scholars2terms where term_id="+keywords_id ## <= coupling edges (scholar_0 <=> keyword_X <=> scholar_i)
# new way (using scholars<=>kw map to do only one sql query)
# we use the sch_kw table (scholars <=> kw map)
sql_query
=
"""
SELECT
neighbors_by_kw.uid,
...
...
@@ -120,13 +117,11 @@ class MyExtractor:
# debug
# mlog("DEBUG", "getScholarsList<==scholar_array", scholar_array)
elif
qtype
==
"filter"
:
elif
qtype
==
"filter
s
"
:
sql_query
=
None
filter_dict
=
restparse
(
queryargs
)
# debug
mlog
(
"DEBUG"
,
"filter: REST query is"
,
filter_dict
)
mlog
(
"DEBUG"
,
"filter
s
: REST query is"
,
filter_dict
)
if
"query"
in
filter_dict
and
filter_dict
[
"query"
]
==
"*"
:
# query is "*" <=> all scholars
...
...
@@ -139,9 +134,7 @@ class MyExtractor:
# query is a set of filters like: key <=> array of values
# (expressed as rest parameters: "keyA[]=valA1&keyB[]=valB1&keyB[]=valB2")
# 1. we receive the original request.query_string
# and restparse rebuilds the corresponding dict
# 1. we receive it as a dict of arrays
# 2. we map it to an sql conjunction of alternatives
# ==> WHERE colA IN ("valA1") AND colB IN ("valB1", "valB2")
...
...
services/main.py
View file @
44bde70b
...
...
@@ -155,13 +155,7 @@ def api_main():
db
=
MySQL
(
config
[
'SQL_HOST'
])
if
'qtype'
in
request
.
args
:
if
request
.
args
[
'qtype'
]
==
"filters"
:
# all the other args are a series of constraints for filtering
# ex: qtype=filters&keywords[]=complex%20networks&keywords[]=complexity%20theory&countries[]=France&countries[]=USA
scholars
=
db
.
getScholarsList
(
"filter"
,
restparse
(
request
.
query_string
.
decode
()))
else
:
unique_id
=
request
.
args
[
'unique_id'
]
scholars
=
db
.
getScholarsList
(
"unique_id"
,
unique_id
)
scholars
=
db
.
getScholarsList
(
request
.
args
[
'qtype'
],
restparse
(
request
.
query_string
.
decode
()))
else
:
raise
TypeError
(
"API query is missing qtype (should be 'filters' or 'uid')"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment