-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #931 from neuroscout/ext_count
add distinct extractor route
- Loading branch information
Showing
4 changed files
with
59 additions
and
4 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
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
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
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,33 @@ | ||
""" Miscelanous tools """ | ||
|
||
from .. import models as ms | ||
|
||
|
||
def distinct_extractors(count=True, active=True): | ||
""" Tool to count unique number of predictors for each Dataset/Task """ | ||
active_datasets = ms.Dataset.query.filter_by(active=active) | ||
superset = set([v for (v, ) in ms.Predictor.query.filter_by(active=True).filter( | ||
ms.Predictor.dataset_id.in_( | ||
active_datasets.with_entities('id'))).join( | ||
ms.ExtractedFeature).distinct( | ||
'extractor_name').values('extractor_name')]) | ||
|
||
res = {} | ||
|
||
for en in superset: | ||
for ds in active_datasets: | ||
for t in ds.tasks: | ||
name = f"{ds.name}_{t.name}" | ||
if name not in res: | ||
res[name] = {} | ||
preds = ms.Predictor.query.filter_by( | ||
dataset_id=ds.id, active=True).join( | ||
ms.ExtractedFeature).filter_by( | ||
extractor_name=en).distinct('feature_name') | ||
if count: | ||
r = preds.count() | ||
else: | ||
r = list(preds.values('name')) | ||
res[name][en] = r | ||
|
||
return res |