Skip to content

Commit 6143a5e

Browse files
committed
šŸ›Unit fix.
1 parent 25e71d7 commit 6143a5e

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

ā€ŽTests/TedToolkit.Console/Absorptance.csā€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace TedToolkit.Quantities;
22

3+
[QuantityDisplayUnit<AbsorbedDoseUnit>(AbsorbedDoseUnit.Centigray)]
34
[QuantityImplicitFromValueType]
45
[QuantityImplicitToValueType]
56
[QuantityOperator<AbsorbedDose, AbsorbedDose, double>(Operator.Divide)]

ā€Žsrc/analyzers/TedToolkit.Quantities.Analyzer/QuantitiesAttributeGenerator.csā€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public readonly record struct QuantityUnit(Quantity Quantity, string Unit)
2020
var unit = q.Units
2121
.Select(u => data.Units[u])
2222
.OrderBy(u => u.DistanceToDefault)
23+
.ThenByDescending(u => u.ApplicableSystem)
2324
.First().GetUnitName(data.Units.Values);
2425
return new QuantityUnit(q, unit);
2526
});

ā€Žsrc/analyzers/TedToolkit.Quantities.Analyzer/QuantityStructGenerator.csā€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ private ExpressionSyntax GetSystemUnitName()
998998
{
999999
var memberName = allUnits
10001000
.OrderBy(u => u.DistanceToDefault)
1001+
.ThenByDescending(u => u.ApplicableSystem)
10011002
.First().GetUnitName(data.Units.Values);
10021003
return FromMember(quantity.UnitName, memberName);
10031004
}
@@ -1019,6 +1020,7 @@ private ExpressionSyntax GetSystemUnitName()
10191020
return true;
10201021
})
10211022
.OrderBy(u => u.DistanceToDefault)
1023+
.ThenByDescending(u => u.ApplicableSystem)
10221024
.FirstOrDefault();
10231025

10241026
if (!string.IsNullOrEmpty(choiceUnit.Name))

ā€Žsrc/analyzers/TedToolkit.Quantities.Analyzer/UnitSystem.csā€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public Unit GetUnit(string key)
2626

2727
return quantityUnits
2828
.OrderBy(i => i.DistanceToDefault)
29+
.ThenByDescending(i => i.ApplicableSystem)
2930
.First();
3031
}
3132
}

ā€Žsrc/libraries/TedToolkit.Quantities.Data/Unit.csā€Ž

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ static string MakeSafe(string value)
3636

3737
[JsonIgnore] public Conversion Conversion => new(EDecimal.FromString(Multiplier), EDecimal.FromString(Offset));
3838

39-
private const double Weight = 1e4;
4039

4140
[JsonIgnore]
4241
public double DistanceToDefault
@@ -48,7 +47,7 @@ public double DistanceToDefault
4847
{
4948
if (double.TryParse(Multiplier, out var value))
5049
{
51-
result += Math.Abs(value - 1) * Weight;
50+
result += Math.Abs(value - 1);
5251
}
5352
else
5453
{
@@ -60,15 +59,15 @@ public double DistanceToDefault
6059
{
6160
if (double.TryParse(Offset, out var value))
6261
{
63-
result += Math.Abs(value) * Weight;
62+
result += Math.Abs(value);
6463
}
6564
else
6665
{
6766
return double.MaxValue;
6867
}
6968
}
7069

71-
return result - ApplicableSystem;
70+
return result;
7271
}
7372
}
7473
}

0 commit comments

Comments
Ā (0)