Skip to content

Commit

Permalink
Fix some issues with crosstab rendering when privacy threshold applies
Browse files Browse the repository at this point in the history
  • Loading branch information
ymarcon committed Feb 10, 2021
1 parent 5a61c64 commit 4d10692
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ else if (opalTable instanceof HarmonizationStudyTable)
MicaConfig micaConfig = micaConfigService.getConfig();
int privacyThreshold = micaConfig.getPrivacyThreshold();
crossDto.setPrivacyThreshold(privacyThreshold);
boolean privacyChecks = crossVariable.hasCategories() ? validatePrivacyThreshold(results, privacyThreshold) : true;
boolean privacyChecks = !crossVariable.hasCategories() || validatePrivacyThreshold(results, privacyThreshold);
boolean totalPrivacyChecks = validateTotalPrivacyThreshold(results, privacyThreshold);

// add facet results in the same order as the variable categories
Expand All @@ -517,7 +517,7 @@ else if (opalTable instanceof HarmonizationStudyTable)
// add total facet for all variable categories
results.getFacetsList().stream().filter(facet -> facet.hasFacet() && "_total".equals(facet.getFacet()))
.forEach(facet -> {
boolean privacyCheck = privacyChecks && facet.getFilters(0).getCount() > micaConfig.getPrivacyThreshold();
boolean privacyCheck = privacyChecks && facet.getFilters(0).getCount() >= micaConfig.getPrivacyThreshold();
addSummaryStatistics(crossVariable, allAggBuilder, facet, privacyCheck, totalPrivacyChecks);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ private static void mergeAggregations(Mica.DatasetVariableAggregationDto.Builder
Collection<Mica.DatasetVariableAggregationDto> aggDtos) {
mergeFrequencies(aggDto, aggDtos);
mergeStatistics(aggDto, aggDtos);
aggDto.setN(aggDtos.stream().mapToInt(Mica.DatasetVariableAggregationDto::getN).sum());
aggDto.setTotal(aggDtos.stream().mapToInt(Mica.DatasetVariableAggregationDto::getTotal).sum());
aggDto.setN(aggDtos.stream().filter(a -> a.hasStatistics() || a.getFrequenciesCount()>0).mapToInt(Mica.DatasetVariableAggregationDto::getN).sum());
aggDto.setTotal(aggDtos.stream().filter(a -> a.hasStatistics() || a.getFrequenciesCount()>0).mapToInt(Mica.DatasetVariableAggregationDto::getTotal).sum());
aggDtos.forEach(a -> {
if(a.hasTerm()) aggDto.setTerm(a.getTerm());
});
Expand Down
17 changes: 13 additions & 4 deletions mica-webapp/src/main/webapp/assets/js/mica-dataset-crosstab.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class DatasetCrosstab {
if (data.contingencies) {
this._contingencies = this._normalizeData(data.contingencies);
this._mainContingency = this._normalizeData([data.all]).pop();
const mergedPrivacyCheck = this._contingencies.every(c => c.privacyCheck);
const mergedTotalPrivacyCheck = this._contingencies.every(c => c.totalPrivacyCheck);
this._mainContingency.privacyCheck = this._mainContingency.privacyCheck && mergedPrivacyCheck;
this._mainContingency.totalPrivacyCheck = this._mainContingency.totalPrivacyCheck && mergedTotalPrivacyCheck;
} else {
this._mainContingency = this._normalizeData([data]).pop();
}
Expand Down Expand Up @@ -211,8 +215,7 @@ class DatasetCrosstab {
if (!contingency.totalPrivacyCheck || contingency.all.n > 0) {
if (that._isStatistical(that.getVariable2())) {
that._normalizeStatistics(contingency, v1Cats);
}
if (v2Cats) {
} else if (v2Cats) {
that._normalizeFrequencies(contingency, v2Cats);
}
}
Expand Down Expand Up @@ -241,12 +244,16 @@ class DatasetCrosstab {
};
}

contingency.privacyCheck = contingency.aggregations.filter(aggregation => aggregation.statistics !== null).length === contingency.aggregations.length;
contingency.privacyCheck = contingency.aggregations.every(a => a.n>-1);//contingency.aggregations.filter(aggregation => aggregation.statistics !== null).length === contingency.aggregations.length;
let terms = contingency.aggregations.map(aggregation => aggregation.term);

if (!contingency.privacyCheck) {
// server returns no aggregation, create empty ones
contingency.aggregations.forEach(aggregation => aggregation.statistics = createEmptyStatistics());
contingency.aggregations.forEach(aggregation => {
if (!aggregation.statistics) {
aggregation.statistics = createEmptyStatistics();
}
});
contingency.all.statistics = createEmptyStatistics();
} else {
// create the missing category aggregations
Expand Down Expand Up @@ -488,6 +495,8 @@ const initStudySelector = function() {
const renderDatasetCrosstab = function(contingency) {
if (!contingency.privacyCheck || !contingency.totalPrivacyCheck) {
$('#privacy-alert').show();
} else {
$('#privacy-alert').hide();
}
// init Crosstab element
const crosstabElem = $('#crosstab');
Expand Down

0 comments on commit 4d10692

Please sign in to comment.