Created
January 9, 2023 20:25
-
-
Save Zmey56/1c475414a997f4d0c93b591e9089e8a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_select_vars(mertics, metrics_list, group_by_slices_list, slice, all_data=False): | |
date_select = "toDate(time) as date, " | |
time_select = '''toStartOfFifteenMinutes(time) as time, | |
formatDateTime(toStartOfFifteenMinutes(time), '%R') as time_,''' | |
select_expression = [] | |
for metric in mertics: | |
formula = metrics_list[metric]['formula'] | |
alias = metrics_list[metric]['alias'] | |
expression = '{formula} AS {alias}'.format(formula=formula, alias=alias) | |
select_expression.append(expression) | |
if slice != 'total': | |
formula = group_by_slices_list[slice]['formula'] | |
alias = group_by_slices_list[slice]['alias'] | |
expression = '{formula} AS {alias}'.format(formula=formula, alias=alias) | |
select_expression.append(expression) | |
select_expression = ','.join(select_expression) | |
if not all_data: | |
select_expression = date_select + select_expression | |
else: | |
select_expression = date_select + time_select + select_expression | |
return select_expression |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment