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_consumptiontext_report(config, submitted_by_user, g): """ Gathers data for consumption text report and generates it's PDF :param config: report configuration :param submitted_by_user: user who submitted the report :param g: g :return: report path """ report_path = DataReports.generate_consumptiontext_report(config.report_year, config.benchmark_year, SharedReporting.generate_consumptiontext_report(config, 'sic', g), submitted_by_user, config.account_type) return report_path
def generate_standards_pdf(config, standards_chart_info, standards_table_info, submitted_by, submitted_to): """ Generates an standards PDF and returns the path to the file :param config: report configuration :param standards_chart_info: standards chart info :param standards_table_info: standards table information :param submitted_by: user submitting the report :param submitted_to: group the report is for :return: path to pdf """ return DataReports.generate_component_standards_report(config, standards_chart_info, standards_table_info, submitted_by, submitted_to)
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
def generate_peak_report(config, submitted_by_user, submitted_to, g): """ Gathers data for peak report and generates it's PDF :param config: report configuration :param submitted_by_user: user who submitted the report :param submitted_to: group the report is addressed to :param g: g :return: path to PDF report """ data = get_peak_report_data(config, g) # generate peak report with data report_path = DataReports.generate_peak_report(data, config.report_year, submitted_by_user, submitted_to) return report_path
def generate_difference_pdf(config, difference_data, comparison_table_data, submitted_by, submitted_to): report_path = DataReports.generate_component_difference_report(config, difference_data, comparison_table_data, submitted_by, submitted_to) return report_path
def generate_variance_report(config, y_units, y_unit_map, submitted_by_user, submitted_to, g): """ Gathers data for variance report and generates it's PDF :param config: report configuration :param y_units: y units :param y_unit_map: database column name for y units :param submitted_by_user: user who submitted the report :param submitted_to: group who the report is addressed to :param g: g :return: path to PDF of report """ total_data = [] for code in config.entity_ids: sic_code = g.uow.sic.get_by_code(code) # get all accounts for sic code group_descendants = g.uow.sic.get_group_descendants(code) accounts = [] # check to make sure we should get electric accounts if config.account_type.lower() != 'gas': # get all electric accounts for desc in group_descendants: accounts += SharedReporting.get_accounts_for_group(desc, 'Electric', config.report_year, config.comparison_type, config.demand_type, g) accounts += SharedReporting.get_accounts_for_group(desc, 'Electric', config.benchmark_year, config.comparison_type, config.demand_type, g) # get all month utility, actual, benchmark, plan, variance ($), and variance (%) for every month in the report year electric_data = SharedReporting.get_variance_report_data(accounts, 'electric', config.report_year, config.benchmark_year, config.demand_type, y_units, y_unit_map, g) else: # create blank template so no null errors are thrown later electric_data = {"sitedata": [ {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "Variance ($)", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "Variance (%)", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} ]} accounts = [] if config.account_type.lower() != 'electric': # get all gas accounts for desc in group_descendants: accounts += SharedReporting.get_accounts_for_group(desc, 'Gas', config.report_year, config.comparison_type, config.demand_type, g) accounts += SharedReporting.get_accounts_for_group(desc, 'Gas', config.benchmark_year, config.comparison_type, config.demand_type, g) # get gas data gas_data = SharedReporting.get_variance_report_data(accounts, 'gas', config.report_year, config.benchmark_year, config.demand_type, y_units, y_unit_map, g) else: # create blank template so no null errors are thrown later gas_data = {"sitedata": [ {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "Variance ($)", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}, {"label": "Variance (%)", "data": [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]} ]} data = {"entity_name": sic_code["name"], "sitedata": [ {"label": "", "data": []}, {"label": "", "data": []}, {"label": "", "data": []}, {"label": "", "data": []}, {"label": "Variance ($)", "data": []}, {"label": "Variance (%)", "data": []} ]} # determine which site labels to use if config.account_type.lower() != 'electric': labels = [gas_data["sitedata"][0]["label"], gas_data["sitedata"][1]["label"], gas_data["sitedata"][2]["label"], gas_data["sitedata"][3]["label"]] else: labels = [electric_data["sitedata"][0]["label"], electric_data["sitedata"][1]["label"], electric_data["sitedata"][2]["label"], electric_data["sitedata"][3]["label"]] data["sitedata"][0]["label"] = labels[0] data["sitedata"][1]["label"] = labels[1] data["sitedata"][2]["label"] = labels[2] data["sitedata"][3]["label"] = labels[3] # add gas data to electric data utility_list = [a+b for a,b in zip(electric_data["sitedata"][0]["data"], gas_data["sitedata"][0]["data"])] actual_list = [a+b for a,b in zip(electric_data["sitedata"][1]["data"], gas_data["sitedata"][1]["data"])] benchmark_list = [a+b for a,b in zip(electric_data["sitedata"][2]["data"], gas_data["sitedata"][2]["data"])] plan_list = [a+b for a,b in zip(electric_data["sitedata"][3]["data"], gas_data["sitedata"][3]["data"])] cost_variance_list = [a+b for a,b in zip(electric_data["sitedata"][4]["data"], gas_data["sitedata"][4]["data"])] percent_variance_list = [a+b for a,b in zip(electric_data["sitedata"][5]["data"], gas_data["sitedata"][5]["data"])] # format all data to be used in the javascript utility_list = ["{:,d}".format(entry) for entry in utility_list] actual_list = ["{:,d}".format(entry) for entry in actual_list] benchmark_list = ["{:,d}".format(entry) for entry in benchmark_list] plan_list = ["{:,d}".format(entry) for entry in plan_list] percent_variance_list = ["{:,.2f}%".format(entry) for entry in percent_variance_list] locale.setlocale(locale.LC_ALL, '') cost_variance_list = [locale.currency(entry, grouping=True) for entry in cost_variance_list] # set the final data values data["entity_name"] = sic_code["name"] data["sitedata"][0]["data"] = utility_list data["sitedata"][1]["data"] = actual_list data["sitedata"][2]["data"] = benchmark_list data["sitedata"][3]["data"] = plan_list data["sitedata"][4]["data"] = cost_variance_list data["sitedata"][5]["data"] = percent_variance_list total_data.append(data) report_path = DataReports.generate_variance_report(total_data, config.report_year, config.benchmark_year, submitted_by_user, submitted_to) return report_path