Skip to content

Commit

Permalink
censor overview stats
Browse files Browse the repository at this point in the history
  • Loading branch information
gsfk committed May 13, 2024
1 parent 9246543 commit 76120cb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions bento_beacon/utils/beacon_response.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)},
}


Expand Down
5 changes: 5 additions & 0 deletions bento_beacon/utils/censorship.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit 76120cb

Please sign in to comment.