opensemantic.characteristics.quantitative 0.2.2.dev2__tar.gz → 0.2.3.dev0__tar.gz

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.
Files changed (39) hide show
  1. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/PKG-INFO +1 -1
  2. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic/characteristics/quantitative/_static.py +2 -0
  3. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic/characteristics/quantitative/conversion_test.py +26 -17
  4. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic.characteristics.quantitative.egg-info/PKG-INFO +1 -1
  5. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic.characteristics.quantitative.egg-info/SOURCES.txt +1 -0
  6. opensemantic_characteristics_quantitative-0.2.3.dev0/tests/conversion_test.py +184 -0
  7. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/.coveragerc +0 -0
  8. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/.github/workflows/ci.yml +0 -0
  9. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/.gitignore +0 -0
  10. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/.isort.cfg +0 -0
  11. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/.pre-commit-config.yaml +0 -0
  12. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/.readthedocs.yml +0 -0
  13. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/AUTHORS.md +0 -0
  14. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/CHANGELOG.md +0 -0
  15. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/CONTRIBUTING.md +0 -0
  16. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/LICENSE.txt +0 -0
  17. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/README.md +0 -0
  18. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/Makefile +0 -0
  19. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/_static/.gitignore +0 -0
  20. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/authors.md +0 -0
  21. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/changelog.md +0 -0
  22. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/conf.py +0 -0
  23. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/contributing.md +0 -0
  24. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/index.md +0 -0
  25. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/license.md +0 -0
  26. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/readme.md +0 -0
  27. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/docs/requirements.txt +0 -0
  28. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/pyproject.toml +0 -0
  29. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/setup.cfg +0 -0
  30. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/setup.py +0 -0
  31. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic/characteristics/quantitative/__init__.py +0 -0
  32. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic/characteristics/quantitative/_model.py +0 -0
  33. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic.characteristics.quantitative.egg-info/dependency_links.txt +0 -0
  34. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic.characteristics.quantitative.egg-info/not-zip-safe +0 -0
  35. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic.characteristics.quantitative.egg-info/requires.txt +0 -0
  36. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/src/opensemantic.characteristics.quantitative.egg-info/top_level.txt +0 -0
  37. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/tests/conftest.py +0 -0
  38. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/tests/integration_test.py +0 -0
  39. {opensemantic_characteristics_quantitative-0.2.2.dev2 → opensemantic_characteristics_quantitative-0.2.3.dev0}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opensemantic.characteristics.quantitative
3
- Version: 0.2.2.dev2
3
+ Version: 0.2.3.dev0
4
4
  Summary: Library with Python models derived from the page package world.opensemantic.characteristics.quantitative
5
5
  Home-page: https://github.com/OpenSemanticWorld-Packages/opensemantic.characteristics.quantitative-python
6
6
  Author: OpenSemanticWorld
@@ -205,6 +205,8 @@ class QuantityValue(Characteristic, metaclass=QuantityValueMetaclass):
205
205
  unit_symbol = unit_symbol.replace("\\", "_").strip("_")
206
206
  # nummeric_value = quantity.magnitude # simplify the unit may change the scale
207
207
  nummeric_value = float(value.split("{")[1].split("}")[0])
208
+ if len(unit_symbol) == 0:
209
+ unit_symbol = "dimensionless" # todo: wite test
208
210
  unit_class = unit_registry[unit_symbol]
209
211
  quantity_class = quantity_registry[unit_class]
210
212
  return quantity_class(value=nummeric_value, unit=unit_class[unit_symbol])
@@ -5,20 +5,23 @@ import pint
5
5
  import opensemantic.characteristics.quantitative._model as q
6
6
  from opensemantic.characteristics.quantitative._static import quantity_registry
7
7
 
8
- q1 = q.Mobility(
9
- value=1.0,
10
- unit=q.MobilityUnit.meter_squared_per_second_per_volt,
11
- )
12
8
 
13
- q2 = q.Mobility(
14
- value=1.0,
15
- unit=q.MobilityUnit.centi_meter_squared_per_second_per_volt,
16
- )
9
+ def test_addition():
10
+ q1 = q.Mobility(
11
+ value=1.0,
12
+ unit=q.MobilityUnit.meter_squared_per_second_per_volt,
13
+ )
17
14
 
18
- q3 = q1 + q2
19
- assert (
20
- q3.value == 1.0001 and q3.unit == q.MobilityUnit.meter_squared_per_second_per_volt
21
- )
15
+ q2 = q.Mobility(
16
+ value=1.0,
17
+ unit=q.MobilityUnit.centi_meter_squared_per_second_per_volt,
18
+ )
19
+
20
+ q3 = q1 + q2
21
+ assert (
22
+ q3.value == 1.0001
23
+ and q3.unit == q.MobilityUnit.meter_squared_per_second_per_volt
24
+ )
22
25
 
23
26
 
24
27
  def test_quantity_value():
@@ -51,7 +54,6 @@ def test_quantity_value():
51
54
 
52
55
 
53
56
  def test_pint():
54
-
55
57
  q1 = q.Length(value=1.0, unit=q.LengthUnit.milli_meter)
56
58
  # transform to pint
57
59
  q_pint = q1.to_pint()
@@ -72,8 +74,13 @@ def test_pint():
72
74
  q43 = q41 + q42
73
75
  assert q43 == q.Area(value=1.000001, unit=q.AreaUnit.meter_squared)
74
76
 
77
+ q5 = q.Length(value=2.0, unit=q.LengthUnit.meter)
78
+ q25 = q2 / q5 # Dimensionless(value=0.5, unit=DimensionLessUnit.dimensionless)
79
+ # will envoke QuantityValue.from_pint(), which will call unit_registry[unit_symbol]
80
+ _ = q.VoltageRatio(value=q25.value)
81
+
75
82
 
76
- def full_inventory_test():
83
+ def test_full_inventory_test():
77
84
  # test all QuantityValue classes
78
85
  warning_count = 0
79
86
  critical_warning_count = 0
@@ -158,9 +165,11 @@ def full_inventory_test():
158
165
  # 359 successful, 105 errors and 485 warnings (444 critical) # fix all inverse
159
166
 
160
167
 
161
- test_quantity_value()
162
- test_pint()
163
- full_inventory_test()
168
+ if __name__ == "__main__":
169
+ test_addition()
170
+ test_quantity_value()
171
+ test_pint()
172
+ test_full_inventory_test()
164
173
 
165
174
  # pint_reg = pint.UnitRegistry()
166
175
  # pint_q = pint_reg.Quantity(1.0, "petajoule")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opensemantic.characteristics.quantitative
3
- Version: 0.2.2.dev2
3
+ Version: 0.2.3.dev0
4
4
  Summary: Library with Python models derived from the page package world.opensemantic.characteristics.quantitative
5
5
  Home-page: https://github.com/OpenSemanticWorld-Packages/opensemantic.characteristics.quantitative-python
6
6
  Author: OpenSemanticWorld
@@ -34,4 +34,5 @@ src/opensemantic/characteristics/quantitative/_model.py
34
34
  src/opensemantic/characteristics/quantitative/_static.py
35
35
  src/opensemantic/characteristics/quantitative/conversion_test.py
36
36
  tests/conftest.py
37
+ tests/conversion_test.py
37
38
  tests/integration_test.py
@@ -0,0 +1,184 @@
1
+ import json
2
+
3
+ import pint
4
+
5
+ import opensemantic.characteristics.quantitative._model as q
6
+ from opensemantic.characteristics.quantitative._static import quantity_registry
7
+
8
+
9
+ def test_addition():
10
+ q1 = q.Mobility(
11
+ value=1.0,
12
+ unit=q.MobilityUnit.meter_squared_per_second_per_volt,
13
+ )
14
+
15
+ q2 = q.Mobility(
16
+ value=1.0,
17
+ unit=q.MobilityUnit.centi_meter_squared_per_second_per_volt,
18
+ )
19
+
20
+ q3 = q1 + q2
21
+ assert (
22
+ q3.value == 1.0001
23
+ and q3.unit == q.MobilityUnit.meter_squared_per_second_per_volt
24
+ )
25
+
26
+
27
+ def test_quantity_value():
28
+ q1 = q.Length(value=1.0, unit=q.LengthUnit.milli_meter)
29
+
30
+ q_json = json.loads(q1.json(exclude_none=True))
31
+ # print(q_json)
32
+ assert q_json == {
33
+ "type": ["Category:OSWee9c7e5c343e542cb5a8b4648315902f"],
34
+ "value": 1.0,
35
+ "unit": (
36
+ "Item:OSWf101d25e944856e3bd4b4c9863db7de2"
37
+ "#OSW322dec469be75aedb008b3ebff29db86"
38
+ ),
39
+ }
40
+
41
+ q1 = q.Length(value=1.0, unit=q.LengthUnit.meter)
42
+
43
+ q_json = json.loads(q1.json(exclude_none=True))
44
+ # print(q_json)
45
+ assert q_json == {
46
+ "type": ["Category:OSWee9c7e5c343e542cb5a8b4648315902f"],
47
+ "value": 1.0,
48
+ "unit": "Item:OSWf101d25e944856e3bd4b4c9863db7de2",
49
+ }
50
+
51
+ q_json = json.loads(q1.json(exclude_none=True, exclude_defaults=True))
52
+ # print(q_json)
53
+ assert q_json == {"value": 1.0}
54
+
55
+
56
+ def test_pint():
57
+ q1 = q.Length(value=1.0, unit=q.LengthUnit.milli_meter)
58
+ # transform to pint
59
+ q_pint = q1.to_pint()
60
+ # transform back to QuantityValue
61
+ q_ = q.QuantityValue.from_pint(q_pint)
62
+ assert q1 == q_
63
+
64
+ q2 = q.Length(value=1.0, unit=q.LengthUnit.meter)
65
+ q3 = q1 + q2
66
+ assert q3 == q.Length(value=1.001, unit=q.LengthUnit.meter)
67
+
68
+ q31 = q1 * q2
69
+ assert q31 == q.Area(value=1000.0, unit=q.AreaUnit.milli_meter_squared)
70
+
71
+ q41 = q.Area(value=1.0, unit=q.AreaUnit.meter_squared)
72
+ q42 = q.Area(value=1.0, unit=q.AreaUnit.milli_meter_squared)
73
+ # 'square_meter' is not a valid unit for pint, but 'square_meter' is
74
+ q43 = q41 + q42
75
+ assert q43 == q.Area(value=1.000001, unit=q.AreaUnit.meter_squared)
76
+
77
+ q5 = q.Length(value=2.0, unit=q.LengthUnit.meter)
78
+ q25 = q2 / q5 # Dimensionless(value=0.5, unit=DimensionLessUnit.dimensionless)
79
+ # will envoke QuantityValue.from_pint(), which will call unit_registry[unit_symbol]
80
+ _ = q.VoltageRatio(value=q25.value)
81
+
82
+
83
+ def test_full_inventory_test():
84
+ # test all QuantityValue classes
85
+ warning_count = 0
86
+ critical_warning_count = 0
87
+ error_count = 0
88
+ success_count = 0
89
+ qu_reg = {}
90
+ # build a list of all UnitEnums per QuantityValue class
91
+ for ue, qv in quantity_registry.items():
92
+ if qv not in qu_reg:
93
+ qu_reg[qv] = []
94
+ qu_reg[qv].append(ue)
95
+
96
+ # build a list of all entr
97
+
98
+ for qv in qu_reg.keys():
99
+ # round-trip to and from pint
100
+ # interate of the ue Enum members
101
+
102
+ for ue in qu_reg[qv]:
103
+ for u in ue:
104
+ # create a QuantityValue object
105
+ q1 = qv(value=1.0, unit=u)
106
+
107
+ try:
108
+ # transform to pint
109
+ q_pint = q1.to_pint()
110
+ # transform back to QuantityValue
111
+ q_ = q.QuantityValue.from_pint(q_pint)
112
+ # assert q1 == q_
113
+ if q1 != q_:
114
+ # print(
115
+ # (
116
+ # f"Warning: {q1.value} {q1.unit} ",
117
+ # f"!= {q_.value} {q_.unit}",
118
+ # )
119
+ # )
120
+ warning_count += 1
121
+ # print(q1.to_pint())
122
+ # print(q_.to_pint())
123
+ if type(q1) is not type(q_):
124
+ print(
125
+ (
126
+ f"Critical Warning: {q1.__class__.__name__} "
127
+ f"and {q_.__class__.__name__} "
128
+ f"have the same unit {u}"
129
+ )
130
+ )
131
+ critical_warning_count += 1
132
+ pass
133
+ elif q1.unit != q_.unit:
134
+ print(f"Warning: {q1.unit} was normalized to {q_.unit}")
135
+ pass
136
+ elif q1.value != q_.value:
137
+ print(f"Warning: Rounding error: {q1.value} vs {q_.value}")
138
+ pass
139
+ else:
140
+ print(f"Warning: Unknown error: {q1} vs {q_}")
141
+ pass
142
+
143
+ else:
144
+ success_count += 1
145
+ except Exception as e:
146
+ # check if e is of type pint.errors.UndefinedUnitError
147
+ if isinstance(e, pint.errors.UndefinedUnitError):
148
+ print(f"Error: Missing unit {u} in pint")
149
+ elif isinstance(e, KeyError):
150
+ print(f"Error: Missing unit {u} in unit_registry")
151
+ else:
152
+ print(f"Error {e.__class__}: {q1} -> {q_pint} -> {q_}")
153
+ # print(re
154
+ error_count += 1
155
+ print(
156
+ (
157
+ f"{success_count} successful, "
158
+ f"{error_count} errors and {warning_count} warnings "
159
+ f"({critical_warning_count} critical)"
160
+ )
161
+ )
162
+ # 283 successful, 366 errors and 300 warnings # baseline
163
+ # 295 successful, 292 errors and 362 warnings # fix inverse units
164
+ # 346 successful, 122 errors and 481 warnings # fix SI prefixes
165
+ # 359 successful, 105 errors and 485 warnings (444 critical) # fix all inverse
166
+
167
+
168
+ if __name__ == "__main__":
169
+ test_addition()
170
+ test_quantity_value()
171
+ test_pint()
172
+ test_full_inventory_test()
173
+
174
+ # pint_reg = pint.UnitRegistry()
175
+ # pint_q = pint_reg.Quantity(1.0, "petajoule")
176
+ # # not defined, try alias
177
+ # pint_q = pint_reg.Quantity(1.0, "joule 1 / kelvin 1 / kilogram squared 1 / pascal")
178
+ # print(pint_q)
179
+ # print(f"{pint_q:9f#Lx}")
180
+
181
+ # naming collisions?
182
+ # VaporPermeability
183
+ # NEONUnit
184
+ # CombinedNonEvaporativeHeatTransferCoefficient