From d145e67b3ef7d664474462d057d5b7854e16b937 Mon Sep 17 00:00:00 2001 From: sara-santana Date: Fri, 29 Nov 2024 18:25:16 +0000 Subject: [PATCH] fixing bugs --- beacon/request/handlers.py | 8 +++--- beacon/response/build_response.py | 43 +++++++++++-------------------- beacon/scripts/collusion_test.py | 1 + 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/beacon/request/handlers.py b/beacon/request/handlers.py index 654f3305..223152ae 100644 --- a/beacon/request/handlers.py +++ b/beacon/request/handlers.py @@ -252,16 +252,17 @@ async def wrapper(request: Request): ######################## P-VALUE ######################## # apply the p-value strategy if user is authenticated but not registered and only if submodule is genomic variations - count = 1 LOG.debug(f"PUBLIC = {public}") LOG.debug(f"REGISTERED = {registered}") if not public and not registered and db_fn_submodule == "g_variants": history, records, total_cases, removed, removed_individuals = pvalue_strategy(access_token, records, qparams) - dataset_result = (count, records, total_cases) + dataset_result = (len(list(records)), list(records)) + LOG.debug(f"DATASET RESULTS = {dataset_result}") datasets_query_results[dataset_id] = (dataset_result) if history is not None: LOG.debug(f"Query was stored in the database") + LOG.debug(history) return await json_stream(request, history) LOG.debug(f"schema = {entity_schema}") @@ -293,8 +294,9 @@ async def wrapper(request: Request): if not store: # !!!!! JUST TESTING TO SEE IF IT KEEPS THE RECORD IN THE DB WHILE ALL DATASETS ARE ACCESSIBLE TO ALL USERS (public or not) client.beacon['history'].insert_one(document) + LOG.debug(f"response = {response}") - return await json_stream(request, removed_individuals) + return await json_stream(request, response) return wrapper diff --git a/beacon/response/build_response.py b/beacon/response/build_response.py index f879d511..9e48ff4c 100644 --- a/beacon/response/build_response.py +++ b/beacon/response/build_response.py @@ -40,25 +40,16 @@ def build_response_summary(exists, num_total_results): def build_generic_response( results_by_dataset:Dict[str,Tuple[int,list]], accessible_datasets:List[str], granularity:Granularity, qparams, entity_schema, registered:bool, public:bool): - - # flag to check if we need to keep the query and result in database (if user is registered and results include non accessible datasets) - store = False - + # iterate over all results to get: # total count # response by dataset - + store = False num_total_results = 0 response_list:List[Dict] = [] for dataset_id in results_by_dataset: - # if user is not authenticated, they cannot see aggregated data from datasets that are not public, so this will prevent - # the non public datasets to be appended to non authenticated users responses - if public and dataset_id not in accessible_datasets: - continue - num_dataset_results = results_by_dataset[dataset_id][0] dataset_results = results_by_dataset[dataset_id][1] - total_cases = results_by_dataset[dataset_id][2] num_total_results += num_dataset_results dataset_response = { @@ -66,35 +57,31 @@ def build_generic_response( "exists": num_dataset_results > 0, "setType": "dataset", "results": dataset_results, - "resultsCount": total_cases + "resultsCount": num_dataset_results } # if dataset is not authorized, erase the records part - if dataset_id not in accessible_datasets or not registered: + if dataset_id not in accessible_datasets: dataset_response["results"] = [] response_list.append(dataset_response) - + if dataset_id not in accessible_datasets and not registered and not public: - store = True - - beacon_response = [] - - if not dataset_results == []: + store = True - beacon_response = { - 'meta': build_meta(qparams, entity_schema, granularity), - 'responseSummary': build_response_summary(num_total_results > 0, num_total_results), - 'beaconHandovers': conf.beacon_handovers, - 'response': { - 'resultSets': response_list - } + beacon_response = { + 'meta': build_meta(qparams, entity_schema, granularity), + 'responseSummary': build_response_summary(num_total_results > 0, num_total_results), + 'beaconHandovers': conf.beacon_handovers, + 'response': { + 'resultSets': response_list } - - + } return beacon_response, store + + def build_response_by_dataset(data, response_dict, num_total_results, qparams, func): """"Fills the `response` part with the correct format in `results`""" list_of_responses=[] diff --git a/beacon/scripts/collusion_test.py b/beacon/scripts/collusion_test.py index bd92ff9d..b7d7b36a 100644 --- a/beacon/scripts/collusion_test.py +++ b/beacon/scripts/collusion_test.py @@ -146,6 +146,7 @@ def main(): vType = variant_doc["variation"]['variantType'] stdout, stderr = query_variant_with_curl(access_token, alt, ref, start, end, vType) if individual_id in stdout: + print(stdout) print("!!!!!!!!!!!!!!!!!!!!!!!!!!!") print(f"The individual {individual_id} was removed in variant number {var_count}") total_risk -= (current_budget - client.beacon.get_collection('budget').find_one({"individualId": individual_id})['budget'])