-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] add username and neurostore studyset script (#590)
* add username script * add script to create neurostore_studyset
- Loading branch information
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from auth0.v3.management.users import Users | ||
from neurosynth_compose.resources.users import User | ||
|
||
TOKEN = "INSERT TOKEN" | ||
|
||
|
||
user_endpoint = Users(domain="neurosynth-staging.us.auth0.com", token=TOKEN) | ||
|
||
result = user_endpoint.list(per_page=100)['users'] | ||
|
||
sql_users = [] | ||
for user in result: | ||
print(user['name']) | ||
sql_user = User.query.filter_by(external_id=user['user_id']).one_or_none() | ||
if sql_user is None: | ||
sql_user = User(external_id=user['user_id']) | ||
sql_user.name = user['name'] | ||
sql_users.append(sql_user) | ||
print(user['user_id']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from neurostore.models import BaseStudy, Studyset | ||
from sqlalchemy.orm import joinedload | ||
|
||
|
||
base_studies = BaseStudy.query.options( | ||
joinedload("versions") | ||
).filter_by(has_coordinates=True).all() | ||
|
||
neurostore_studyset = [] | ||
for bs in base_studies: | ||
if not bs.versions or not bs.has_coordinates: | ||
continue | ||
selected_study = bs.versions[0] | ||
|
||
for v in bs.versions[1:]: | ||
if not v.has_coordinates: | ||
continue | ||
|
||
if v.user is not None: | ||
if selected_study.user is None: | ||
selected_study = v | ||
else: | ||
if ( | ||
selected_study.updated_at or selected_study.created_at | ||
) <= (v.updated_at or v.created_at): | ||
selected_study = v | ||
neurostore_studyset.append(selected_study) | ||
|
||
ss = Studyset(name="Neurostore Studyset", description="aggregation of studies on the neurostore database. Ran periodically, may not represent the latest state of the database.", studies=neurostore_studyset) | ||
|
||
|