-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add unit formatter system with enums and conversion logic #679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Axlrbs
wants to merge
10
commits into
main
Choose a base branch
from
features/add-unit-formatter-system
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a19e29
feat: add unit formatter system with enums and conversion logic
Axlrbs 88bc546
feat: implement unit formatter system with SI prefixes and update uni…
Axlrbs 7c34bce
feat: enhance unit formatter with family-based conversions and add un…
Axlrbs 01d6ec3
feat: refine unit definitions and enhance unit registry with family a…
Axlrbs 1c1f8a6
Merge branch 'main' into features/add-unit-formatter-system
Axlrbs f36e5eb
Refactor unit formatting and conversion logic in useUnitFormatter
Axlrbs fc948d9
feat: enhance unit parsing logic in useUnitFormatter and add extractU…
Axlrbs 6820bce
fix: copilot review
Axlrbs c783056
feat: add Area unit and support for exponent conversions
Axlrbs d821346
Merge branch 'main' into features/add-unit-formatter-system
Axlrbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| export enum UnitPrefix { | ||
| None = "", | ||
| Nano = "n", | ||
| Micro = "µ", | ||
| Milli = "m", | ||
| Kilo = "k", | ||
| Mega = "M", | ||
| Giga = "G", | ||
| Tera = "T", | ||
| Peta = "P" | ||
| } | ||
|
|
||
| export enum UnitFamily { | ||
| Energy = "energy", | ||
| Power = "power", | ||
| Volume = "volume", | ||
| GasVolume = "gasVolume", | ||
| WaterFlow = "waterFlow", | ||
| GasFlow = "gasFlow", | ||
| Pressure = "pressure", | ||
| Temperature = "temperature", | ||
| Speed = "speed", | ||
| Distance = "distance", | ||
| Mass = "mass", | ||
| MassFlow = "massFlow", | ||
| Frequency = "frequency", | ||
| Voltage = "voltage", | ||
| Current = "current", | ||
| Resistance = "resistance", | ||
| Percentage = "percentage", | ||
| Capacity = "capacity", | ||
| SnowProduction = "snowProduction", | ||
| Efficiency = "efficiency" | ||
| } | ||
|
|
||
|
|
||
| export enum EnergyUnit { | ||
| Wh = "Wh", | ||
| kWh = "kWh", | ||
| MWh = "MWh", | ||
| GWh = "GWh", | ||
| TWh = "TWh", | ||
| } | ||
|
|
||
| export enum PowerUnit { | ||
| W = "W", | ||
| kW = "kW", | ||
| MW = "MW", | ||
| GW = "GW", | ||
| TW = "TW", | ||
| } | ||
|
|
||
| export enum VolumeUnit { | ||
| mL = "mL", | ||
| L = "L", | ||
| m3 = "m3", | ||
| dam3 = "dam3", | ||
| } | ||
|
|
||
| export enum GasVolumeUnit { | ||
| Nm3 = "Nm3", | ||
| kNm3 = "kNm3", | ||
| MNm3 = "MNm3", | ||
| GNm3 = "GNm3", | ||
| } | ||
|
|
||
| export enum WaterFlowUnit { | ||
| mL_s = "mL/s", | ||
| L_s = "L/s", | ||
| m3_s = "m3/s", | ||
| L_min = "L/min", | ||
| m3_h = "m3/h", | ||
| } | ||
|
|
||
| export enum GasFlowUnit { | ||
| Nm3_h = "Nm3/h", | ||
| kNm3_h = "kNm3/h", | ||
| MNm3_h = "MNm3/h", | ||
| } | ||
|
|
||
| export enum PressureUnit { | ||
| Pa = "Pa", | ||
| kPa = "kPa", | ||
| MPa = "MPa", | ||
| GPa = "GPa", | ||
| bar = "bar", | ||
| mbar = "mbar", | ||
| } | ||
|
|
||
| export enum TemperatureUnit { | ||
| Celsius = "°C", | ||
| Kelvin = "K", | ||
| Fahrenheit = "°F", | ||
| } | ||
|
|
||
| export enum SpeedUnit { | ||
| m_s = "m/s", | ||
| km_h = "km/h", | ||
| knot = "kn", | ||
| } | ||
|
|
||
| export enum DistanceUnit { | ||
| mm = "mm", | ||
| cm = "cm", | ||
| m = "m", | ||
| km = "km", | ||
| } | ||
|
|
||
| export enum MassUnit { | ||
| mg = "mg", | ||
| g = "g", | ||
| kg = "kg", | ||
| t = "t", | ||
| kt = "kt", | ||
| Mt = "Mt", | ||
| } | ||
|
|
||
| export enum MassFlowUnit { | ||
| g_s = "g/s", | ||
| kg_s = "kg/s", | ||
| t_s = "t/s", | ||
| kg_h = "kg/h", | ||
| t_h = "t/h", | ||
| } | ||
|
|
||
| export enum FrequencyUnit { | ||
| Hz = "Hz", | ||
| kHz = "kHz", | ||
| MHz = "MHz", | ||
| GHz = "GHz", | ||
| rpm = "rpm", | ||
| } | ||
|
|
||
| export enum VoltageUnit { | ||
| mV = "mV", | ||
| V = "V", | ||
| kV = "kV", | ||
| MV = "MV", | ||
| } | ||
|
|
||
| export enum CurrentUnit { | ||
| mA = "mA", | ||
| A = "A", | ||
| kA = "kA", | ||
| } | ||
|
|
||
| export enum ResistanceUnit { | ||
| mΩ = "mΩ", | ||
| Ω = "Ω", | ||
| kΩ = "kΩ", | ||
| MΩ = "MΩ", | ||
| } | ||
|
|
||
| export enum PercentageUnit { | ||
| Percent = "%", | ||
| RelativeHumidity = "%RH", | ||
| } | ||
|
|
||
| export enum CapacityUnit { | ||
| pers = "pers", | ||
| pers_h = "pers/h", | ||
| } | ||
|
|
||
| export enum SnowProductionUnit { | ||
| m3_neige_h = "m3_neige/h", | ||
| } | ||
|
|
||
| export enum EfficiencyUnit { | ||
| kWh_m3 = "kWh/m3", | ||
| kWh_kg = "kWh/kg", | ||
| } | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from "./unitDetails"; | ||
| export * from "./unitsRegistry"; |
22 changes: 22 additions & 0 deletions
22
src/shared/foundation-shared-domain/models/units/unitDetails.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import type { UnitFamily } from "@dative-gpi/foundation-shared-domain/enums"; | ||
|
|
||
| export type UnitScaleStep = { unit: string; ratioToParent: number }; | ||
|
|
||
| export type UnitConversion = { | ||
| sourceUnit: string; | ||
| targetUnit: string; | ||
| conversionRate: number; | ||
| minThreshold?: number; | ||
| }; | ||
|
|
||
Axlrbs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export interface UnitDefinition { | ||
| symbol: string; | ||
| precision: number; | ||
| family?: UnitFamily; | ||
| factor?: number; | ||
| conversions?: Array<{ | ||
| targetUnit: string; | ||
| conversionRate: number; | ||
| minThreshold?: number; | ||
| }>; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.