コード例 #1
0
def get_y_axis_and_conversion_factor(config):
    """
    Gets the y axis unit and conversion factor
    :param config: EquipmentReport
    :return: y_axis_unit, conversion_factor
    """
    y_axis_units = "Btu"

    same_unit = g.uow.equipment.all_of_same_unit(config.syrx_nums)

    # if all equipment points have the same unit, then we will use that unit as the y axis
    if same_unit:
        y_axis_units = g.uow.equipment.get_equipment_point_by_syrx_num(config.syrx_nums[0])

        if 'units' in y_axis_units:
            y_axis_units = y_axis_units['units']
        else:
            y_axis_units = "Binary"

        # if the unit is kWh then have a conversion factor, otherwise it will be 1
        if y_axis_units.lower() == "kwh":
            conversion_factor = SharedReporting.get_factor('kwh', 'sum_btu')
        else:
            conversion_factor = 1.0
    else:
        # otherwise, we keep the units in Btu
        conversion_factor = 1.0

    return y_axis_units, conversion_factor
コード例 #2
0
def get_total_energy_chart_data_web(sic_code, report_year, benchmark_year, account_type, comparison_type, demand_type,
                                    y_units, y_unit_map, g):
    """
    Gets the data for the energy consumption chart
    :param sic_code: sic code being reported on
    :param report_year: report year from configuration
    :param benchmark_year: benchmark year from configuration
    :param account_type: 'electric'/'gas'/'all'
    :param comparison_type: 'temp'/'dewpt'/'enthalpy'
    :param demand_type: 'all'/'peak'/'offpeak'
    :param y_units: y units used for reporting 'btu, mcf, etc'
    :param y_unit_map: mapping column for database (often 'sum_btu')
    :param g: g
    :return: object containing all necessary information
    """

    # determine if demand will be included in query
    consider_demand_type = False
    if demand_type != 'all':
        consider_demand_type = True

    same_year = report_year == benchmark_year

    # get unit factor for the selected y units
    unit_factor = SharedReporting.get_factor(y_units, y_unit_map)
    data = TotalEnergyData()

    # get group descendants of sic code
    descendants = g.uow.sic.get_group_descendants(sic_code)
    accounts = []

    # get all accounts for each group for the desired year
    for gr in descendants:
        accounts += SharedReporting.get_accounts_for_group(gr, account_type, report_year, comparison_type, demand_type, g)
        if not same_year:
            accounts += SharedReporting.get_accounts_for_group(gr, account_type, benchmark_year, comparison_type, demand_type, g)

    if len(accounts) < 1:
        benchmark_data = []
    else:
        benchmark_data = g.uow.compiled_energy_records.get_compiled_energy_records_for_report(accounts, data_field_name=y_unit_map, consider_demand_type=consider_demand_type)

    # group the data by value
    grouped = defaultdict(list)

    for d in benchmark_data:
        grouped[d['group']['value']].append(d)

    reported_consumption = []
    diff = []
    benchmark_diff = []
    benchmark_consumption = []

    # get the distinct values for the group
    grouped_keys = list(grouped.keys())
    grouped_keys.sort()

    # if the report year and benchmark year are the same, it will be handled differently
    if same_year:
        for value in grouped_keys:
            entry = grouped[value]
            record_value = entry[0]['reduction'][y_unit_map] * unit_factor / entry[0]['reduction']['sum_hours_in_record']
            reported_consumption.append([value, round(record_value, 5)])
            diff.append([value, 0])
            benchmark_consumption.append([value, round(record_value, 5)])
            benchmark_diff.append([value, 0])
    else:
        # loop through every distinct value and get all of the records for it
        for value in grouped_keys:
            entry = grouped[value]
            if len(entry) > 1:
                report_record = 0
                benchmark_record = 0
                report_avg_size = 0
                benchmark_avg_size = 0
                benchmark_record_hours = 0
                for record in entry:
                    if record['group']['year'] == report_year:
                        report_record_hours = record['reduction']['sum_hours_in_record']

                        # normalize the values
                        report_record = round(record['reduction'][y_unit_map] * unit_factor / report_record_hours, 5)
                        reported_consumption.append([value, report_record])

                        report_avg_size = record['reduction']['sum_size_normalization'] * 1.0 / report_record_hours
                    elif record['group']['year'] == benchmark_year:
                        benchmark_record_hours = record['reduction']['sum_hours_in_record']

                        # get the size and record value to be normalized later
                        benchmark_avg_size = record['reduction']['sum_size_normalization'] * 1.0 / benchmark_record_hours
                        benchmark_record = record['reduction'][y_unit_map] * unit_factor

                # normalize the benchmark value
                size_ratio = report_avg_size * 1.0 / benchmark_avg_size
                benchmark_record *= size_ratio
                benchmark_record /= benchmark_record_hours

                # add normalized value to charts
                benchmark_consumption.append([value, round(benchmark_record, 5)])
                benchmark_diff.append([value, 0])
                diff.append([value, benchmark_record - report_record])

        data.reported_consumption = reported_consumption
        data.benchmark_consumption = benchmark_consumption
        data.diff = diff
        data.benchmark_diff = benchmark_diff
        return data
コード例 #3
0
def calculate_pf_data(account_group, report_year, benchmark_year, same_year):
    """
    Calculates the powerfactor data for the account
    :param account_group: data for the account grouped by value
    :param report_year: current year for the report data
    :param benchmark_year: benchmark year to compare it to
    :param same_year: boolean value stating whether report_year == benchmark_year
    :return: TotalEnergyData
    """
    # initialize all variables for this account/year combination
    reported_consumption = []
    diff = []
    benchmark_diff = []
    benchmark_consumption = []

    grouped_keys = list(account_group.keys())
    grouped_keys.sort()

    kwh_unit_factor = SharedReporting.get_factor('kwh', 'sum_btu')

    # if the benchmark year and current year are the same they will be handled differently
    if same_year:
        for value in grouped_keys:
            entry = account_group[value][0]

            # calculate powerfactor
            record_kwh = entry["reduction"]["sum_btu"] * kwh_unit_factor
            record_kvar = math.sqrt(math.pow(record_kwh, 2) + math.pow(entry['reduction']['sum_kvar'], 2))
            record_pf = record_kwh * 1.0 / record_kvar

            # update lists of data
            reported_consumption.append([value, round(record_pf, 5)])
            diff.append([value, 0])
            benchmark_consumption.append([value, round(record_pf, 5)])
            benchmark_diff.append([value, 0])
    else:
        # loop through each entry in the keys
        for value in grouped_keys:
            entry = account_group[value]

            # if the data exists for both years
            if len(entry) > 1:
                record_pf = 0
                reported_avg_size = 0
                benchmark_avg_size = 0
                benchmark_record_btu_normalized = 0
                benchmark_record_kvar_normalized = 0
                for record in entry:
                    if record['group']['year'] == report_year:
                        # calculate powerfactor
                        record_kwh = record['reduction']['sum_btu'] * kwh_unit_factor
                        record_kvar = math.sqrt(math.pow(record_kwh, 2) + math.pow(record['reduction']['sum_kvar'], 2))
                        record_pf = record_kwh * 1.0 / record_kvar

                        report_record_hours = record['reduction']['sum_hours_in_record']
                        reported_avg_size = record['reduction']['sum_size_normalization'] * 1.0 / report_record_hours

                        # update list
                        reported_consumption.append([value, round(record_pf, 5)])
                    elif record['group']['year'] == benchmark_year:
                        benchmark_avg_size = record['reduction']['sum_size_normalization'] * 1.0 / record['reduction']['sum_hours_in_record']
                        benchmark_record_btu_normalized = record['reduction']['sum_btu']
                        benchmark_record_kvar_normalized = record['reduction']['sum_kvar']

                # normalize the btu and kvar to properly calculate pf
                size_ratio = reported_avg_size * 1.0 / benchmark_avg_size
                benchmark_record_btu_normalized *= size_ratio
                benchmark_record_kvar_normalized *= size_ratio
                benchmark_kwh = benchmark_record_btu_normalized * kwh_unit_factor
                benchmark_kvar = math.sqrt(math.pow(benchmark_kwh, 2) + math.pow(benchmark_record_kvar_normalized, 2))
                benchmark_pf = benchmark_kwh * 1.0 / benchmark_kvar

                # update lists
                benchmark_consumption.append([value, round(benchmark_pf, 5)])
                benchmark_diff.append([value, 0])
                diff.append([value, round(benchmark_pf - record_pf, 5)])

    # create a new data object to be returned
    data = TotalEnergyData()

    data.reported_consumption = reported_consumption
    data.benchmark_consumption = benchmark_consumption
    data.diff = diff
    data.benchmark_diff = benchmark_diff

    return data