def read_campaign_retention():
    path_manager = EnvManager()
    resource_path = path_manager.get_resource_dir()
    source_dir = ospath.join(resource_path, 'campaign_retention')
    source_file = ospath.join(source_dir, 'campaign_retention.csv')
    source_data = pd.read_csv(
        source_file, usecols=['Date', 'Campaign', 'Install Day', 'Day 1'])

    sa_mask = source_data['Campaign'].apply(isContain, sub_string='_SA_')
    sa_data = source_data[sa_mask]
    sa_sum = sa_data.groupby('Date').sum()
    row_num = len(sa_sum.index)
    if row_num > 0:
        country_list = pd.Series(['SA'] * row_num, index=sa_sum.index)
        sa_sum['country'] = country_list

    ph_mask = source_data['Campaign'].apply(isContain, sub_string='_ph_')
    ph_data = source_data[ph_mask]
    ph_sum = ph_data.groupby('Date').sum()
    row_num = len(ph_sum.index)
    if row_num > 0:
        country_list = pd.Series(['PH'] * row_num, index=ph_sum.index)
        ph_sum['country'] = country_list

    result_data = pd.concat([sa_sum, ph_sum])

    writer = pd.ExcelWriter('sum_retention.xlsx')
    result_data.to_excel(writer, 'retention')
    writer.save()
def analysis_typany_retention():
    path_manager = EnvManager()
    resource_path = path_manager.get_resource_dir()
    typany_path = ospath.join(resource_path, 'typany')
    retention_file = ospath.join(typany_path, 'retention_typany.xlsx')
    retention_data = ReadExcelDataHandler.read_typany_retention(retention_file)
    # pivot_data = pd.pivot_table(retention_data, index=['Date', 'Country'], values=['Install Day', 'Day 1'],
    #                             aggfunc=np.sum, fill_value=0)
    pivot_data = retention_data.groupby(['Date', 'Country'],
                                        as_index=False).sum()

    output_dir = path_manager.get_output_dir()
    output_file = ospath.join(output_dir, 'typany.xlsx')
    writer = pd.ExcelWriter(output_file)
    pivot_data.to_excel(writer, 'retention')
    writer.save()
Example #3
0
    conversion_data['All conv.'] = conversion_data['All conv.'].apply(str.replace, args=(',', '')).apply(float)
    conversion_data['Cost'] = conversion_data['Cost'].apply(str.replace, args=(',', '')).apply(float)

    install_data = pd.read_excel(install_file, parse_cols="B, C")
    install_data['campaign'] = install_data['campaign'].apply(str)
    install_data.rename(columns={'campaign': 'Campaign ID', 'install': 'AF Install'}, inplace=True)

    merger_data = pd.merge(conversion_data, install_data, on='Campaign ID', how='outer')
    merger_data.fillna(0, inplace=True)
    merger_data['Other Conversion'] = merger_data['All conv.'] - merger_data['Conversions']
    merger_data['Cost/AF'] = map(comhelper.division_operation, merger_data['Cost'], merger_data['AF Install'])
    merger_data['Cost/Coversion'] = map(comhelper.division_operation, merger_data['Cost'], merger_data['Conversions'])
    merger_data['Cost/All'] = map(comhelper.division_operation, merger_data['Cost'], merger_data['All conv.'])
    merger_data['Cost/Other'] = map(comhelper.division_operation, merger_data['Cost'], merger_data['Other Conversion'])

    export_data = merger_data[['Campaign ID', 'Campaign', 'AF Install', 'Conversions', 'All conv.', 'Other Conversion',
                               'Cost', 'Cost/AF', 'Cost/Coversion', 'Cost/All', 'Cost/Other']]

    date_str = comhelper.get_delta_date(-1)
    file_name = 'adword_conversion_' + date_str + '.xlsx'
    export_file = ospath.join(output_root_path, file_name)
    ExcelExporter.export_data_excel(export_data, export_file)


if __name__ == '__main__':
    path_manager = EnvManager()
    resource_path = path_manager.get_resource_dir()
    conversion_path = ospath.join(resource_path, 'aw_conversion')
    output_path = path_manager.get_output_dir()
    export_conversion(conversion_path, output_path)