def add_reference_rates(gc, data, offline=None): ref_rate_title = "BW-Video-Keen-Key" if offline: ref_rates = offline_sheets.read_sheets(ref_rate_title) else: ref_rates = read_sheets(gc, ref_rate_title) ref_rates = {k: df.replace("NULL", np.nan) for k, df in ref_rates.iteritems()} ref_rates = {k: df.dropna(axis=0, how='all') for k, df in ref_rates.iteritems()} rev_rates = ref_rates['REVENUE RATE'] if rev_rates.revenue_rate.dtype == np.object: rev_rates['revenue_rate'] = rev_rates['revenue_rate'].apply(remove_dollar) cost_rates = ref_rates['COST RATE'] if cost_rates.cost_rate.dtype == np.object: cost_rates['cost_rate'] = cost_rates['cost_rate'].apply(remove_dollar) data = data.merge(rev_rates, on='program', how='left') data = data.merge(cost_rates, on=['campaign', 'refer'], how='left') return data
def add_reference_rates(gc, data, offline=None): ref_rate_title = "BW-Video-Keen-Key" if offline: ref_rates = offline_sheets.read_sheets(ref_rate_title) else: ref_rates = read_sheets(gc, ref_rate_title) ref_rates = { k: df.replace("NULL", np.nan) for k, df in ref_rates.iteritems() } ref_rates = { k: df.dropna(axis=0, how='all') for k, df in ref_rates.iteritems() } rev_rates = ref_rates['REVENUE RATE'] if rev_rates.revenue_rate.dtype == np.object: rev_rates['revenue_rate'] = rev_rates['revenue_rate'].apply( remove_dollar) cost_rates = ref_rates['COST RATE'] if cost_rates.cost_rate.dtype == np.object: cost_rates['cost_rate'] = cost_rates['cost_rate'].apply(remove_dollar) data = data.merge(rev_rates, on='program', how='left') data = data.merge(cost_rates, on=['campaign', 'refer'], how='left') return data
def get_alert_exclusions(gc, offline=None): filters_title = "BW-Video-Keen-Key" sheet = "ALERT-EXCLUSIONS" if offline: exclusions = offline_sheets.read_sheets(filters_title, sheet) else: exclusions = read_sheets(gc, filters_title, sheet) return exclusions
def get_filters(gc, offline=None): filters_title = "BW-Video-Keen-Key" sheet = "FILTERS" if offline: df_filter = offline_sheets.read_sheets(filters_title, sheet) else: df_filter = read_sheets(gc, filters_title, sheet) df_filter = df_filter.rename(columns={ "FilterVariable": "property_name", "Formula": "operator", "Value": "property_value"}) df_filter["operator"] = df_filter.operator.map(apply_operator_map) return df_filter.to_dict("records")
def get_alert_exclusions(gc, offline=None): filters_title = "BW-Video-Keen-Key" sheet = "ALERT-EXCLUSIONS" if offline: exclusions = offline_sheets.read_sheets(filters_title, sheet) else: exclusions = read_sheets(gc, filters_title, sheet) alertNames = exclusions.columns.tolist() alertNames.remove("campaign") for column in alertNames: exclusions[column] = exclusions[column].str.replace("X", "x") exclusions['exclude-' + column] = exclusions[column] == 'x' exclusions = exclusions.drop(axis=1, labels=alertNames) return exclusions
def get_filters(gc, offline=None): filters_title = "BW-Video-Keen-Key" sheet = "FILTERS" if offline: df_filter = offline_sheets.read_sheets(filters_title, sheet) else: df_filter = read_sheets(gc, filters_title, sheet) df_filter = df_filter.rename( columns={ "FilterVariable": "property_name", "Formula": "operator", "Value": "property_value" }) df_filter["operator"] = df_filter.operator.map(apply_operator_map) return df_filter.to_dict("records")
def get_alert_rules(gc, offline=None): filters_title = "BW-Video-Keen-Key" sheet = "ALERT-RULES" if offline: return offline_sheets.read_sheets(filters_title, sheet) return read_sheets(gc, filters_title, sheet)