def projectSummary(self): match = re.match(r"^/?projects/([^/]+)$", self.command) id = parse.unquote(str(match.group(1))) self.restLog("Returing project {} summary".format(id), 2) result = nidm.experiment.Navigate.GetProjectAttributes(self.nidm_files, project_id=id) result['subjects'] = Query.GetParticipantUUIDsForProject( self.nidm_files, project_id=id, filter=self.query['filter']) result['data_elements'] = Query.GetProjectDataElements(self.nidm_files, project_id=id) # if we got fields, drill into each subject and pull out the field data # subject details -> derivitives / instrument -> values -> element if 'fields' in self.query and len(self.query['fields']) > 0: self.restLog("Using fields {}".format(self.query['fields']), 2) result['field_values'] = [] # get all the synonyms for all the fields field_synonyms = functools.reduce(operator.iconcat, [ Query.GetDatatypeSynonyms(self.nidm_files, id, x) for x in self.query['fields'] ], []) for sub in result['subjects']['uuid']: for activity in Navigate.getActivities(self.nidm_files, sub): activity = Navigate.getActivityData( self.nidm_files, activity) for data_element in activity.data: if data_element.dataElement in field_synonyms: result['field_values'].append( data_element._replace(subject=sub)) if len(result['field_values']) == 0: raise ValueError("Supplied field not found. (" + ", ".join(self.query['fields']) + ")") return self.projectSummaryFormat(result)
def projectSummary(self): GetParticipantDetails_Cached = memory.cache( Query.GetParticipantDetails) match = re.match(r"^/?projects/([^/]+)$", self.command) id = parse.unquote(str(match.group(1))) self.restLog("Returing project {} summary".format(id), 2) result = nidm.experiment.Navigate.GetProjectAttributes(self.nidm_files, project_id=id) result['subjects'] = Query.GetParticipantUUIDsForProject( self.nidm_files, project_id=id, filter=self.query['filter']) result['data_elements'] = Query.GetProjectDataElements(self.nidm_files, project_id=id) # if we got fields, drill into each subject and pull out the field data # subject details -> derivitives / instrument -> values -> element if 'fields' in self.query and len(self.query['fields']) > 0: self.restLog("Using fields {}".format(self.query['fields']), 2) result['field_values'] = [] for sub in result['subjects']: sub_data = GetParticipantDetails_Cached( self.nidm_files, id, sub) for study_type in ['derivatives']: if study_type in sub_data: for key, deriv in sub_data[study_type].items(): for element_uri, data_row in deriv['values'].items( ): field = self.getTailOfURI(element_uri) if field in self.query['fields']: result['field_values'].append({ 'subject': sub, 'field': field, 'datumType': data_row['datumType'], 'label': data_row['label'], 'value': data_row['value'], 'units': data_row['units'] }) for study_type in ['instruments']: if study_type in sub_data: for instrument_uri, instrument_dict in sub_data[ study_type].items(): for instrument_field, instument_value in instrument_dict.items( ): if instrument_field in self.query['fields']: result['field_values'].append({ 'subject': sub, 'field': instrument_field, 'datumType': '', 'label': '', 'value': instument_value, 'units': '' }) return self.projectSummaryFormat(result)