Search in sources :

Example 1 with BaseStudyTable

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Math(org.obiba.opal.web.model.Math) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) BadRequestException(javax.ws.rs.BadRequestException) IOException(java.io.IOException) NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Future(java.util.concurrent.Future) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) Mica(org.obiba.mica.web.model.Mica) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with BaseStudyTable

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);
}
Also used : HashMap(java.util.HashMap) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Dataset(org.obiba.mica.dataset.domain.Dataset) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) ModelAndView(org.springframework.web.servlet.ModelAndView) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) StudyTable(org.obiba.mica.core.domain.StudyTable) HarmonizationStudyTable(org.obiba.mica.core.domain.HarmonizationStudyTable) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) HashMap(java.util.HashMap) Map(java.util.Map) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with BaseStudyTable

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Math(org.obiba.opal.web.model.Math) NoSuchVariableException(org.obiba.magma.NoSuchVariableException) IOException(java.io.IOException) NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Future(java.util.concurrent.Future) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) Mica(org.obiba.mica.web.model.Mica) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with BaseStudyTable

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();
}
Also used : NoSuchVariableException(org.obiba.magma.NoSuchVariableException) IOException(java.io.IOException) NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Search(org.obiba.opal.web.model.Search) Future(java.util.concurrent.Future) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) Mica(org.obiba.mica.web.model.Mica)

Example 5 with BaseStudyTable

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);
}
Also used : NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) BaseStudyTable(org.obiba.mica.core.domain.BaseStudyTable) IOException(java.io.IOException) NoSuchValueTableException(org.obiba.magma.NoSuchValueTableException) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

BaseStudyTable (org.obiba.mica.core.domain.BaseStudyTable)7 HarmonizationDataset (org.obiba.mica.dataset.domain.HarmonizationDataset)7 IOException (java.io.IOException)5 NoSuchValueTableException (org.obiba.magma.NoSuchValueTableException)4 NoSuchVariableException (org.obiba.magma.NoSuchVariableException)4 Timed (com.codahale.metrics.annotation.Timed)3 ImmutableList (com.google.common.collect.ImmutableList)3 Future (java.util.concurrent.Future)3 Mica (org.obiba.mica.web.model.Mica)3 StudyDataset (org.obiba.mica.dataset.domain.StudyDataset)2 Math (org.obiba.opal.web.model.Math)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Joiner (com.google.common.base.Joiner)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 InputStream (java.io.InputStream)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1