def get_cpus_power_table(data, index, opps, leak_factors):  # pylint: disable=too-many-locals
    # pylint: disable=no-member
    power_table = data[[index, 'cluster', 'cpus', 'power']].pivot_table(index=index,
                                                                        columns=['cluster', 'cpus'],
                                                                        values='power')
    bs_power_table = pd.DataFrame(index=power_table.index, columns=power_table.columns)
    for cluster in power_table.columns.levels[0]:
        power_table[cluster, 0] = (power_table[cluster, 1] -
                                   (power_table[cluster, 2] -
                                    power_table[cluster, 1]))
        bs_power_table.loc[power_table[cluster, 1].notnull(), (cluster, 1)] = fit_polynomial(power_table[cluster, 1].dropna(), 2)
        bs_power_table.loc[power_table[cluster, 2].notnull(), (cluster, 2)] = fit_polynomial(power_table[cluster, 2].dropna(), 2)

        if opps[cluster] is None:
            bs_power_table.loc[bs_power_table[cluster, 1].notnull(), (cluster, 0)] = \
                (2 * power_table[cluster, 1] - power_table[cluster, 2]).values
        else:
            voltages = opps[cluster].set_index('frequency').sort_index()
            leakage = leak_factors[cluster] * 2 * voltages['voltage']**3 / 0.9**3
            leakage_delta = leakage - leakage[leakage.index[0]]
            bs_power_table.loc[:, (cluster, 0)] = \
                (2 * bs_power_table[cluster, 1] + leakage_delta - bs_power_table[cluster, 2])

    # re-order columns and rename colum '0' to  'cluster'
    power_table = power_table[sorted(power_table.columns,
                                     cmp=lambda x, y: cmp(y[0], x[0]) or cmp(x[1], y[1]))]
    bs_power_table = bs_power_table[sorted(bs_power_table.columns,
                                           cmp=lambda x, y: cmp(y[0], x[0]) or cmp(x[1], y[1]))]
    old_levels = power_table.columns.levels
    power_table.columns.set_levels([old_levels[0], list(map(str, old_levels[1])[:-1]) + ['cluster']],
                                   inplace=True)
    bs_power_table.columns.set_levels([old_levels[0], list(map(str, old_levels[1])[:-1]) + ['cluster']],
                                      inplace=True)
    return power_table, bs_power_table
dataset/ETHPy150Open ARM-software/workload-automation/wlauto/instrumentation/energy_model/__init__.py/get_cpus_power_table/original