def nested_to_flat(nested_output):
    """
    Convenience function for comparing two results dictionary.
    Used in many built-in tests (before passing both dicts to check_common_outputs).

    Arguments:
        nested_output: dict, API response
    """
    base = {
        'run_uuid': nested_output['Scenario']['run_uuid'],
        'api_version': nested_output['Scenario']['api_version'],
        'status': nested_output['Scenario']['status'],

        'year_one_electric_load_series': nested_output['Scenario']['Site']['LoadProfile']['year_one_electric_load_series_kw'],
        
        'lcc': nested_output['Scenario']['Site']['Financial']['lcc_us_dollars'],
        'lcc_bau': nested_output['Scenario']['Site']['Financial']['lcc_bau_us_dollars'],
        'npv': nested_output['Scenario']['Site']['Financial']['npv_us_dollars'],
        'net_capital_costs_plus_om': nested_output['Scenario']['Site']['Financial']['net_capital_costs_plus_om_us_dollars'],
        'avoided_outage_costs_us_dollars': nested_output['Scenario']['Site']['Financial']['avoided_outage_costs_us_dollars'],
        'microgrid_upgrade_cost_us_dollars': nested_output['Scenario']['Site']['Financial']['microgrid_upgrade_cost_us_dollars'],

        'pv_kw': nested_output['Scenario']['Site']['PV']['size_kw'],
        'year_one_energy_produced': nested_output['Scenario']['Site']['PV']['year_one_energy_produced_kwh'],
        'pv_kw_ac_hourly': nested_output['Scenario']['Site']['PV']['year_one_power_production_series_kw'],
        'average_yearly_pv_energy_produced': nested_output['Scenario']['Site']['PV']['average_yearly_energy_produced_kwh'],
        'average_annual_energy_exported': nested_output['Scenario']['Site']['PV']['average_yearly_energy_exported_kwh'],
        'year_one_pv_to_battery_series': nested_output['Scenario']['Site']['PV']['year_one_to_battery_series_kw'],
        'year_one_pv_to_load_series': nested_output['Scenario']['Site']['PV']['year_one_to_load_series_kw'],
        'year_one_pv_to_grid_series': nested_output['Scenario']['Site']['PV']['year_one_to_grid_series_kw'],
        'existing_pv_om_cost_us_dollars': nested_output['Scenario']['Site']['PV']['existing_pv_om_cost_us_dollars'],
        
        'batt_kw': nested_output['Scenario']['Site']['Storage']['size_kw'],
        'batt_kwh': nested_output['Scenario']['Site']['Storage']['size_kwh'],
        'year_one_battery_to_load_series': nested_output['Scenario']['Site']['Storage']['year_one_to_load_series_kw'],
        'year_one_battery_to_grid_series': nested_output['Scenario']['Site']['Storage']['year_one_to_grid_series_kw'],
        'year_one_battery_soc_series': nested_output['Scenario']['Site']['Storage']['year_one_soc_series_pct'],

        'year_one_energy_cost': nested_output['Scenario']['Site']['ElectricTariff']['year_one_energy_cost_us_dollars'],
        'year_one_demand_cost': nested_output['Scenario']['Site']['ElectricTariff']['year_one_demand_cost_us_dollars'],
        'year_one_fixed_cost': nested_output['Scenario']['Site']['ElectricTariff']['year_one_fixed_cost_us_dollars'],
        'year_one_min_charge_adder': nested_output['Scenario']['Site']['ElectricTariff']['year_one_min_charge_adder_us_dollars'],
        'year_one_energy_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['year_one_energy_cost_bau_us_dollars'],
        'year_one_demand_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['year_one_demand_cost_bau_us_dollars'],
        'year_one_fixed_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['year_one_fixed_cost_bau_us_dollars'],
        'year_one_min_charge_adder_bau': nested_output['Scenario']['Site']['ElectricTariff']['year_one_min_charge_adder_bau_us_dollars'],
        'total_energy_cost': nested_output['Scenario']['Site']['ElectricTariff']['total_energy_cost_us_dollars'],
        'total_demand_cost': nested_output['Scenario']['Site']['ElectricTariff']['total_demand_cost_us_dollars'],
        'total_fixed_cost': nested_output['Scenario']['Site']['ElectricTariff']['total_fixed_cost_us_dollars'],
        'total_min_charge_adder': nested_output['Scenario']['Site']['ElectricTariff']['total_min_charge_adder_us_dollars'],
        'total_energy_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['total_energy_cost_bau_us_dollars'],
        'total_demand_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['total_demand_cost_bau_us_dollars'],
        'total_fixed_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['total_fixed_cost_bau_us_dollars'],
        'total_min_charge_adder_bau': nested_output['Scenario']['Site']['ElectricTariff']['total_min_charge_adder_bau_us_dollars'],
        'year_one_bill': nested_output['Scenario']['Site']['ElectricTariff']['year_one_bill_us_dollars'],
        'year_one_bill_bau': nested_output['Scenario']['Site']['ElectricTariff']['year_one_bill_bau_us_dollars'],
        'year_one_export_benefit': nested_output['Scenario']['Site']['ElectricTariff']['year_one_export_benefit_us_dollars'],
        'year_one_grid_to_load_series': nested_output['Scenario']['Site']['ElectricTariff']['year_one_to_load_series_kw'],
        'year_one_grid_to_battery_series': nested_output['Scenario']['Site']['ElectricTariff']['year_one_to_battery_series_kw'],
        'year_one_energy_cost_series': nested_output['Scenario']['Site']['ElectricTariff']['year_one_energy_cost_series_us_dollars_per_kwh'],
        'year_one_demand_cost_series': nested_output['Scenario']['Site']['ElectricTariff']['year_one_demand_cost_series_us_dollars_per_kw'],
        'year_one_utility_kwh': nested_output['Scenario']['Site']['ElectricTariff']['year_one_energy_supplied_kwh'],
        'year_one_payments_to_third_party_owner': None,
        'total_payments_to_third_party_owner': None,
        'year_one_coincident_peak_cost': nested_output['Scenario']['Site']['ElectricTariff']['year_one_coincident_peak_cost_us_dollars'],
        'year_one_coincident_peak_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['year_one_coincident_peak_cost_bau_us_dollars'],
        'total_coincident_peak_cost': nested_output['Scenario']['Site']['ElectricTariff']['total_coincident_peak_cost_us_dollars'],
        'total_coincident_peak_cost_bau': nested_output['Scenario']['Site']['ElectricTariff']['total_coincident_peak_cost_bau_us_dollars']
    }
    if nested_output['Scenario']['Site'].get('Wind') is not None:
        base.update({
            'wind_kw':nested_output['Scenario']['Site']['Wind']['size_kw'],
            'average_yearly_wind_energy_produced':nested_output['Scenario']['Site']['Wind']['average_yearly_energy_produced_kwh'],
            'average_annual_energy_exported_wind': nested_output['Scenario']['Site']['Wind']['average_yearly_energy_exported_kwh'],
            'year_one_wind_to_battery_series': nested_output['Scenario']['Site']['Wind']['year_one_to_battery_series_kw'],
            'year_one_wind_to_load_series': nested_output['Scenario']['Site']['Wind']['year_one_to_load_series_kw'],
            'year_one_wind_to_grid_series': nested_output['Scenario']['Site']['Wind']['year_one_to_grid_series_kw']
       })
    if nested_output['Scenario']['Site'].get('Generator') is not None:
        base.update({
            'gen_kw':nested_output['Scenario']['Site']['Generator']['size_kw'],
            'average_yearly_gen_energy_produced':nested_output['Scenario']['Site']['Generator']['average_yearly_energy_produced_kwh'],
            'average_annual_energy_exported_gen': nested_output['Scenario']['Site']['Generator']['average_yearly_energy_exported_kwh'],
            'year_one_gen_to_battery_series': nested_output['Scenario']['Site']['Generator']['year_one_to_battery_series_kw'],
            'year_one_gen_to_load_series': nested_output['Scenario']['Site']['Generator']['year_one_to_load_series_kw'],
            'year_one_gen_to_grid_series': nested_output['Scenario']['Site']['Generator']['year_one_to_grid_series_kw'],
            'fuel_used_gal': nested_output['Scenario']['Site']['Generator']['fuel_used_gal'],
            'existing_gen_total_fixed_om_cost_us_dollars': nested_output['Scenario']['Site']['Generator']['existing_gen_total_fixed_om_cost_us_dollars'],
            'existing_gen_total_variable_om_cost_us_dollars': nested_output['Scenario']['Site']['Generator'][
                'existing_gen_total_variable_om_cost_us_dollars'],
            'total_fuel_cost_us_dollars': nested_output['Scenario']['Site']['Generator'][
                'total_fuel_cost_us_dollars'],
            'gen_total_variable_om_cost_us_dollars': nested_output['Scenario']['Site']['Generator'][
                'total_variable_om_cost_us_dollars'],
            'existing_gen_total_fuel_cost_us_dollars': nested_output['Scenario']['Site']['Generator'][
                'existing_gen_total_fuel_cost_us_dollars'],
       })
    return base