def get_comparison_chart_data(config): """ Gets a list of the series used for the comparison report charts :param config: ComponentReportingComparisonConfiguration :return: TotalEnergyDataContainer that holds all information for the chart """ series_list = [] for entity in config.component_ids: # get label from the entity label = get_label_for_entity(entity) # get actual component_id from the list syrx_nums = get_syrx_nums_from_entity(entity) # combine the comparison year with the historical mode years all_years = list(set([config.comparison_year] + config.historical_years)) for year in all_years: new_series_data = {} for syrx_num in syrx_nums: # get the equipment point by syrx num ep = g.uow.equipment.get_equipment_point_by_syrx_num(syrx_num) # get the series data for each point syrx_series = g.uow.compiled_point_records.get_data_for_syrx_nums([syrx_num], year, 1, 12) if len(syrx_series) > 0: # convert the data to the new values conversion_factor = SharedReporting.get_component_point_conversion(ep['units'].lower(), config.unit) convert_data_to_btu_unit(syrx_series[0]['data'], conversion_factor) # add to the new_series_data add_to_new_series_data(new_series_data, syrx_series[0]['data']) if len(new_series_data) > 0: new_series_data_list = [] # change the data from a dictionary to list for key in sorted(new_series_data.keys()): new_series_data_list.append([key, new_series_data[key]]) # overwrite the point name with the component name new_series = [{"name": None, "data": new_series_data_list}] new_series[0]["name"] = label + " - " + str(year) series_list += new_series chart_info = TotalEnergyDataContainer() chart_info.title = "Intensity" chart_info.data = series_list chart_info.x_axis_label = "Temperature (F)" chart_info.y_axis_label = "Energy Consumption (" + SharedReporting.get_y_unit_label(config.unit) + ")" return chart_info
def get_comparison_pdf_report(config): if not config.submitted_to: return abort(409) submitted_by = g.uow.users.get_user_by_id(session["current_user"]["id"]) submitted_to = config.submitted_to # get the submitted by and submitted to submitted_by, submitted_to = SharedReporting.get_submitted_contacts(submitted_by, submitted_to, g) total_energy_chart_info = TotalEnergyDataContainer() report_name = "Component Comparison Report" total_energy_chart_info.y_axis_label = "Energy Consumption (BTU)" total_energy_chart_info.title = "Intensity" comparison_data = get_comparison_chart_data(config) comparison_table_data = get_comparison_table_data(config, config.comparison_year) report_path = generate_comparison_pdf(config, comparison_data, comparison_table_data, submitted_by, submitted_to) return send_file(report_path, mimetype='application/pdf', as_attachment=True, attachment_filename=report_name + '.pdf')
def get_standards_pdf_report(config): if not config.submitted_to: return abort(409) submitted_by = g.uow.users.get_user_by_id(session["current_user"]["id"]) submitted_to = config.submitted_to # get the submitted by and submitted to submitted_by, submitted_to = SharedReporting.get_submitted_contacts(submitted_by, submitted_to, g) total_energy_chart_info = TotalEnergyDataContainer() report_name = "Component Standards Report" total_energy_chart_info.y_axis_label = "Energy Consumption (BTU/sqft)" total_energy_chart_info.title = "Intensity" standards_data = get_standards_chart_data(config) standards_table_data = get_standards_table_data(config) report_path = generate_standards_pdf(config, standards_data, standards_table_data, submitted_by, submitted_to) # send file back out to user for download return send_file(report_path, mimetype='application/pdf', as_attachment=True, attachment_filename=report_name + '.pdf')
def get_report(config): report_name = "DefaultReportName" report_path = "" # make sure submitted_to isn't empty if not config.submitted_to: abort(400) submitted_by_user = g.uow.users.get_user_by_id(session["current_user"]["id"]) submitted_to = config.submitted_to # get submitted_by and submitted_to submitted_by_user, submitted_to = SharedReporting.get_submitted_contacts(submitted_by_user, submitted_to, g) total_energy_chart_info = TotalEnergyDataContainer() # determine the x units x_units = "F" total_energy_chart_info.x_axis_label = "Temperature (" + x_units + ")" if config.comparison_type == "dewpt": x_units = "Dewpt" total_energy_chart_info.x_axis_label = "Dewpt" elif config.comparison_type == "enthalpy": x_units = "Enthalpy" total_energy_chart_info.x_axis_label = "Enthalpy" # get actual y units to send back, and get their equivalent column in the database # then call the proper report function determined by config.report_type if config.report_type == "consumption": report_name = "Consumption_Report" if config.account_type.lower() == "electric": y_units = config.electric_units y_unit_map = 'sum_btu' total_energy_chart_info.title = 'Total Energy Usage - Electric' elif config.account_type.lower() == 'gas': y_units = config.gas_units y_unit_map = 'sum_btu' total_energy_chart_info.title = 'Total Energy Usage - Gas' else: y_units = config.btu_units y_unit_map = "sum_btu" total_energy_chart_info.title = 'Total Energy Usage' total_energy_chart_info.y_axis_label = 'Average Energy Usage (' + SharedReporting.get_y_unit_label(y_units) + ')' # generate consumption report report_path = generate_consumption_report(config, y_units, y_unit_map, total_energy_chart_info, submitted_by_user, submitted_to, g) elif config.report_type == "variance": report_name = "Variance Report" if config.account_type == "electric": y_units = config.electric_units elif config.account_type == "gas": y_units = config.gas_units else: y_units = config.btu_units y_unit_map = "sum_btu" report_path = generate_variance_report(config, y_units, y_unit_map, submitted_by_user, submitted_to, g) elif config.report_type == "kvar": report_name = "kVArh" y_units = "kvar" y_unit_map = "sum_kvar" total_energy_chart_info.y_axis_label = "Average Electric Usage (kVar)" total_energy_chart_info.title = "kVar" report_path = generate_kvarh_report(config, y_units, y_unit_map, total_energy_chart_info, submitted_by_user, submitted_to, g) elif config.report_type == "text": report_name = "Consumption Text Report" report_path = generate_consumptiontext_report(config, submitted_by_user, g) elif config.report_type == "kva": report_name = "kVah" y_units = "kva" y_unit_map = "kva" total_energy_chart_info.y_axis_label = "Average Electric Usage (kVa)" total_energy_chart_info.title = "kVa" report_path = generate_kvah_report(config, y_units, y_unit_map, total_energy_chart_info, submitted_by_user, submitted_to, g) elif config.report_type == "powerfactor": report_name = "Power Factor" y_units = "pf" y_unit_map = "pf" total_energy_chart_info.y_axis_label = "Average Power Factor" total_energy_chart_info.title = "Power Factor" report_path = generate_powerfactor_report(config, y_units, y_unit_map, total_energy_chart_info, submitted_by_user, submitted_to, g) elif config.report_type == "peak": report_name = "Peak Report" report_path = generate_peak_report(config, submitted_by_user, submitted_to, g) return send_file(report_path, mimetype='application/pdf', as_attachment=True, attachment_filename=report_name + '.pdf')