Пример #1
0
    def test_view_that_returns_valid_types_and_units_for_meters(self):
        url = reverse('api:v3:meters-valid-types-units')

        result = self.client.get(url)
        result_dict = ast.literal_eval(result.content.decode("utf-8"))

        expectation = {
            type: list(units.keys())
            for type, units in kbtu_thermal_conversion_factors("US").items()
        }

        self.assertEqual(result_dict, expectation)
Пример #2
0
    def valid_types_units(self, request):
        """
        Returns the valid type for units.

        The valid type and unit combinations are built from US Thermal Conversion
        values. As of this writing, the valid combinations are the same as for
        Canadian conversions, even though the actual factors may differ between
        the two.
        (https://portfoliomanager.energystar.gov/pdf/reference/Thermal%20Conversions.pdf)
        """
        return {
            type: list(units.keys())
            for type, units in kbtu_thermal_conversion_factors("US").items()
        }
Пример #3
0
    def __init__(self, xml_file):
        self._xml_file = xml_file
        self._cache_data = None

        # Codes taken from https://bedes.lbl.gov/sites/default/files/Green%20Button%20V0.7.2%20to%20BEDES%20V2.1%20Mapping%2020170927.pdf
        self.kind_codes = {
            0: 'Electric - Grid',  # listed as 'electricity'
            1: 'Natural Gas',  # listed as 'gas'
        }
        self.uom_codes = {
            31: 'J',
            42: 'cubic meters',  # listed as 'm3'
            72: 'Wh',
            119: 'cf',  # listed as 'ft3'
            132: 'Btu',  # listed as 'btu'
            169: 'therms',  # listed as 'therm'
        }
        self.power_of_ten_codes = {
            -12: 'p',  # Pico: 10^-12
            -9: 'n',  # Nano: 10^-9
            -6: 'micro',  # Micro: 10^-6
            -3: 'm',  # Milli: 10^-3
            -1: 'd',  # Deci: 10^-1
            0: '',  # N/A
            1: 'da',  # Deca: 10^1
            2: 'h',  # Hecto: 10^2
            3: 'k',  # Kilo: 10^3
            6: 'M',  # Mega: 10^6
            9: 'G',  # Giga: 10^9
            12: 'T',  # Tera: 10^12
        }

        # US factors work for CAN factors as this is only used to find valid unit types for a given energy type
        self._thermal_factors = kbtu_thermal_conversion_factors("US")

        # These are the valid unit prefixes found in thermal conversions
        self.thermal_factor_prefixes = {
            'k': 3,
            'M': 6,
            'G': 9,
            'c': 2,
        }
Пример #4
0
    def factors(self):
        if self._cache_factors is None:
            self._cache_factors = kbtu_thermal_conversion_factors(
                self._org_country)

        return self._cache_factors
Пример #5
0
 def valid_type_and_unit_combinations(country):
     return {
         type: [unit for unit in unit_factors.keys()]
         for type, unit_factors in kbtu_thermal_conversion_factors(
             country).items()
     }
Пример #6
0
 def valid_types_units(self, request):
     return {
         type: list(units.keys())
         for type, units in kbtu_thermal_conversion_factors("US").items()
     }