Skip to content

Commit

Permalink
Remove stopgap code and fix a couple of bugs (#299)
Browse files Browse the repository at this point in the history
* removed stopgap conditional checking for Age

* fixed an issue with None in features endpoint
  • Loading branch information
hyi authored Dec 6, 2023
1 parent ef94115 commit f90a8c5
Showing 1 changed file with 28 additions and 35 deletions.
63 changes: 28 additions & 35 deletions icees_api/features/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ def select_feature_count_all_values(
for value in value_to_be_added:
# only append value to levels when value is not in levels and level_op_val is empty or
# value does not satisfy the operations encoded in the level_op_val
if not level_op_val or \
('<' in level_op_val and int(value) >= level_op_val['<']) or \
('>' in level_op_val and int(value) <= level_op_val['>']):
levels.append(value)
if value:
if not level_op_val or ('<' in level_op_val and int(value) >= level_op_val['<']) \
or ('>' in level_op_val and int(value) <= level_op_val['>']):
levels.append(value)
feat_qualifiers = [{
"operator": "=",
"value": level
Expand All @@ -818,21 +818,20 @@ def select_feature_count_all_values(
} for k, v in level_op_val.items()])
greater_value_sum = less_value_sum = 0
for value in value_to_be_added:
int_val = int(value)
if '<' in level_op_val and int_val < level_op_val['<']:
less_value_sum += values[value]
if '>' in level_op_val and int_val > level_op_val['>']:
greater_value_sum += values[value]
if greater_value_sum > 0:
feat_matrix.append({
"frequency": greater_value_sum,
"percentage": div(greater_value_sum, total)
})
if less_value_sum > 0:
feat_matrix.append({
"frequency": less_value_sum,
"percentage": div(less_value_sum, total)
})
if value:
int_val = int(value)
if '<' in level_op_val and int_val < level_op_val['<']:
less_value_sum += values[value]
if '>' in level_op_val and int_val > level_op_val['>']:
greater_value_sum += values[value]
feat_matrix.append({
"frequency": greater_value_sum,
"percentage": div(greater_value_sum, total)
})
feat_matrix.append({
"frequency": less_value_sum,
"percentage": div(less_value_sum, total)
})
feature_a_norm_with_biolink_class = {
"feature_name": feature_name,
"feature_qualifiers": feat_qualifiers,
Expand Down Expand Up @@ -1039,25 +1038,19 @@ def get_operator_and_value(input_levels, feat_name, append_feature_variable=Fals
"""
fqs = []
for input_level in input_levels:
# checking if feature variable name contains Age is a stop-gap solution, which will be removed after
# Age-related variable binning is removed in FHIR PIT and dataset is updated
if 'Age' in feat_name:
non_op_idx = 0
if isinstance(input_level, str):
for lev in input_level:
if lev in ['<', '>']:
non_op_idx += 1
else:
break
if non_op_idx == 0:
op = '='
op_val = input_level
else:
non_op_idx = 0
if isinstance(input_level, str):
for lev in input_level:
if lev in ['<', '>']:
non_op_idx += 1
else:
break
if non_op_idx == 0:
op = '='
op_val = input_level
else:
op = input_level[:non_op_idx]
op_val = input_level[non_op_idx:]
op = input_level[:non_op_idx]
op_val = input_level[non_op_idx:]
if append_feature_variable:
fqs.append({feat_name: {"operator": op, "value": op_val}})
else:
Expand Down

0 comments on commit f90a8c5

Please sign in to comment.