Skip to content

Add unit enums with converters for commonly used units #229

Description

@Tom-Kingstone

Description:

would be better than having to implement this in every toolkit in a different way...

eg.

class PowerUnit(Enum)
    W = ("Watt", 1)
    kW = ("Kilowatt", 1e3)
    MW = ("Megawatt", 1e6)
    BTU_hr = ("British Thermal Unit / hour", 3.412141633)
    kBTU_hr = ("Kilo British Thermal Unit / hour", 3.412141633e3)
    MBTU_hr = ("Mega British Thermal Unit / hour", 3.412141633e6)

    def convert(self, value: float, to_unit: PowerUnit):
        return (value * self.value[1]) / to_unit.value[1]

#usage
some_value_in_kW = 40

new_value_in_BTU_hr = PowerUnit.kW.convert(some_value_in_kW, PowerUnit.BTU)

for now I think we can do the common ones that are used elsewhere:

  • Power
  • Energy
  • Temperature
  • Distance
  • Area
  • Speed

Metadata

Metadata

Assignees

Labels

type:featureNew capability or enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions