def get_contributors_ranking_mbm_change_report()

in osci/postprocess/osci_change_report/osci_change_report.py [0:0]


def get_contributors_ranking_mbm_change_report(reports: Iterable[Tuple[datetime, pd.DataFrame]],
                                               contributor_field: str,
                                               commits_amount_field: str) -> pd.DataFrame:
    """Creates a combined report, that shows the difference between several contributors rankings

    :param reports: collection of datatime and pandas DataFrame objects
    :param contributor_field: contributor column name
    :param commits_amount_field: amount of commits column name
    """
    df_list = []
    for report in reports:
        tmp_df = pd \
            .pivot_table(report[1],
                         values=[commits_amount_field, ],
                         index=[report[1].index.values, contributor_field]) \
            .rename(columns={commits_amount_field: datetime.strftime(report[0], '%b')}) \
            .reset_index(contributor_field)
        df_list.append(tmp_df)
    df = reduce(lambda x, y: pd.merge(x, y, how='outer', on=contributor_field), df_list) \
        .sort_values(by=contributor_field).fillna(0)
    df.iloc[:, 1:] = df.iloc[:, 1:].astype(int)
    df['Total'] = df.sum(axis=1)
    return df