Skip to content

Commit 3c51281

Browse files
committed
use db for ingestion, and remove extra imports
1 parent f14f343 commit 3c51281

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

store/neurostore/ingest/extracted_features.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,9 @@
22

33
import json
44
import os.path as op
5-
import re
65
from pathlib import Path
76
import hashlib
8-
9-
import numpy as np
10-
import pandas as pd
11-
import requests
12-
from scipy import sparse
137
from dateutil.parser import parse as parse_date
14-
from sqlalchemy import or_
158

169
from neurostore.database import db
1710
from neurostore.models import (
@@ -22,15 +15,15 @@
2215
)
2316

2417

25-
def ingest_feature(feature_directory, session):
18+
def ingest_feature(feature_directory):
2619
"""Ingest demographics data into the database."""
2720
# read pipeline_info.json from the base feature directory
2821
with open(op.join(feature_directory, "pipeline_info.json")) as f:
2922
pipeline_info = json.load(f)
3023

3124
# search if there is an existing pipeline with the same name and version
3225
pipeline = (
33-
session.query(Pipeline)
26+
db.session.query(Pipeline)
3427
.filter(
3528
Pipeline.name == pipeline_info["name"],
3629
Pipeline.version == pipeline_info["version"],
@@ -48,7 +41,7 @@ def ingest_feature(feature_directory, session):
4841
pubget_compatible=pipeline_info.get("pubget_compatible", False),
4942
derived_from=pipeline_info.get("derived_from", None),
5043
)
51-
session.add(pipeline)
44+
db.session.add(pipeline)
5245

5346
# search within the pipeline and see if there are any existing pipeline configs
5447
# that match the "arguements" field in the pipeline_info.json
@@ -57,7 +50,7 @@ def ingest_feature(feature_directory, session):
5750
json.dumps(pipeline_info["arguments"]).encode()
5851
).hexdigest()
5952
pipeline_config = (
60-
session.query(PipelineConfig)
53+
db.session.query(PipelineConfig)
6154
.filter(
6255
PipelineConfig.pipeline_id == pipeline.id,
6356
PipelineConfig.config_hash == config_hash,
@@ -71,7 +64,7 @@ def ingest_feature(feature_directory, session):
7164
config=pipeline_info["arguments"],
7265
config_hash=config_hash,
7366
)
74-
session.add(pipeline_config)
67+
db.session.add(pipeline_config)
7568

7669
# create a new pipeline run
7770
pipeline_run = PipelineRun(
@@ -104,7 +97,7 @@ def ingest_feature(feature_directory, session):
10497
)
10598
)
10699

107-
session.add(pipeline_run)
108-
session.add_all(pipeline_run_results)
100+
db.session.add(pipeline_run)
101+
db.session.add_all(pipeline_run_results)
109102

110-
session.commit()
103+
db.session.commit()

store/neurostore/tests/test_ingestion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ def test_ingest_neuroquery(ingest_neuroquery, session):
1616

1717

1818
def test_ingest_features(create_demographic_features, session):
19-
ingest_feature(create_demographic_features, session)
19+
ingest_feature(create_demographic_features)

0 commit comments

Comments
 (0)