Skip to content

Commit

Permalink
[ENH] add username and neurostore studyset script (#590)
Browse files Browse the repository at this point in the history
* add username script

* add script to create neurostore_studyset
  • Loading branch information
jdkent authored Sep 19, 2023
1 parent 6d33105 commit de0d47d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
19 changes: 19 additions & 0 deletions compose/scripts/add_usernames.py
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'])
31 changes: 31 additions & 0 deletions store/scripts/create_neurostore_studyset.py
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)


0 comments on commit de0d47d

Please sign in to comment.