use of org.obiba.mica.core.domain.BaseStudyTable in project mica2 by obiba.
the class PublishedDataschemaDatasetVariableResource method getVariableAggregations.
@GET
@Path("/aggregation")
@Timed
public Mica.DatasetVariableAggregationsDto getVariableAggregations() {
ImmutableList.Builder<Mica.DatasetVariableAggregationDto> builder = ImmutableList.builder();
HarmonizationDataset dataset = getDataset(HarmonizationDataset.class, datasetId);
Mica.DatasetVariableAggregationsDto.Builder aggDto = Mica.DatasetVariableAggregationsDto.newBuilder();
List<Future<Math.SummaryStatisticsDto>> results = Lists.newArrayList();
dataset.getBaseStudyTables().forEach(table -> results.add(helper.getVariableFacet(dataset, variableName, table)));
for (int i = 0; i < dataset.getBaseStudyTables().size(); i++) {
BaseStudyTable opalTable = dataset.getBaseStudyTables().get(i);
Future<Math.SummaryStatisticsDto> futureResult = results.get(i);
try {
builder.add(dtos.asDto(opalTable, futureResult.get()).build());
} catch (Exception e) {
log.warn("Unable to retrieve statistics: " + e.getMessage(), e);
builder.add(dtos.asDto(opalTable, null).build());
}
}
List<Mica.DatasetVariableAggregationDto> aggsDto = builder.build();
Mica.DatasetVariableAggregationDto allAggDto = CombinedStatistics.mergeAggregations(aggsDto);
aggDto.setN(allAggDto.getN());
aggDto.setTotal(allAggDto.getTotal());
if (allAggDto.hasStatistics())
aggDto.setStatistics(allAggDto.getStatistics());
aggDto.addAllFrequencies(allAggDto.getFrequenciesList());
aggDto.addAllAggregations(aggsDto);
return aggDto.build();
}
use of org.obiba.mica.core.domain.BaseStudyTable in project mica2 by obiba.
the class DatasetController method dataset.
@GetMapping("/dataset/{id:.+}")
public ModelAndView dataset(@PathVariable String id, @RequestParam(value = "draft", required = false) String shareKey) {
Map<String, Object> params = newParameters();
Dataset dataset = getDataset(id, shareKey);
params.put("dataset", dataset);
params.put("type", (dataset instanceof StudyDataset) ? "Collected" : "Harmonized");
params.put("draft", !Strings.isNullOrEmpty(shareKey));
if (dataset instanceof StudyDataset) {
addStudyTableParameters(params, ((StudyDataset) dataset).getStudyTable());
} else {
HarmonizationDataset harmoDataset = (HarmonizationDataset) dataset;
addHarmonizationTableParameters(params, harmoDataset.getHarmonizationTable());
Map<String, BaseStudy> allStudies = Maps.newHashMap();
List<BaseStudyTable> allTables = Lists.newArrayList();
List<Map<String, Object>> studyTables = Lists.newArrayList();
List<String> ids = Lists.newArrayList();
for (StudyTable sTable : harmoDataset.getStudyTables()) {
Map<String, Object> p = new HashMap<>();
if (addStudyTableParameters(p, sTable, ids))
allTables.add(sTable);
if (!p.isEmpty()) {
studyTables.add(p);
allStudies.put(sTable.getStudyId(), (BaseStudy) p.get("study"));
}
}
params.put("studyTables", studyTables);
List<Map<String, Object>> harmonizationTables = Lists.newArrayList();
ids.clear();
for (HarmonizationStudyTable hTable : harmoDataset.getHarmonizationTables()) {
Map<String, Object> p = new HashMap<>();
if (addHarmonizationTableParameters(p, hTable, ids))
allTables.add(hTable);
if (!p.isEmpty()) {
harmonizationTables.add(p);
allStudies.put(hTable.getStudyId(), (BaseStudy) p.get("study"));
}
}
params.put("harmonizationTables", harmonizationTables);
params.put("allTables", allTables);
params.put("allStudies", allStudies);
}
params.put("showDatasetContingencyLink", showDatasetContingencyLink());
return new ModelAndView("dataset", params);
}
use of org.obiba.mica.core.domain.BaseStudyTable in project mica2 by obiba.
the class PublishedDataschemaDatasetVariableResource method getVariableAggregations.
@GET
@Path("/aggregation")
@Timed
public Mica.DatasetVariableAggregationsDto getVariableAggregations(@QueryParam("study") @DefaultValue("true") boolean withStudySummary) {
checkDatasetAccess();
checkVariableSummaryAccess();
ImmutableList.Builder<Mica.DatasetVariableAggregationDto> builder = ImmutableList.builder();
HarmonizationDataset dataset = getDataset(HarmonizationDataset.class, datasetId);
Mica.DatasetVariableAggregationsDto.Builder aggDto = Mica.DatasetVariableAggregationsDto.newBuilder();
List<Future<Math.SummaryStatisticsDto>> results = Lists.newArrayList();
dataset.getBaseStudyTables().forEach(table -> results.add(helper.getVariableFacet(dataset, variableName, table)));
for (int i = 0; i < dataset.getBaseStudyTables().size(); i++) {
BaseStudyTable opalTable = dataset.getBaseStudyTables().get(i);
Future<Math.SummaryStatisticsDto> futureResult = results.get(i);
try {
builder.add(dtos.asDto(opalTable, futureResult.get(), withStudySummary).build());
} catch (Exception e) {
log.warn("Unable to retrieve statistics: " + e.getMessage(), e);
builder.add(dtos.asDto(opalTable, null, withStudySummary).build());
}
}
List<Mica.DatasetVariableAggregationDto> aggsDto = builder.build();
Mica.DatasetVariableAggregationDto allAggDto = CombinedStatistics.mergeAggregations(aggsDto);
aggDto.setN(allAggDto.getN());
aggDto.setTotal(allAggDto.getTotal());
if (allAggDto.hasStatistics())
aggDto.setStatistics(allAggDto.getStatistics());
aggDto.addAllFrequencies(allAggDto.getFrequenciesList());
aggDto.addAllAggregations(aggsDto);
return aggDto.build();
}
use of org.obiba.mica.core.domain.BaseStudyTable in project mica2 by obiba.
the class PublishedDataschemaDatasetVariableResource method getDatasetVariableContingenciesDto.
//
// Private methods
//
private Mica.DatasetVariableContingenciesDto getDatasetVariableContingenciesDto(DatasetVariable var, DatasetVariable crossVar) {
HarmonizationDataset dataset = getDataset(HarmonizationDataset.class, datasetId);
Mica.DatasetVariableContingenciesDto.Builder crossDto = Mica.DatasetVariableContingenciesDto.newBuilder();
List<Future<Search.QueryResultDto>> results = Lists.newArrayList();
dataset.getBaseStudyTables().forEach(table -> results.add(helper.getContingencyTable(dataset, var, crossVar, table)));
Multimap<String, Mica.DatasetVariableAggregationDto> termAggregations = LinkedListMultimap.create();
for (int i = 0; i < dataset.getBaseStudyTables().size(); i++) {
BaseStudyTable opalTable = dataset.getBaseStudyTables().get(i);
Future<Search.QueryResultDto> futureResult = results.get(i);
try {
Mica.DatasetVariableContingencyDto studyTableCrossDto = dtos.asContingencyDto(opalTable, var, crossVar, futureResult.get()).build();
termAggregations.put(null, studyTableCrossDto.getAll());
studyTableCrossDto.getAggregationsList().forEach(termAggDto -> termAggregations.put(termAggDto.getTerm(), termAggDto));
crossDto.addContingencies(studyTableCrossDto);
} catch (Exception e) {
log.warn("Unable to retrieve contingency table: " + e.getMessage(), e);
crossDto.addContingencies(dtos.asContingencyDto(opalTable, var, crossVar, null));
}
}
// Merge aggregations by term (=variable category) + all terms aggregation.
Mica.DatasetVariableContingencyDto.Builder allContingencies = Mica.DatasetVariableContingencyDto.newBuilder();
termAggregations.asMap().entrySet().forEach(entry -> {
Mica.DatasetVariableAggregationDto merged = CombinedStatistics.mergeAggregations(entry.getValue());
if (entry.getKey() == null) {
allContingencies.setAll(merged);
} else {
allContingencies.addAggregations(merged);
}
});
crossDto.setAll(allContingencies);
return crossDto.build();
}
use of org.obiba.mica.core.domain.BaseStudyTable in project mica2 by obiba.
the class PublishedHarmonizedDatasetVariableResource method getVariableAggregations.
@GET
@Path("/aggregation")
@Timed
public Mica.DatasetVariableAggregationDto getVariableAggregations(@QueryParam("study") @DefaultValue("true") boolean withStudySummary) {
checkDatasetAccess();
checkVariableSummaryAccess();
HarmonizationDataset dataset = getDataset(HarmonizationDataset.class, datasetId);
for (BaseStudyTable opalTable : dataset.getBaseStudyTables()) {
String opalTableId = studyId;
if (opalTable.isFor(opalTableId, project, table)) {
try {
return dtos.asDto(opalTable, datasetService.getVariableSummary(dataset, variableName, studyId, project, table).getWrappedDto(), withStudySummary).build();
} catch (Exception e) {
log.warn("Unable to retrieve statistics: " + e.getMessage(), e);
return dtos.asDto(opalTable, null, withStudySummary).build();
}
}
}
throw new NoSuchValueTableException(project, table);
}
Aggregations