ucon 0.6.4__py3-none-any.whl → 0.6.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ucon/core.py CHANGED
@@ -99,6 +99,8 @@ class Dimension(Enum):
99
99
  permittivity = Vector(4, -3, -1, 2, 0, 0, 0, 0)
100
100
  power = Vector(-3, 2, 1, 0, 0, 0, 0, 0)
101
101
  pressure = Vector(-2, -1, 1, 0, 0, 0, 0, 0)
102
+ dynamic_viscosity = Vector(-1, -1, 1, 0, 0, 0, 0, 0) # M·L⁻¹·T⁻¹ (Pa·s)
103
+ kinematic_viscosity = Vector(-1, 2, 0, 0, 0, 0, 0, 0) # L²·T⁻¹ (m²/s)
102
104
  resistance = Vector(-3, 2, 1, -2, 0, 0, 0, 0)
103
105
  resistivity = Vector(-3, 3, 1, -2, 0, 0, 0, 0)
104
106
  specific_heat_capacity = Vector(-2, 2, 0, 0, -1, 0, 0, 0)
ucon/graph.py CHANGED
@@ -555,6 +555,8 @@ def _build_standard_graph() -> ConversionGraph:
555
555
  graph.add_edge(src=units.celsius, dst=units.kelvin, map=AffineMap(1, 273.15))
556
556
  # F → C: C = (F - 32) * 5/9
557
557
  graph.add_edge(src=units.fahrenheit, dst=units.celsius, map=AffineMap(5/9, -32 * 5/9))
558
+ # K → °R: °R = K × 9/5 (both absolute scales, same zero point)
559
+ graph.add_edge(src=units.kelvin, dst=units.rankine, map=LinearMap(9/5))
558
560
 
559
561
  # --- Pressure ---
560
562
  # 1 Pa = 0.00001 bar, so 1 bar = 100000 Pa
@@ -563,6 +565,28 @@ def _build_standard_graph() -> ConversionGraph:
563
565
  graph.add_edge(src=units.pascal, dst=units.psi, map=LinearMap(0.000145038))
564
566
  # 1 atm = 101325 Pa
565
567
  graph.add_edge(src=units.atmosphere, dst=units.pascal, map=LinearMap(101325))
568
+ # 1 torr = 133.322368 Pa
569
+ graph.add_edge(src=units.torr, dst=units.pascal, map=LinearMap(133.322368))
570
+ # 1 mmHg ≈ 1 torr (by definition, at 0°C)
571
+ graph.add_edge(src=units.millimeter_mercury, dst=units.torr, map=LinearMap(1.0))
572
+ # 1 inHg = 3386.389 Pa
573
+ graph.add_edge(src=units.inch_mercury, dst=units.pascal, map=LinearMap(3386.389))
574
+
575
+ # --- Force ---
576
+ # 1 lbf = 4.4482216152605 N (exact, from lb_m × g_n)
577
+ graph.add_edge(src=units.pound_force, dst=units.newton, map=LinearMap(4.4482216152605))
578
+ # 1 kgf = 9.80665 N (exact, by definition)
579
+ graph.add_edge(src=units.kilogram_force, dst=units.newton, map=LinearMap(9.80665))
580
+ # 1 dyne = 1e-5 N (CGS unit)
581
+ graph.add_edge(src=units.dyne, dst=units.newton, map=LinearMap(1e-5))
582
+
583
+ # --- Dynamic Viscosity ---
584
+ # 1 poise = 0.1 Pa·s (CGS unit)
585
+ graph.add_edge(src=units.poise, dst=units.pascal * units.second, map=LinearMap(0.1))
586
+
587
+ # --- Kinematic Viscosity ---
588
+ # 1 stokes = 1e-4 m²/s (CGS unit)
589
+ graph.add_edge(src=units.stokes, dst=units.meter ** 2 / units.second, map=LinearMap(1e-4))
566
590
 
567
591
  # --- Volume ---
568
592
  graph.add_edge(src=units.liter, dst=units.gallon, map=LinearMap(0.264172))
ucon/mcp/server.py CHANGED
@@ -91,16 +91,11 @@ def convert(value: float, from_unit: str, to_unit: str) -> ConversionResult:
91
91
  num = Number(quantity=value, unit=src)
92
92
  result = num.to(dst)
93
93
 
94
- unit_str = None
95
- dim_name = "none"
96
-
97
- if result.unit:
98
- if isinstance(result.unit, UnitProduct):
99
- unit_str = result.unit.shorthand
100
- dim_name = result.unit.dimension.name
101
- elif isinstance(result.unit, Unit):
102
- unit_str = result.unit.shorthand
103
- dim_name = result.unit.dimension.name
94
+ # Use the target unit string as output (what the user asked for).
95
+ # This handles cases like mg/kg → µg/kg where internal representation
96
+ # may lose unit info due to dimension cancellation.
97
+ unit_str = to_unit
98
+ dim_name = dst.dimension.name if hasattr(dst, 'dimension') else "none"
104
99
 
105
100
  return ConversionResult(
106
101
  quantity=result.quantity,
ucon/units.py CHANGED
@@ -80,6 +80,12 @@ webers_per_meter = Unit(name='webers_per_meter', dimension=Dimension.magnetic_pe
80
80
  # ----------------------------------------------------------------------
81
81
 
82
82
 
83
+ # -- Viscosity Units ---------------------------------------------------
84
+ poise = Unit(name='poise', dimension=Dimension.dynamic_viscosity, aliases=('P',))
85
+ stokes = Unit(name='stokes', dimension=Dimension.kinematic_viscosity, aliases=('St',))
86
+ # ----------------------------------------------------------------------
87
+
88
+
83
89
  # -- Time Units --------------------------------------------------------
84
90
  second = Unit(name='second', dimension=Dimension.time, aliases=('s', 'sec'))
85
91
  minute = Unit(name='minute', dimension=Dimension.time, aliases=('min',))
@@ -101,6 +107,7 @@ ounce = Unit(name='ounce', dimension=Dimension.mass, aliases=('oz', 'ounces'))
101
107
 
102
108
  # Temperature
103
109
  fahrenheit = Unit(name='fahrenheit', dimension=Dimension.temperature, aliases=('°F', 'degF'))
110
+ rankine = Unit(name='rankine', dimension=Dimension.temperature, aliases=('°R', 'degR', 'R'))
104
111
 
105
112
  # Volume
106
113
  gallon = Unit(name='gallon', dimension=Dimension.volume, aliases=('gal', 'gallons'))
@@ -116,6 +123,14 @@ horsepower = Unit(name='horsepower', dimension=Dimension.power, aliases=('hp',))
116
123
  bar = Unit(name='bar', dimension=Dimension.pressure, aliases=('bar',))
117
124
  psi = Unit(name='psi', dimension=Dimension.pressure, aliases=('psi', 'lbf/in²'))
118
125
  atmosphere = Unit(name='atmosphere', dimension=Dimension.pressure, aliases=('atm',))
126
+ torr = Unit(name='torr', dimension=Dimension.pressure, aliases=('Torr',))
127
+ millimeter_mercury = Unit(name='millimeter_mercury', dimension=Dimension.pressure, aliases=('mmHg',))
128
+ inch_mercury = Unit(name='inch_mercury', dimension=Dimension.pressure, aliases=('inHg',))
129
+
130
+ # Force
131
+ pound_force = Unit(name='pound_force', dimension=Dimension.force, aliases=('lbf',))
132
+ kilogram_force = Unit(name='kilogram_force', dimension=Dimension.force, aliases=('kgf',))
133
+ dyne = Unit(name='dyne', dimension=Dimension.force, aliases=('dyn',))
119
134
  # ----------------------------------------------------------------------
120
135
 
121
136
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ucon
3
- Version: 0.6.4
3
+ Version: 0.6.6
4
4
  Summary: A tool for dimensional analysis: a 'Unit CONverter'
5
5
  Home-page: https://github.com/withtwoemms/ucon
6
6
  Author: Emmanuel I. Obi
@@ -0,0 +1,17 @@
1
+ ucon/__init__.py,sha256=SAXuDNMmxzaLVr4JpUHsz-feQotVhpzsCUj2WiXYA-0,2361
2
+ ucon/algebra.py,sha256=6QrPyD23L93XSrnIORcYEx2CLDv4WDcrh6H_hxeeOus,8668
3
+ ucon/core.py,sha256=uwMi17VuJbE-P0aSpfGgTPLmRjVLeqfXIaemR2N1Ooo,63470
4
+ ucon/graph.py,sha256=qjA5g67scHLZsQoHaG5Z2bN8VgamSByp6oKp7-rUc3c,22586
5
+ ucon/maps.py,sha256=-rPMOHylcQYUn62R9IU23bXdCRCRNBhdH3UD4G5IUEk,9123
6
+ ucon/pydantic.py,sha256=64ZR1EYFRnBGHj3VIF5pc3swdAiR2ZlYrgcntdbKN4k,5189
7
+ ucon/quantity.py,sha256=GBxZ_96nocx-8F-usNWGbPvWHRhRgdZzqfH9Sx69iC4,465
8
+ ucon/units.py,sha256=jAerucV7GDbVdwh7BY-8SsnoqsMYMjTzgs5YZz30xGc,18344
9
+ ucon/mcp/__init__.py,sha256=WoFOQ7JeDIzbjjkFIJ0Uv53VVLu-4lrjzG5vpVGGfT4,123
10
+ ucon/mcp/server.py,sha256=RDKFvr_NtLNd8UBQp1wCDUpgnF0OYucn6woMi3JP8E0,6971
11
+ ucon-0.6.6.dist-info/licenses/LICENSE,sha256=LtimSYBSw1L_X6n1-VEdZRdwuROzPumrMUNX21asFuI,11356
12
+ ucon-0.6.6.dist-info/licenses/NOTICE,sha256=bh4fBOItio3kM4hSNYhqfFpcaAvOoixjD7Du8im-sYA,1079
13
+ ucon-0.6.6.dist-info/METADATA,sha256=Bz39ydFUit_y8uK9BWDS6cJdmmMhI4Q9WBqYljcDR4k,17397
14
+ ucon-0.6.6.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
15
+ ucon-0.6.6.dist-info/entry_points.txt,sha256=jbfLf0FbOulgGa0nM_sRiTNfiCAkJcHnSSK_oj3g0cQ,50
16
+ ucon-0.6.6.dist-info/top_level.txt,sha256=Vv3KDuZ86fmH5yOYLbYap9DbBblK1YUkmlThffF71jA,5
17
+ ucon-0.6.6.dist-info/RECORD,,
@@ -1,17 +0,0 @@
1
- ucon/__init__.py,sha256=SAXuDNMmxzaLVr4JpUHsz-feQotVhpzsCUj2WiXYA-0,2361
2
- ucon/algebra.py,sha256=6QrPyD23L93XSrnIORcYEx2CLDv4WDcrh6H_hxeeOus,8668
3
- ucon/core.py,sha256=V10GfKTf28GFgoO9NMI7ciqKHI_p8wG8qICR6u85gv0,63300
4
- ucon/graph.py,sha256=vBIKwppYCAu5sw6R_3zTBlnOk2WmYMClIb6j5kDvJHI,21342
5
- ucon/maps.py,sha256=-rPMOHylcQYUn62R9IU23bXdCRCRNBhdH3UD4G5IUEk,9123
6
- ucon/pydantic.py,sha256=64ZR1EYFRnBGHj3VIF5pc3swdAiR2ZlYrgcntdbKN4k,5189
7
- ucon/quantity.py,sha256=GBxZ_96nocx-8F-usNWGbPvWHRhRgdZzqfH9Sx69iC4,465
8
- ucon/units.py,sha256=T410Haid7PBLKQgxEfUGKheOAj61E3gRCau4aw0NNJM,17414
9
- ucon/mcp/__init__.py,sha256=WoFOQ7JeDIzbjjkFIJ0Uv53VVLu-4lrjzG5vpVGGfT4,123
10
- ucon/mcp/server.py,sha256=uUrdevEaR65Qjh9xn8Q-_IusNjPGxdkLF9iQmiSTs0g,7016
11
- ucon-0.6.4.dist-info/licenses/LICENSE,sha256=LtimSYBSw1L_X6n1-VEdZRdwuROzPumrMUNX21asFuI,11356
12
- ucon-0.6.4.dist-info/licenses/NOTICE,sha256=bh4fBOItio3kM4hSNYhqfFpcaAvOoixjD7Du8im-sYA,1079
13
- ucon-0.6.4.dist-info/METADATA,sha256=gdY9jvge5vPs_uocKQHXM-TB3Pq-Dw877y3nCdQYhGs,17397
14
- ucon-0.6.4.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
15
- ucon-0.6.4.dist-info/entry_points.txt,sha256=jbfLf0FbOulgGa0nM_sRiTNfiCAkJcHnSSK_oj3g0cQ,50
16
- ucon-0.6.4.dist-info/top_level.txt,sha256=Vv3KDuZ86fmH5yOYLbYap9DbBblK1YUkmlThffF71jA,5
17
- ucon-0.6.4.dist-info/RECORD,,
File without changes