Skip to content

Commit 0c51ad9

Browse files
committed
Update dm to use classification
1 parent 5182fa1 commit 0c51ad9

File tree

10 files changed

+75
-26
lines changed

10 files changed

+75
-26
lines changed

api/placer.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,16 @@ def check(self):
242242
job = Job.get(self.context.get('job_id'))
243243
input_names = [{'name': v.name} for v in job.inputs.itervalues()]
244244

245-
measurement = self.metadata.get(self.container_type, {}).pop('measurement', None)
245+
classification = self.metadata.get(self.container_type, {}).pop('measurement', None)
246246
info = self.metadata.get(self.container_type,{}).pop('metadata', None)
247247
modality = self.metadata.get(self.container_type, {}).pop('instrument', None)
248-
if measurement or info or modality:
248+
if classification or info or modality:
249249
files_ = self.metadata[self.container_type].get('files', [])
250250
files_ += input_names
251251
for f in files_:
252-
if measurement:
253-
f['measurements'] = [measurement]
252+
if classification:
253+
custom = {'custom': [classification]}
254+
f['classification'] = custom
254255
if info:
255256
f['info'] = info
256257
if modality:
@@ -502,7 +503,7 @@ def finalize(self):
502503

503504
# OPPORTUNITY: packfile endpoint could be extended someday to take additional metadata.
504505
'modality': None,
505-
'measurements': [],
506+
'classification': {},
506507
'tags': [],
507508
'info': {},
508509

api/upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def process_upload(request, strategy, container_type=None, id_=None, origin=None
119119

120120
'type': None,
121121
'modality': None,
122-
'measurements': [],
122+
'classification': {},
123123
'tags': [],
124124
'info': {}
125125
}

bin/database.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from api.jobs import gears
1515
from api.types import Origin
1616

17-
CURRENT_DATABASE_VERSION = 21 # An int that is bumped when a new schema change is made
17+
CURRENT_DATABASE_VERSION = 22 # An int that is bumped when a new schema change is made
1818

1919
def get_db_version():
2020

@@ -636,6 +636,58 @@ def dm_v2_updates(cont_list, cont_name):
636636
dm_v2_updates(config.db.acquisitions.find(query), 'acquisitions')
637637

638638

639+
def upgrade_to_22():
640+
"""
641+
Change file `measurement` field to `classification` map
642+
Place all measurements in `custom` key on map
643+
"""
644+
645+
def update_project_template(template):
646+
for a in template.get('acquisitions', []):
647+
new_file_templates = []
648+
for f in a.get('files', []):
649+
if f.get('measurement'):
650+
measurements = f.pop('measurement')
651+
f['classification'] = {'custom': measurement}
652+
653+
return template
654+
655+
656+
def change_to_classification(cont_list, cont_name):
657+
for container in cont_list:
658+
659+
if cont_name == 'projects' and container.get('template'):
660+
new_template = update_project_template(json.loads(container.get('template')))
661+
update['$set'] = {'template': new_template}
662+
663+
query = {'_id': container['_id']}
664+
update = {}
665+
666+
files = container.get('files')
667+
if files is not None:
668+
updated_files = []
669+
for file_ in files:
670+
if 'measurements' in file_:
671+
measurements = file_.pop('measurements', [])
672+
custom = {'custom': measurements}
673+
file_['classification'] = custom
674+
675+
updated_files.append(file_)
676+
if update.get('$set'):
677+
update['$set']['files'] = updated_files
678+
else:
679+
update['$set'] = {'files': updated_files}
680+
681+
result = config.db[cont_name].update_one(query, update)
682+
683+
query = {'files.measurements': { '$exists': True}}
684+
685+
change_to_classification(config.db.collections.find(query), 'collections')
686+
change_to_classification(config.db.projects.find(query), 'projects')
687+
change_to_classification(config.db.sessions.find(query), 'sessions')
688+
change_to_classification(config.db.acquisitions.find(query), 'acquisitions')
689+
690+
639691
def upgrade_schema():
640692
"""
641693
Upgrades db to the current schema version

raml/examples/file_info_list.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"hash": "v0-sha384-12188e00a26650b2baa3f0195337dcf504f4362bb2136eef0cdbefb57159356b1355a0402fca0ab5ab081f21c305e5c2",
99
"name": "cortical_surface_right_hemisphere.obj",
1010
"tags": [],
11-
"measurements": [],
11+
"classification": {},
1212
"modified": "2016-10-18T15:26:35.701000+00:00",
1313
"instrument": null,
1414
"size": 21804112,
@@ -23,7 +23,7 @@
2323
"hash": "v0-sha384-12188e00a26650b2baa3f0195337dcf504f4362bb2136eef0cdbefb57159356b1355a0402fca0ab5ab081f21c305e5c2",
2424
"name": "cortical_surface_right_hemisphere.obj",
2525
"tags": [],
26-
"measurements": [],
26+
"classification": {},
2727
"modified": "2016-10-18T17:45:17.776000+00:00",
2828
"instrument": null,
2929
"metadata": {},

raml/examples/output/acquisition-list.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"name": "Admin Import"
1010
},
1111
"mimetype": "application/zip",
12-
"measurements": [],
12+
"classification": {},
1313
"hash": "v0-sha384-dd3c97bfe0ad1fcba75ae6718c6e81038c59af4f447f5db194d52732efa4f955b28455db02eb64cad3e4e55f11e3679f",
1414
"name": "4784_1_1_localizer_dicom.zip",
1515
"tags": [],
@@ -49,7 +49,7 @@
4949
"name": "Admin Import"
5050
},
5151
"mimetype": "application/zip",
52-
"measurements": [],
52+
"classification": {},
5353
"hash": "v0-sha384-ca055fb36845db86e4278cf6e185f8674d11a96f4b29af27e401fc495cc82ef6b53a5729c3757713064649dc71c8c725",
5454
"name": "4784_3_1_t1_dicom.zip",
5555
"tags": [],
@@ -89,7 +89,7 @@
8989
"name": "Admin Import"
9090
},
9191
"mimetype": "application/zip",
92-
"measurements": [],
92+
"classification": {},
9393
"hash": "v0-sha384-537e42b1dd8f1feef9844fbfb4f60461361e71cafa7055556097e9d0b9f7fac68c8f234ed126af9412bd43a548948847",
9494
"name": "4784_5_1_fmri_dicom.zip",
9595
"tags": [],

raml/examples/output/acquisition.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"name": "Admin Import"
99
},
1010
"mimetype": "application/zip",
11-
"measurements": [],
11+
"classification": {},
1212
"hash": "v0-sha384-dd3c97bfe0ad1fcba75ae6718c6e81038c59af4f447f5db194d52732efa4f955b28455db02eb64cad3e4e55f11e3679f",
1313
"name": "4784_1_1_localizer_dicom.zip",
1414
"tags": [],

raml/examples/output/analysis-item.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"hash": "v0-sha384-12188e00a26650b2baa3f0195337dcf504f4362bb2136eef0cdbefb57159356b1355a0402fca0ab5ab081f21c305e5c2",
99
"name": "cortical_surface_right_hemisphere.obj",
1010
"tags": [],
11-
"measurements": [],
11+
"classification": {},
1212
"modified": "2016-10-18T15:26:35.701000+00:00",
1313
"instrument": null,
1414
"input": true,
@@ -24,7 +24,7 @@
2424
"hash": "v0-sha384-12188e00a26650b2baa3f0195337dcf504f4362bb2136eef0cdbefb57159356b1355a0402fca0ab5ab081f21c305e5c2",
2525
"name": "cortical_surface_right_hemisphere.obj",
2626
"tags": [],
27-
"measurements": [],
27+
"classification": {},
2828
"modified": "2016-10-18T17:45:17.776000+00:00",
2929
"instrument": null,
3030
"output": true,

raml/schemas/definitions/analysis.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
{"type":"null"}
5050
]
5151
},
52-
"measurements": {"$ref":"../definitions/file.json#/definitions/measurements"},
52+
"classification": {"$ref":"../definitions/file.json#/definitions/classification"},
5353
"tags": {"$ref":"../definitions/file.json#/definitions/tags"},
5454
"info": {"$ref":"../definitions/file.json#/definitions/info"},
5555
"origin":{"$ref":"../definitions/file.json#/definitions/origin"},

raml/schemas/definitions/file.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
"file-type": { "type": "string" },
66
"mimetype": { "type": "string" },
77
"modality": { "type": "string" },
8-
"measurements": {
9-
"items": { "type": "string"},
10-
"type": "array",
11-
"uniqueItems": true
8+
"classification": {
9+
"type": "object"
1210
},
1311
"tags": {
1412
"items": { "type": "string"},
@@ -37,7 +35,7 @@
3735
"type": {"$ref":"#/definitions/file-type"},
3836
"mimetype": {"$ref":"#/definitions/mimetype"},
3937
"modality": {"$ref":"#/definitions/modality"},
40-
"measurements": {"$ref":"#/definitions/measurements"},
38+
"classification": {"$ref":"#/definitions/classification"},
4139
"tags": {"$ref":"#/definitions/tags"},
4240
"info": {"$ref":"#/definitions/info"}
4341
},
@@ -55,7 +53,7 @@
5553
{"type":"null"}
5654
]
5755
},
58-
"measurements": {"$ref":"#/definitions/measurements"},
56+
"classification": {"$ref":"#/definitions/classification"},
5957
"tags": {"$ref":"#/definitions/tags"},
6058
"info": {"$ref":"#/definitions/info"},
6159
"origin":{"$ref":"#/definitions/origin"},

raml/schemas/mongo/file.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@
1010
"size": { "type": "integer" },
1111
"hash": { "type": "string" },
1212
"modality": { "type": "string" },
13-
"measurements": {
14-
"items": { "type": "string"},
15-
"type": "array",
16-
"uniqueItems": true
13+
"classification": {
14+
"type": "object"
1715
},
1816
"tags": {
1917
"items": { "type": "string"},

0 commit comments

Comments
 (0)