def before_overall_results_processing(self, context):
        # pylint: disable=too-many-locals
        if not self.idle_data or not self.freq_data:
            self.logger.warning('Run aborted early; not generating energy_model.')
            return
        output_directory = os.path.join(context.output_directory, 'energy_model')
        os.makedirs(output_directory)

        df = pd.DataFrame(self.idle_data, columns=['cluster', 'cpus', 'state_id',
                                                   'state', 'iteration', 'metric', 'value'])
        idle_power_table = wa_result_to_power_perf_table(df, '', index=['cluster', 'cpus', 'state'])
        idle_output = os.path.join(output_directory, IDLE_TABLE_FILE)
        with open(idle_output, 'w') as wfh:
            idle_power_table.to_csv(wfh, index=False)
        context.add_artifact('idle_power_table', idle_output, 'export')

        df = pd.DataFrame(self.freq_data,
                          columns=['cluster', 'cpus', 'frequency', 'iteration', 'metric', 'value'])
        freq_power_table = wa_result_to_power_perf_table(df, self.performance_metric,
                                                         index=['cluster', 'cpus', 'frequency'])
        freq_output = os.path.join(output_directory, FREQ_TABLE_FILE)
        with open(freq_output, 'w') as wfh:
            freq_power_table.to_csv(wfh, index=False)
        context.add_artifact('freq_power_table', freq_output, 'export')

        if self.big_opps is None or self.little_opps is None:
            message = 'OPPs not specified for one or both clusters; cluster power will not be adjusted for leakage.'
            self.logger.warning(message)
        opps = {'big': self.big_opps, 'little': self.little_opps}
        leakages = {'big': self.big_leakage, 'little': self.little_leakage}
        try:
            measured_cpus_table, cpus_table = get_cpus_power_table(freq_power_table, 'frequency', opps, leakages)
        except (ValueError, __HOLE__, IndexError) as e:
            self.logger.error('Could not create cpu power tables: {}'.format(e))
            return
        measured_cpus_output = os.path.join(output_directory, MEASURED_CPUS_TABLE_FILE)
        with open(measured_cpus_output, 'w') as wfh:
            measured_cpus_table.to_csv(wfh)
        context.add_artifact('measured_cpus_table', measured_cpus_output, 'export')
        cpus_output = os.path.join(output_directory, CPUS_TABLE_FILE)
        with open(cpus_output, 'w') as wfh:
            cpus_table.to_csv(wfh)
        context.add_artifact('cpus_table', cpus_output, 'export')

        em = build_energy_model(freq_power_table, cpus_table, idle_power_table, self.first_cluster_idle_state)
        em_file = os.path.join(output_directory, '{}_em.c'.format(self.device_name))
        em_text = generate_em_c_file(em, self.big_core, self.little_core,
                                     self.em_template_file, em_file)
        context.add_artifact('em', em_file, 'data')

        report_file = os.path.join(output_directory, 'report.html')
        generate_report(freq_power_table, measured_cpus_table, cpus_table,
                        idle_power_table, self.report_template_file,
                        self.device_name, em_text, report_file)
        context.add_artifact('pm_report', report_file, 'export')
dataset/ETHPy150Open ARM-software/workload-automation/wlauto/instrumentation/energy_model/__init__.py/EnergyModelInstrument.before_overall_results_processing