Skip to content

Commit 6977066

Browse files
authored
[MNT] add scripts (#1127)
* add scripts * update gitignore to ignore secrets * get openapi back in sync
1 parent 4ca473b commit 6977066

File tree

8 files changed

+1781
-1
lines changed

8 files changed

+1781
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.neurostuff_secrets
12
historical/
23

34
# node

store/backend/neurostore/openapi

store/scripts/clean_database.py

Lines changed: 901 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
from sqlalchemy import exists, or_
2+
from neurostore.models.data import Study, Analysis, Point, Image
3+
from neurostore.database import db
4+
5+
# Get studies without base_study_id that have analyses with points or images
6+
orphans_with_analyses = Study.query.filter(
7+
Study.base_study_id == None, # Studies without base_study_id
8+
or_(
9+
# Has analysis with points
10+
exists().where(
11+
Analysis.study_id == Study.id,
12+
exists().where(Point.analysis_id == Analysis.id)
13+
),
14+
# Has analysis with images
15+
exists().where(
16+
Analysis.study_id == Study.id,
17+
exists().where(Image.analysis_id == Analysis.id)
18+
)
19+
)
20+
).all()
21+
22+
print(f"Found {len(orphans_with_analyses)} orphan studies with analyses containing points or images:")
23+
for study in orphans_with_analyses:
24+
print(f"\nStudy ID: {study.id}")
25+
print(f"Name: {study.name}")
26+
27+
# Count points and images for this study
28+
point_count = db.session.query(Point)\
29+
.join(Analysis)\
30+
.filter(Analysis.study_id == study.id)\
31+
.count()
32+
33+
image_count = db.session.query(Image)\
34+
.join(Analysis)\
35+
.filter(Analysis.study_id == study.id)\
36+
.count()
37+
38+
print(f"Points: {point_count}")
39+
print(f"Images: {image_count}")
40+
41+
# Print identifiers if available
42+
if study.pmid:
43+
print(f"PMID: {study.pmid}")
44+
if study.doi:
45+
print(f"DOI: {study.doi}")
46+
if study.pmcid:
47+
print(f"PMCID: {study.pmcid}")

0 commit comments

Comments
 (0)