-
Notifications
You must be signed in to change notification settings - Fork 39
Lk/units prototype rebase #570
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
Changes from all commits
89048db
5a88a34
b02e7d5
165c5c6
5bd63e4
7394454
1e89b78
0a3b486
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,26 @@ | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| import Mustache | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Map conversion_unit to the default natural Unitful unit for getters | ||||||||||||||||||||||||||||||||||||||||
| const NATURAL_UNIT_MAP = Dict{String, String}( | ||||||||||||||||||||||||||||||||||||||||
| ":mva" => "MW", # Power → MW (default for :mva) | ||||||||||||||||||||||||||||||||||||||||
| ":ohm" => "OHMS", # Impedance → Ohms | ||||||||||||||||||||||||||||||||||||||||
| ":siemens" => "SIEMENS", # Admittance → Siemens | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Determine the natural unit based on conversion_unit and field name | ||||||||||||||||||||||||||||||||||||||||
| function get_natural_unit(conversion_unit::String, field_name::String) | ||||||||||||||||||||||||||||||||||||||||
| if conversion_unit == ":mva" | ||||||||||||||||||||||||||||||||||||||||
| # Reactive power fields use Mvar instead of MW | ||||||||||||||||||||||||||||||||||||||||
| if occursin("reactive", lowercase(field_name)) | ||||||||||||||||||||||||||||||||||||||||
| return "Mvar" | ||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||
| return "MW" | ||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||
| return get(NATURAL_UNIT_MAP, conversion_unit, "MW") | ||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+4
to
+23
|
||||||||||||||||||||||||||||||||||||||||
| # Map conversion_unit to the default natural Unitful unit for getters | |
| const NATURAL_UNIT_MAP = Dict{String, String}( | |
| ":mva" => "MW", # Power → MW (default for :mva) | |
| ":ohm" => "OHMS", # Impedance → Ohms | |
| ":siemens" => "SIEMENS", # Admittance → Siemens | |
| ) | |
| # Determine the natural unit based on conversion_unit and field name | |
| function get_natural_unit(conversion_unit::String, field_name::String) | |
| if conversion_unit == ":mva" | |
| # Reactive power fields use Mvar instead of MW | |
| if occursin("reactive", lowercase(field_name)) | |
| return "Mvar" | |
| else | |
| return "MW" | |
| end | |
| end | |
| return get(NATURAL_UNIT_MAP, conversion_unit, "MW") | |
| end |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -286,10 +286,16 @@ end | |||||||||||||||||||||||||
| @test zero(IS.FuelCurve) == | ||||||||||||||||||||||||||
| IS.FuelCurve(IS.InputOutputCurve(IS.LinearFunctionData(0.0, 0.0)), 0.0) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| @test repr(cc) == sprint(show, cc) == | ||||||||||||||||||||||||||
| "InfrastructureSystems.CostCurve{QuadraticCurve}(QuadraticCurve(1.0, 2.0, 3.0), InfrastructureSystems.UnitSystemModule.UnitSystem.NATURAL_UNITS = 2, LinearCurve(0.0, 0.0))" | ||||||||||||||||||||||||||
| @test repr(fc) == sprint(show, fc) == | ||||||||||||||||||||||||||
| "InfrastructureSystems.FuelCurve{QuadraticCurve}(QuadraticCurve(1.0, 2.0, 3.0), InfrastructureSystems.UnitSystemModule.UnitSystem.NATURAL_UNITS = 2, 4.0, LinearCurve(0.0, 0.0), LinearCurve(0.0, 0.0))" | ||||||||||||||||||||||||||
| # repr and sprint(show, ...) must agree; the type parameter may or may not | ||||||||||||||||||||||||||
| # be module-qualified depending on what's in scope, so check key content. | ||||||||||||||||||||||||||
| @test repr(cc) == sprint(show, cc) | ||||||||||||||||||||||||||
| @test occursin("CostCurve", repr(cc)) | ||||||||||||||||||||||||||
| @test occursin("QuadraticCurve(1.0, 2.0, 3.0)", repr(cc)) | ||||||||||||||||||||||||||
| @test occursin("LinearCurve(0.0, 0.0)", repr(cc)) | ||||||||||||||||||||||||||
| @test repr(fc) == sprint(show, fc) | ||||||||||||||||||||||||||
| @test occursin("FuelCurve", repr(fc)) | ||||||||||||||||||||||||||
| @test occursin("QuadraticCurve(1.0, 2.0, 3.0)", repr(fc)) | ||||||||||||||||||||||||||
|
Comment on lines
+293
to
+297
|
||||||||||||||||||||||||||
| @test occursin("QuadraticCurve(1.0, 2.0, 3.0)", repr(cc)) | |
| @test occursin("LinearCurve(0.0, 0.0)", repr(cc)) | |
| @test repr(fc) == sprint(show, fc) | |
| @test occursin("FuelCurve", repr(fc)) | |
| @test occursin("QuadraticCurve(1.0, 2.0, 3.0)", repr(fc)) | |
| @test occursin("QuadraticCurve(1.0, 2.0, 3.0)", repr(cc)) | |
| @test occursin("NATURAL_UNITS", repr(cc)) | |
| @test occursin("LinearCurve(0.0, 0.0)", repr(cc)) | |
| @test repr(fc) == sprint(show, fc) | |
| @test occursin("FuelCurve", repr(fc)) | |
| @test occursin("QuadraticCurve(1.0, 2.0, 3.0)", repr(fc)) | |
| @test occursin("NATURAL_UNITS", repr(fc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains a hard rule comment saying not to add exports due to name clashes, but this change re-exports several functions/constants from
PowerSystemsUnits(e.g.,convert_units,ustrip,DEFAULT_UNITS). Either update/remove the "Do not add export statements" guidance to reflect the intended public API, or avoid re-exporting functions and require consumers to qualify them viaPowerSystemsUnitsto prevent collisions.