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
package main | |
import ( | |
"fmt" | |
"os" | |
) | |
func main() { | |
for _, s := range os.Args { | |
fmt.Println(s) |
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_metric_alert(alert_df, metric, metric_alias, slice, group, day_threshhold=0.3): | |
alert_data = {} | |
is_alert = 0 | |
day_0 = date.today().strftime("%Y-%m-%d") | |
day_1 = (date.today() - pd.DateOffset(days=1)).strftime("%Y-%m-%d") | |
day_7 = (date.today() - pd.DateOffset(days=7)).strftime("%Y-%m-%d") | |
day_0_value = alert_df[alert_df['date'] == day_0][metric].iloc[0] | |
day_1_value = alert_df[alert_df['date'] == day_1][metric].iloc[0] | |
day_7_value = alert_df[alert_df['date'] == day_7][metric].iloc[0] |
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 global_monitoring(chat=None): | |
chat_id = chat or 0000000000 | |
alerts = [ | |
{"mertics": ["users_feed", "likes", "views", "ctr"], "slice": "total"}, | |
{"mertics": ["users_feed", "likes", "views", "ctr"], "slice": "os"}, | |
{"mertics": ["users_msg", "messages", "mpu"], "slice": "total"}, | |
] | |
time = Getch('''SELECT toStartOfFifteenMinutes(max(time)) - interval 15 minute AS mas_time | |
FROM simulator.feed_actions WHERE toDate(time) >= today() - 1''').df |
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_alert(alert_data, time, chat): | |
chat_id = chat | |
metrics_list, group_by_slices_list, where_expression_template, alert_plots, responsible_users = get_alert_info() | |
mertics = alert_data['mertics'] | |
slice = alert_data['slice'] | |
query = '''SELECT {select_vars} | |
FROM {from_table_name} |
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 send_alert(plot_df, group, metric_name, metric_alias, slice_name, alert_plot, responsible_users, chat): | |
bot = telegram.Bot(token=os.environ.get('REPORT_BOT_TOKEN')) | |
dahsboard_link = 'https://superset.lab.karpov.courses/superset/dashboard/52/' | |
day_0 = date.today().strftime("%Y-%m-%d") | |
day_1 = (date.today() - pd.DateOffset(days=1)).strftime("%Y-%m-%d") | |
day_7 = (date.today() - pd.DateOffset(days=7)).strftime("%Y-%m-%d") |
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_group_by_expression(slice, group_by_slices_list, all_data=False): | |
if not all_data: | |
group_by_expression = ' date' | |
else: | |
group_by_expression = ' date, toStartOfFifteenMinutes(time) as time, time_' | |
if slice != 'total': | |
alias = group_by_slices_list[slice]['alias'] | |
group_by_expression = group_by_expression + ',' + alias | |
return group_by_expression |
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_where_expression(where_expression_template, group_by_slices_list, time, slice, all_data=False): | |
where_expression = ''' {where_expression_template} and {alias} in ({group_levels}) ''' | |
day_0_min_time = time | |
day_0_max_time = time + pd.Timedelta(minutes=15) | |
day_1_min_time = time - pd.Timedelta(minutes=15) - pd.Timedelta(days=1) | |
day_1_max_time = time + pd.Timedelta(minutes=30) - pd.Timedelta(days=1) | |
day_7_min_time = time - pd.Timedelta(minutes=15) - pd.Timedelta(days=7) | |
day_7_max_time = time + pd.Timedelta(minutes=30) - pd.Timedelta(days=7) |
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_from_table_name(mertics, metrics_list): | |
table_name_list = [] | |
for metric in mertics: | |
table_name = metrics_list[metric]['table_name'] | |
table_name_list.append(table_name) | |
table_name_list = list(set(table_name_list))[0] | |
table_name = str(table_name_list) | |
return table_name |
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'] |
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_alert_info(): | |
metrics_list = { | |
'users_feed': { | |
'alias': 'users_feed', | |
'formula': 'uniqExact(user_id)', | |
'metric_name': 'Users Feed', | |
'table_name': 'simulator.feed_actions' | |
}, | |
'likes': { | |
'alias': 'likes', |
NewerOlder