Skip to content
Snippets Groups Projects
Commit 84cc3235 authored by Pietro Cavassin's avatar Pietro Cavassin
Browse files

fix derivatives variable substitution

parent cbbf0f53
No related branches found
No related tags found
No related merge requests found
......@@ -818,6 +818,7 @@ class DatabaseTable(Table):
case = case.strip("~") # doesn't need "~" anymore
str_list = re.findall(r'("[\w]"|[\w.]+)', case)
print('-----------------\n',str_list,'\n--------------------')
for substr in str_list:
if '.' in substr: # We have a var from another table
table = substr.split('.')[0]
......@@ -836,7 +837,17 @@ class DatabaseTable(Table):
var_target = self._get_variable_target(var_name.strip('"'), year)
if var_target is not None:
var_db = self._protocol.dbcolumn_from_target(var_target)[0]
case = case.replace(var_name, var_db)
case_tokens = case.split(" ")
case_tokens = case.split(' ')
for i in range(0, len(case_tokens)):
# remove everything prior to first, and after last quotation mark (including them)
token_varname = re.sub(r'(^[^\"]*[\"])', '', case_tokens[i])
token_varname = re.sub(r'([\"][^\"]*$)', '', token_varname)
if (token_varname == var_name):
case_tokens[i] = case_tokens[i].replace(var_name, var_db)
ch = ' '
case = ch.join(case_tokens)
if table is not self and table not in referred_tables:
referred_tables.append(table)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment