Skip to content

Commit

Permalink
Fix linter issue C901
Browse files Browse the repository at this point in the history
  • Loading branch information
promans718 committed Oct 4, 2024
1 parent d689d5d commit 2977618
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions toolium/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,31 +279,42 @@ def _replace_param_transform_string(param):
exec(f'exec_param = {type_mapping_match_group.group(1).lower()}({type_mapping_match_group.group(2)})')
new_param = locals()['exec_param']
else:
if type_mapping_match_group.group(1) == 'STR':
replace_param = type_mapping_match_group.group(2)
elif type_mapping_match_group.group(1) == 'UPPER':
replace_param = type_mapping_match_group.group(2).upper()
elif type_mapping_match_group.group(1) == 'LOWER':
replace_param = type_mapping_match_group.group(2).lower()
elif type_mapping_match_group.group(1) == 'REPLACE':
params_to_replace = type_mapping_match_group.group(2).split('::')
replace_param = params_to_replace[2] if len(params_to_replace) > 2 else ''
param_to_replace = params_to_replace[1] if params_to_replace[1] != '\\n' else '\n'
param_to_replace = params_to_replace[1] if params_to_replace[1] != '\\r' else '\r'
replace_param = params_to_replace[0].replace(param_to_replace, replace_param).replace(' ', ' ').replace(' ', ' ')
elif type_mapping_match_group.group(1) == 'DATE':
params_to_replace = type_mapping_match_group.group(2).split('::')
date_actual_format = '%Y/%m/%d %H:%M:%S'
replace_param = _format_date_spanish(params_to_replace[0], params_to_replace[1], date_actual_format,\
capitalize=False)
elif type_mapping_match_group.group(1) == 'TITLE':
replace_param = "".join(map(min, zip(type_mapping_match_group.group(2),
type_mapping_match_group.group(2).title())))
new_param = new_param.replace(
type_mapping_match_group.group(), replace_param)
replace_param = _update_param_transform_string(type_mapping_match_group)
new_param = new_param.replace(type_mapping_match_group.group(), replace_param)
return new_param, param_transformed


def _update_param_transform_string(type_mapping_match_group):
"""
Transform param value according to the specified prefix.
Available transformations: STR, UPPER, LOWER, REPLACE, DATE, TITLE
:param type_mapping_match_group: match group
:return: return the string with the replaced param
"""
if type_mapping_match_group.group(1) == 'STR':
replace_param = type_mapping_match_group.group(2)
elif type_mapping_match_group.group(1) == 'UPPER':
replace_param = type_mapping_match_group.group(2).upper()
elif type_mapping_match_group.group(1) == 'LOWER':
replace_param = type_mapping_match_group.group(2).lower()
elif type_mapping_match_group.group(1) == 'REPLACE':
params_to_replace = type_mapping_match_group.group(2).split('::')
replace_param = params_to_replace[2] if len(params_to_replace) > 2 else ''
param_to_replace = params_to_replace[1] if params_to_replace[1] != '\\n' else '\n'
param_to_replace = params_to_replace[1] if params_to_replace[1] != '\\r' else '\r'
replace_param = params_to_replace[0].replace(param_to_replace, replace_param)\
.replace(' ', ' ').replace(' ', ' ')
elif type_mapping_match_group.group(1) == 'DATE':
params_to_replace = type_mapping_match_group.group(2).split('::')
date_actual_format = '%Y/%m/%d %H:%M:%S'
replace_param = _format_date_spanish(params_to_replace[0], params_to_replace[1], date_actual_format, \
capitalize=False)
elif type_mapping_match_group.group(1) == 'TITLE':
replace_param = "".join(map(min, zip(type_mapping_match_group.group(2), type_mapping_match_group.group(2).title())))
return replace_param


def _replace_param_date(param, language):
"""
Transform param value in a date after applying the specified delta.
Expand Down

0 comments on commit 2977618

Please sign in to comment.