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_encrave_costs(gc, data, report_type): title = "Encrave Report Summaries" encrave_costs = read_sheets(gc, title, report_type) encrave_costs = encrave_costs[['campaign', 'Cost', 'ReportName']] encrave_costs['refer'] = 'en' encrave_costs = encrave_costs.rename(columns={ 'Cost': 'encrave_cost', 'ReportName': "encrave_source" }) data = data.merge(encrave_costs, on=['campaign', 'refer'], how='outer', validate='1:1', indicator=True) left_only_idx = (data.refer == 'en') & (data._merge == 'left_only') if left_only_idx.any(): warn("keen data has 'en' campaigns not contained in Encrave report") warn("CampaignNames: %s" % data.loc[left_only_idx, 'campaign'].tolist()) right_only_idx = (data.refer == 'en') & (data._merge == 'right_only') if right_only_idx.any(): warn("Encrave data has campaigns not contained in keen data") warn("CampaignNames: %s" % data.loc[right_only_idx, 'campaign'].tolist()) data = data[data._merge != 'right_only'] data.drop(axis=1, labels='_merge', inplace=True) 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 add_encrave_costs(gc, data, report_type): title = "Encrave Report Summaries" encrave_costs = read_sheets(gc, title, report_type) encrave_costs = encrave_costs[['campaign', 'Cost', 'ReportName']] encrave_costs['refer'] = 'en' encrave_costs = encrave_costs.rename( columns={'Cost': 'encrave_cost', 'ReportName': "encrave_source"}) data = data.merge(encrave_costs, on=['campaign', 'refer'], how='outer', validate='1:1', indicator=True) left_only_idx = (data.refer=='en') & (data._merge=='left_only') if left_only_idx.any(): warn("keen data has 'en' campaigns not contained in Encrave report") warn("CampaignNames: %s" % data.loc[left_only_idx, 'campaign'].tolist()) right_only_idx = (data.refer=='en') & (data._merge=='right_only') if right_only_idx.any(): warn("Encrave data has campaigns not contained in keen data") warn("CampaignNames: %s" % data.loc[right_only_idx, 'campaign'].tolist()) data = data[data._merge!='right_only'] data.drop(axis=1, labels='_merge', inplace=True) return data
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)