Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove stopgap code and fix a couple of bugs #299

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading