def generate_kvarh_report(config, y_units, y_unit_map, total_energy_chart_info, submitted_by_user, submitted_to, g):
    """
    Gathers data for the kVar report and generates it's PDF
    :param config: report configuration
    :param y_units: y units
    :param y_unit_map: database column name for y unit
    :param total_energy_chart_info: TotalEnergyChartInfo object to hold data
    :param submitted_by_user: user who submitted the report
    :param submitted_to: group who the report what submitted to
    :param g: g
    :return: path to the report PDF
    """
    for code in config.entity_ids:
        sic_code = g.uow.sic.get_by_code(code)

        # get data associated with each account in the sic code
        accounts = []
        group_descendants = g.uow.sic.get_group_descendants(code)
        for gr in group_descendants:
            accounts += SharedReporting.get_accounts_for_group(gr, 'Electric', config.report_year, config.comparison_type, config.demand_type, g)
        data = SharedReporting.get_total_energy_chart_data_pdf(accounts, config.report_year, config.benchmark_year, config.demand_type, y_units, y_unit_map, g)
        total_energy_chart_info.data.append({'entity': sic_code["name"], 'data': data})

    # Generate consumption report with data
    report_path = DataReports.generate_kvarh_report(config.report_year, config.benchmark_year, total_energy_chart_info, submitted_by_user, submitted_to)
    return report_path
def generate_consumption_report(config, y_units, y_unit_map, total_energy_chart_info, submitted_by_user, submitted_to, g):
    """
    Gathers data and generates a pdf from it
    :param config:
    :param y_units:
    :param y_unit_map:
    :param total_energy_chart_info:
    :param submitted_by_user:
    :param submitted_to:
    :param g:
    :return:
    """
    # collect information for intensity chart
    intensity_chart_info = get_intensity_chart_data(config.entity_ids, config.account_type, config.report_year,
                                                    config.comparison_type, config.demand_type, g)

    year_group_grouping = {}
    # loop through every SIC code in the configuration and get their consumption chart data
    for code in config.entity_ids:
        # get the sic code and it's group descendants
        sic_code = g.uow.sic.get_by_code(code)
        group_descendants = g.uow.sic.get_group_descendants(code)

        # get all accounts for the SIC code
        accounts = []
        for gr in group_descendants:
            accounts += SharedReporting.get_accounts_for_group(gr, config.account_type, config.report_year,
                                                               config.comparison_type, config.demand_type, g)

        # get data associated with each account
        data = SharedReporting.get_total_energy_chart_data_pdf(accounts, config.report_year, config.benchmark_year, config.demand_type,
                                               y_units, y_unit_map, g)
        total_energy_chart_info.data.append({'entity': sic_code['name'], 'data': data['chart_data']})

        for year in data['year_data']:
            # check if the year has not been added to the group before
            if not year in year_group_grouping:
                # the year hasn't been added to the grouping, so just create a new entry in the dictionary
                year_group_grouping[year] = [{'entity': sic_code['name'] + ' (' + str(year) + ')',
                                              'data': data['year_data'][year]}]
            else:
                # append the entry
                year_group_grouping[year].append({'entity': sic_code['name'] + ' (' + str(year) + ')',
                                                  'data': data['year_data'][year]})

    # generate report data and get the report path
    report_path = DataReports.generate_consumption_report(config.report_year, config.benchmark_year,
                                                          intensity_chart_info, total_energy_chart_info,
                                                          year_group_grouping, submitted_by_user, submitted_to,
                                                          SharedReporting.get_y_unit_label(y_units))
    return report_path