From 76120cb7f48f21253f103c78c1a74dacf01e6162 Mon Sep 17 00:00:00 2001 From: Gordon Krieger Date: Mon, 13 May 2024 20:10:27 +0000 Subject: [PATCH] censor overview stats --- bento_beacon/utils/beacon_response.py | 6 +++--- bento_beacon/utils/censorship.py | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bento_beacon/utils/beacon_response.py b/bento_beacon/utils/beacon_response.py index 4cc49d9f..4d435cd1 100644 --- a/bento_beacon/utils/beacon_response.py +++ b/bento_beacon/utils/beacon_response.py @@ -1,6 +1,6 @@ from flask import current_app, g, request from .katsu_utils import search_summary_statistics, overview_statistics -from .censorship import get_censorship_threshold, censored_count, MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS +from .censorship import get_censorship_threshold, censored_count, censored_chart_data, MESSAGE_FOR_CENSORED_QUERY_WITH_NO_RESULTS from .exceptions import InvalidQuery, APIException from ..constants import GRANULARITY_BOOLEAN, GRANULARITY_COUNT, GRANULARITY_RECORD @@ -58,8 +58,8 @@ def package_biosample_and_experiment_stats(stats): experiment_type_data = [{"label": key, "value": value} for key, value in experiment_type.items()] return { - "biosamples": {"count": biosamples_count, "sampled_tissue": sampled_tissue_data}, - "experiments": {"count": experiments_count, "experiment_type": experiment_type_data}, + "biosamples": {"count": censored_count(biosamples_count), "sampled_tissue": censored_chart_data(sampled_tissue_data)}, + "experiments": {"count": censored_count(experiments_count), "experiment_type": censored_chart_data(experiment_type_data)}, } diff --git a/bento_beacon/utils/censorship.py b/bento_beacon/utils/censorship.py index 680cdd9e..ecf7a1d0 100644 --- a/bento_beacon/utils/censorship.py +++ b/bento_beacon/utils/censorship.py @@ -64,3 +64,8 @@ def reject_if_too_many_filters(filters): max_filters = get_max_filters() if len(filters) > max_filters: raise InvalidQuery(f"too many filters in request, maximum of {max_filters} permitted") + + +def censored_chart_data(data): + t = get_censorship_threshold() # zero with correct permissions + return [{"label": d["label"], "value": d["value"]} for d in data if d["value"] > t]