Skip to content

Commit

Permalink
fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
sara-santana committed Nov 29, 2024
1 parent eec5eba commit d145e67
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
8 changes: 5 additions & 3 deletions beacon/request/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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

Expand Down
43 changes: 15 additions & 28 deletions beacon/response/build_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,61 +40,48 @@ 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 = {
"id": dataset_id,
"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=[]
Expand Down
1 change: 1 addition & 0 deletions beacon/scripts/collusion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit d145e67

Please sign in to comment.