Skip to content

Commit

Permalink
Add request vis binned data
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcolon021 committed Jul 14, 2023
1 parent 1d7cdf3 commit f746f22
Showing 1 changed file with 30 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,12 +511,12 @@ private int generateVarianceWithCrossCounts(Map<String, String> crossCounts) {
return generateRequestVariance(crossCountsString.toString());
}

protected String processContinuousCrossCounts(String continuousCrossCountResponse, String crossCountResponse) throws IOException {
protected String processContinuousCrossCounts(String continuousCrossCountResponse, String crossCountEntityString) throws IOException {
logger.info("Processing continuous cross counts");
logger.info("Cross count response: {} ", crossCountResponse);
logger.info("Cross count response: {} ", crossCountEntityString);
logger.info("Continuous count response: {}", continuousCrossCountResponse);

if (continuousCrossCountResponse == null || crossCountResponse == null) {
if (continuousCrossCountResponse == null || crossCountEntityString == null) {
return null;
}

Expand All @@ -535,8 +535,19 @@ protected String processContinuousCrossCounts(String continuousCrossCountRespons
String responseString = EntityUtils.toString(entity, "UTF-8");

logger.info("Response from binning endpoint: {}", responseString);
Map<String, Map<String, Integer>> binnedContinuousCrossCounts = objectMapper.convertValue(responseString, new TypeReference<>() {});

return continuousCrossCountResponse;
Map<String, String> crossCounts = objectMapper.readValue(crossCountEntityString, new TypeReference<>(){});
int generatedVariance = this.generateVarianceWithCrossCounts(crossCounts);

String lessThanThresholdStr = "< " + this.threshold;
String varianceStr = " \u00B1" + variance;
boolean mustObfuscate = isCrossCountObfuscated(crossCounts, generatedVariance, lessThanThresholdStr, varianceStr);
if (!mustObfuscate) {
return objectMapper.writeValueAsString(binnedContinuousCrossCounts);
}

return objectMapper.writeValueAsString(binnedContinuousCrossCounts);
}

/**
Expand Down Expand Up @@ -565,15 +576,7 @@ protected String processCategoricalCrossCounts(String categoricalEntityString, S

// Based on the results of the cross counts, we need to determine if we need to obfuscate our categoricalCrossCount
// If any of the cross counts are less than the threshold or have a variance, we need to obfuscate.
boolean mustObfuscate = false;
Map<String, String> obfuscatedCrossCount = this.obfuscateCrossCounts(crossCounts, generatedVariance);
for (Map.Entry<String, String> entry : obfuscatedCrossCount.entrySet()) {
String v = entry.getValue();
if (v.contains(lessThanThresholdStr) || v.contains(varianceStr)) {
mustObfuscate = true;
break;
}
}
boolean mustObfuscate = isCrossCountObfuscated(crossCounts, generatedVariance, lessThanThresholdStr, varianceStr);

if (!mustObfuscate) {
return categoricalEntityString;
Expand All @@ -599,6 +602,20 @@ protected String processCategoricalCrossCounts(String categoricalEntityString, S
return objectMapper.writeValueAsString(categoricalCrossCount);
}

private boolean isCrossCountObfuscated(Map<String, String> crossCounts, int generatedVariance, String lessThanThresholdStr, String varianceStr) {
boolean mustObfuscate = false;
Map<String, String> obfuscatedCrossCount = this.obfuscateCrossCounts(crossCounts, generatedVariance);
for (Map.Entry<String, String> entry : obfuscatedCrossCount.entrySet()) {
String v = entry.getValue();
if (v.contains(lessThanThresholdStr) || v.contains(varianceStr)) {
mustObfuscate = true;
break;
}
}

return mustObfuscate;
}

/**
* This method will generate a random variance for the request based on the passed entityString. The variance
* will be between -variance and +variance. The variance will be generated by adding a random salt to the
Expand Down

0 comments on commit f746f22

Please sign in to comment.