Skip to content

Commit

Permalink
feat: implement Voltage
Browse files Browse the repository at this point in the history
  • Loading branch information
unexcellent committed Nov 19, 2024
1 parent 807c3e7 commit 87da114
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 29 deletions.
17 changes: 12 additions & 5 deletions generate/generate_boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,24 @@ def _generat_zero_function(current_class: str) -> list[str]:
"watts": "1",
"milliwatts": "10**-3",
},
"Velocity": {
"meters_per_second": "1",
"kilometers_per_hour": "(1 / 3.6)",
"miles_per_hour": "(1 / 2.23694)",
},
"Time": {
"hours": "60 * 60",
"minutes": "60",
"seconds": "1",
"milliseconds": "10**-3",
},
"Velocity": {
"meters_per_second": "1",
"kilometers_per_hour": "(1 / 3.6)",
"miles_per_hour": "(1 / 2.23694)",
},
"Voltage": {
"gigavolts": "10**9",
"megavolts": "10**6",
"kilovolts": "10**3",
"volts": "1",
"millivolts": "10**-3",
},
}

generate_boilerplate(quantities_with_fields)
2 changes: 2 additions & 0 deletions quantio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
Power,
Time,
Velocity,
Voltage,
)
from .vector import Vector

Expand All @@ -30,6 +31,7 @@
"Power",
"Time",
"Velocity",
"Voltage",
"Vector",
"CanNotAddTypesError",
"CanNotSubtractTypesError",
Expand Down
104 changes: 80 additions & 24 deletions quantio/quantities.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,55 @@ def zero(cls) -> Power:
# --- End of auto generated part. ---


class Time(_QuantityBase):
"""The duration of an event."""

# --- This part is auto generated. Do not change manually. ---

BASE_UNIT = "seconds"

@property
def hours(self) -> float:
"""The time in hours."""
return self._base_value / 60 * 60

@property
def minutes(self) -> float:
"""The time in minutes."""
return self._base_value / 60

@property
def seconds(self) -> float:
"""The time in seconds."""
return self._base_value / 1

@property
def milliseconds(self) -> float:
"""The time in milliseconds."""
return self._base_value / 10**-3

def __init__(
self,
_base_value: float = 0.0,
hours: float = 0.0,
minutes: float = 0.0,
seconds: float = 0.0,
milliseconds: float = 0.0,
) -> None:
self._base_value = _base_value
self._base_value += hours * 60 * 60
self._base_value += minutes * 60
self._base_value += seconds * 1
self._base_value += milliseconds * 10**-3

@classmethod
def zero(cls) -> Time:
"""Create a Time with a value of zero."""
return Time()

# --- End of auto generated part. ---


class Velocity(_QuantityBase):
"""Distance per time."""

Expand Down Expand Up @@ -612,50 +661,57 @@ def zero(cls) -> Velocity:
# --- End of auto generated part. ---


class Time(_QuantityBase):
"""The duration of an event."""
class Voltage(_QuantityBase):
"""The difference in electric potential between two points."""

# --- This part is auto generated. Do not change manually. ---

BASE_UNIT = "seconds"
BASE_UNIT = "volts"

@property
def hours(self) -> float:
"""The time in hours."""
return self._base_value / 60 * 60
def gigavolts(self) -> float:
"""The voltage in gigavolts."""
return self._base_value / 10**9

@property
def minutes(self) -> float:
"""The time in minutes."""
return self._base_value / 60
def megavolts(self) -> float:
"""The voltage in megavolts."""
return self._base_value / 10**6

@property
def seconds(self) -> float:
"""The time in seconds."""
def kilovolts(self) -> float:
"""The voltage in kilovolts."""
return self._base_value / 10**3

@property
def volts(self) -> float:
"""The voltage in volts."""
return self._base_value / 1

@property
def milliseconds(self) -> float:
"""The time in milliseconds."""
def millivolts(self) -> float:
"""The voltage in millivolts."""
return self._base_value / 10**-3

def __init__(
self,
_base_value: float = 0.0,
hours: float = 0.0,
minutes: float = 0.0,
seconds: float = 0.0,
milliseconds: float = 0.0,
gigavolts: float = 0.0,
megavolts: float = 0.0,
kilovolts: float = 0.0,
volts: float = 0.0,
millivolts: float = 0.0,
) -> None:
self._base_value = _base_value
self._base_value += hours * 60 * 60
self._base_value += minutes * 60
self._base_value += seconds * 1
self._base_value += milliseconds * 10**-3
self._base_value += gigavolts * 10**9
self._base_value += megavolts * 10**6
self._base_value += kilovolts * 10**3
self._base_value += volts * 1
self._base_value += millivolts * 10**-3

@classmethod
def zero(cls) -> Time:
"""Create a Time with a value of zero."""
return Time()
def zero(cls) -> Voltage:
"""Create a Voltage with a value of zero."""
return Voltage()

# --- End of auto generated part. ---

0 comments on commit 87da114

Please sign in to comment.