unitcorn 0.9.0__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.
Potentially problematic release.
This version of unitcorn might be problematic. Click here for more details.
- unitcorn/__init__.py +110 -0
- unitcorn/airQuality/__init__.py +99 -0
- unitcorn/area/__init__.py +3 -0
- unitcorn/area/area.py +103 -0
- unitcorn/base/Decorators.py +72 -0
- unitcorn/base/Registry.py +75 -0
- unitcorn/base/SmartBases.py +26 -0
- unitcorn/base/_Algebra.py +205 -0
- unitcorn/base/_Measurement.py +1122 -0
- unitcorn/base/_ScalingMeasurement.py +398 -0
- unitcorn/base/_SmartFloat.py +1635 -0
- unitcorn/base/__init__.py +6 -0
- unitcorn/config/__init__.py +318 -0
- unitcorn/config/__main__.py +8 -0
- unitcorn/config/si.toml +53 -0
- unitcorn/config/template.toml +146 -0
- unitcorn/config/us.toml +53 -0
- unitcorn/defaults/WeatherFlow/__init__.py +176 -0
- unitcorn/defaults/__init__.py +1 -0
- unitcorn/derived/__init__.py +16 -0
- unitcorn/derived/density.py +26 -0
- unitcorn/derived/partsPer.py +96 -0
- unitcorn/derived/precipitation.py +96 -0
- unitcorn/derived/rate.py +80 -0
- unitcorn/derived/volume.py +122 -0
- unitcorn/derived/wind.py +54 -0
- unitcorn/digital/__init__.py +21 -0
- unitcorn/energy/__init__.py +4 -0
- unitcorn/energy/energy.py +120 -0
- unitcorn/energy/power.py +83 -0
- unitcorn/errors/Conversion.py +12 -0
- unitcorn/errors/Unit.py +4 -0
- unitcorn/errors/__init__.py +7 -0
- unitcorn/length/__init__.py +19 -0
- unitcorn/length/imperial.py +46 -0
- unitcorn/length/length.py +74 -0
- unitcorn/length/metric.py +56 -0
- unitcorn/mass/__init__.py +15 -0
- unitcorn/mass/imperial.py +47 -0
- unitcorn/mass/mass.py +57 -0
- unitcorn/mass/metric.py +47 -0
- unitcorn/others/__init__.py +338 -0
- unitcorn/others/light.py +51 -0
- unitcorn/pressure/__init__.py +3 -0
- unitcorn/pressure/pressure.py +189 -0
- unitcorn/py.typed +0 -0
- unitcorn/temperature/__init__.py +19 -0
- unitcorn/temperature/celsius.py +23 -0
- unitcorn/temperature/change.py +156 -0
- unitcorn/temperature/fahrenheit.py +24 -0
- unitcorn/temperature/kelvin.py +25 -0
- unitcorn/temperature/temperature.py +154 -0
- unitcorn/time_/__init__.py +1 -0
- unitcorn/time_/time.py +387 -0
- unitcorn/utils.py +399 -0
- unitcorn-0.9.0.dist-info/METADATA +536 -0
- unitcorn-0.9.0.dist-info/RECORD +59 -0
- unitcorn-0.9.0.dist-info/WHEEL +4 -0
- unitcorn-0.9.0.dist-info/licenses/LICENSE.txt +17 -0
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import os.path
|
|
2
|
+
import tomllib
|
|
3
|
+
from functools import cached_property
|
|
4
|
+
from importlib import resources
|
|
5
|
+
|
|
6
|
+
import locale
|
|
7
|
+
|
|
8
|
+
from logging import getLogger
|
|
9
|
+
from configparser import ConfigParser, SectionProxy
|
|
10
|
+
from json import dumps as _quoted
|
|
11
|
+
import re
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, Optional, Callable, Set, Iterable, Mapping
|
|
14
|
+
|
|
15
|
+
from ..utils import getEnv, convertString, setPropertiesFromConfig, scored_get_close_matches, best_match, CaseInsensitiveKey
|
|
16
|
+
|
|
17
|
+
log = getLogger('unitcorn').getChild('config')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Config(ConfigParser):
|
|
21
|
+
configuredUnits: dict[str, list[type]] = {}
|
|
22
|
+
#: Callables run after every `read`, so a cache built from the old file is dropped.
|
|
23
|
+
_onRead: list[Callable[[], None]] = []
|
|
24
|
+
locale = locale.getlocale()[0]
|
|
25
|
+
__localUnits: SectionProxy
|
|
26
|
+
|
|
27
|
+
def __init__(self, *args, path: str = None, locale: str = None, **kwargs):
|
|
28
|
+
self.optionxform = CaseInsensitiveKey
|
|
29
|
+
self.__localUnits = None
|
|
30
|
+
path = path or getEnv('CONFIG_PATH')
|
|
31
|
+
super(Config, self).__init__(allow_no_value=True)
|
|
32
|
+
|
|
33
|
+
if locale is not None:
|
|
34
|
+
self.locale = locale
|
|
35
|
+
try:
|
|
36
|
+
locale.setlocale(locale.LC_ALL, self.locale)
|
|
37
|
+
except Exception:
|
|
38
|
+
log.error(f'Unable to set locale to {self.locale}')
|
|
39
|
+
if path is None:
|
|
40
|
+
with resources.path(__package__, self.defaultFileFor(self.locale)) as path:
|
|
41
|
+
self.path = path
|
|
42
|
+
else:
|
|
43
|
+
if isinstance(path, str):
|
|
44
|
+
path = Path(path)
|
|
45
|
+
self.path = path
|
|
46
|
+
|
|
47
|
+
self.read(path, reloadModules=False)
|
|
48
|
+
log.debug(f'Loaded "{path}"')
|
|
49
|
+
|
|
50
|
+
@staticmethod
|
|
51
|
+
def defaultFileFor(name: Optional[str]) -> str:
|
|
52
|
+
"""The bundled config for a locale name. An unknown locale (None) gets `si.toml`."""
|
|
53
|
+
if name and (name.lower().endswith('us') or 'United States' in name):
|
|
54
|
+
return 'us.toml'
|
|
55
|
+
return 'si.toml'
|
|
56
|
+
|
|
57
|
+
def __hash__(self):
|
|
58
|
+
return hash(self.path)
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def customConfig(self):
|
|
62
|
+
return self._customConfig
|
|
63
|
+
|
|
64
|
+
def read(self, *args, reloadModules: bool = True, **kwargs):
|
|
65
|
+
"""Read a config file: TOML by its `.toml` extension, anything else as INI."""
|
|
66
|
+
if args or kwargs:
|
|
67
|
+
for arg in args:
|
|
68
|
+
if os.path.isfile(arg):
|
|
69
|
+
self.path = arg
|
|
70
|
+
log.debug(f'Loaded "{arg}"')
|
|
71
|
+
if Path(arg).suffix.lower() == '.toml':
|
|
72
|
+
with open(arg, 'rb') as file:
|
|
73
|
+
self.read_dict(self.fromToml(tomllib.load(file), source=str(arg)))
|
|
74
|
+
else:
|
|
75
|
+
super().read(arg, **kwargs)
|
|
76
|
+
break
|
|
77
|
+
else:
|
|
78
|
+
log.error(f'{os.path.abspath(os.getcwd())}/{arg} is not a file')
|
|
79
|
+
else:
|
|
80
|
+
log.error(f'Unable to find config file')
|
|
81
|
+
else:
|
|
82
|
+
log.debug(f'Loaded "{self.path}"')
|
|
83
|
+
self.__localUnits = None
|
|
84
|
+
self.__dict__.pop('unitPropertiesKeys', None)
|
|
85
|
+
for invalidate in self._onRead:
|
|
86
|
+
invalidate()
|
|
87
|
+
for k, v in self.configuredUnits.copy().items():
|
|
88
|
+
setPropertiesFromConfig(v, self)
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def fromToml(data: Mapping[str, Any], source: str = '<toml>') -> dict[str, dict[str, str]]:
|
|
92
|
+
"""A parsed TOML config as the INI-shaped sections the rest of the config reads.
|
|
93
|
+
|
|
94
|
+
A `[UnitProperties]` entry is a table (`mmHg = { precision = 2, digit_budget = 5 }`), written back as the
|
|
95
|
+
`precision=2, digit_budget=5` line an INI file holds. That line splits on `,` and `=`, so neither may appear
|
|
96
|
+
in a value. A key left out means unset, the same as a bare key in INI.
|
|
97
|
+
"""
|
|
98
|
+
def text(value) -> str:
|
|
99
|
+
return str(value) # True/False and numbers read back the same as they do from an INI file
|
|
100
|
+
|
|
101
|
+
sections = {}
|
|
102
|
+
for name, section in data.items():
|
|
103
|
+
if not isinstance(section, Mapping):
|
|
104
|
+
raise ValueError(f'{source}: top-level key {name!r} must be a [section]')
|
|
105
|
+
converted = {}
|
|
106
|
+
for key, value in section.items():
|
|
107
|
+
if isinstance(value, Mapping):
|
|
108
|
+
pairs = []
|
|
109
|
+
for prop, propValue in value.items():
|
|
110
|
+
propValue = text(propValue)
|
|
111
|
+
if ',' in propValue or '=' in propValue:
|
|
112
|
+
raise ValueError(f'{source}: [{name}] {key}.{prop} = {propValue!r} can not hold "," or "="')
|
|
113
|
+
pairs.append(f'{prop}={propValue}')
|
|
114
|
+
converted[key] = ', '.join(pairs)
|
|
115
|
+
else:
|
|
116
|
+
converted[key] = text(value)
|
|
117
|
+
sections[name] = converted
|
|
118
|
+
return sections
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def toToml(path: str | Path) -> str:
|
|
122
|
+
"""An INI config file rewritten as TOML, for moving a config over: `python -m unitcorn.config file.ini`."""
|
|
123
|
+
parser = ConfigParser(allow_no_value=True, inline_comment_prefixes=('#',))
|
|
124
|
+
parser.optionxform = str
|
|
125
|
+
parser.read(path, encoding='utf-8')
|
|
126
|
+
|
|
127
|
+
def value(raw: str):
|
|
128
|
+
if raw in ('True', 'False'):
|
|
129
|
+
return raw == 'True'
|
|
130
|
+
if re.fullmatch(r'-?\d+', raw):
|
|
131
|
+
return int(raw)
|
|
132
|
+
if re.fullmatch(r'-?\d*\.\d+', raw):
|
|
133
|
+
return float(raw)
|
|
134
|
+
return raw
|
|
135
|
+
|
|
136
|
+
def literal(v) -> str:
|
|
137
|
+
if isinstance(v, bool):
|
|
138
|
+
return 'true' if v else 'false'
|
|
139
|
+
if isinstance(v, (int, float)):
|
|
140
|
+
return str(v)
|
|
141
|
+
return _quoted(v, ensure_ascii=False)
|
|
142
|
+
|
|
143
|
+
def key(k: str) -> str:
|
|
144
|
+
return k if re.fullmatch(r'[A-Za-z0-9_-]+', k) else _quoted(k, ensure_ascii=False)
|
|
145
|
+
|
|
146
|
+
lines = []
|
|
147
|
+
for name in parser.sections():
|
|
148
|
+
lines.append(f'[{key(name)}]')
|
|
149
|
+
for k, raw in parser[name].items():
|
|
150
|
+
if raw is None:
|
|
151
|
+
lines.append(f'# {key(k)} is unset')
|
|
152
|
+
elif name == 'UnitProperties':
|
|
153
|
+
pairs = (item.split('=', 1) for item in (part.strip() for part in raw.split(',')) if item)
|
|
154
|
+
table = ', '.join(f'{key(p.strip())} = {literal(value(v.strip()))}' for p, v in pairs)
|
|
155
|
+
lines.append(f'{key(k)} = {{ {table} }}')
|
|
156
|
+
else:
|
|
157
|
+
lines.append(f'{key(k)} = {literal(value(raw))}')
|
|
158
|
+
lines.append('')
|
|
159
|
+
return '\n'.join(lines)
|
|
160
|
+
|
|
161
|
+
@classmethod
|
|
162
|
+
def onRead(cls, callback: Callable[[], None]) -> Callable[[], None]:
|
|
163
|
+
"""Run `callback` after each `read`. For caches that hold something worked out from the file."""
|
|
164
|
+
cls._onRead.append(callback)
|
|
165
|
+
return callback
|
|
166
|
+
|
|
167
|
+
def __getattr__(self, item):
|
|
168
|
+
return self[item]
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def loc(self):
|
|
172
|
+
return float(self['Location']['lat']), float(self['Location']['lon'])
|
|
173
|
+
|
|
174
|
+
@property
|
|
175
|
+
def lat(self):
|
|
176
|
+
return float(self['Location']['lat'])
|
|
177
|
+
|
|
178
|
+
@property
|
|
179
|
+
def lon(self):
|
|
180
|
+
return float(self['Location']['lon'])
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def unitProperties(self):
|
|
184
|
+
return self['UnitProperties']
|
|
185
|
+
|
|
186
|
+
@cached_property
|
|
187
|
+
def unitPropertiesKeys(self) -> Set[str]:
|
|
188
|
+
return {i.lower() for i in self['UnitProperties'].keys()}
|
|
189
|
+
|
|
190
|
+
def unitPropertiesKeyFor(self, *candidates: str | None) -> str | None:
|
|
191
|
+
"""The real `[UnitProperties]` key matching any candidate name.
|
|
192
|
+
|
|
193
|
+
Case-insensitive, exact, first-match-wins. Callers pass the names a
|
|
194
|
+
unit might be written as in the config - its class name and its unit
|
|
195
|
+
symbol - and get back the key as spelled in the file, or None.
|
|
196
|
+
|
|
197
|
+
The symbol matters: keys are routinely written as symbols (`inHg`,
|
|
198
|
+
`mmHg`) rather than class names, and matching on the class name alone
|
|
199
|
+
meant those lines were silently ignored.
|
|
200
|
+
"""
|
|
201
|
+
keys = {key.lower(): key for key in self['UnitProperties'].keys()}
|
|
202
|
+
for candidate in candidates:
|
|
203
|
+
if isinstance(candidate, str) and (key := keys.get(candidate.lower())) is not None:
|
|
204
|
+
return key
|
|
205
|
+
return None
|
|
206
|
+
|
|
207
|
+
@property
|
|
208
|
+
def unitDefaults(self):
|
|
209
|
+
return {f'_{prop}': convertString(value) for prop, value in config['UnitDefaults'].items()}
|
|
210
|
+
|
|
211
|
+
@property
|
|
212
|
+
def localUnits(self) -> SectionProxy:
|
|
213
|
+
# Most specific first. A set here made the pick depend on string hash order,
|
|
214
|
+
# which changes from one process to the next when a file has more than one.
|
|
215
|
+
possibleSections = (f'Units_{self.locale}', 'Units', 'LocalUnits', 'unitcorn', 'WeatherUnits')
|
|
216
|
+
existingSections = set(self.sections())
|
|
217
|
+
if self.__localUnits is None:
|
|
218
|
+
if (name := next((section for section in possibleSections if section in existingSections), None)) is None:
|
|
219
|
+
raise AttributeError(f'No local units defined in the config {self.path}')
|
|
220
|
+
self.__localUnits = self[name]
|
|
221
|
+
return self.__localUnits
|
|
222
|
+
|
|
223
|
+
def search(
|
|
224
|
+
self,
|
|
225
|
+
key: str,
|
|
226
|
+
default: Optional[Any] = None,
|
|
227
|
+
guard: Callable[[Any], bool] = None,
|
|
228
|
+
ignoreSection: Optional[str] = None,
|
|
229
|
+
ignore: Optional[Set[str] | str] = None,
|
|
230
|
+
accept: Optional[Set[str] | Mapping | str] = None,
|
|
231
|
+
fuzzy: Optional[bool] = False,
|
|
232
|
+
fuzzy_threshold: Optional[float] = 0.0,
|
|
233
|
+
) -> Optional[Any]:
|
|
234
|
+
if ignore is None:
|
|
235
|
+
ignore = set()
|
|
236
|
+
elif not isinstance(ignore, Iterable):
|
|
237
|
+
ignore = ignore,
|
|
238
|
+
if ignoreSection is None:
|
|
239
|
+
ignoreSection = set()
|
|
240
|
+
elif not isinstance(ignoreSection, Iterable):
|
|
241
|
+
ignoreSection = ignoreSection,
|
|
242
|
+
|
|
243
|
+
if accept is None:
|
|
244
|
+
pass
|
|
245
|
+
elif isinstance(accept, Mapping):
|
|
246
|
+
wasMapping = accept
|
|
247
|
+
accept = [i for j in accept.items() for i in j]
|
|
248
|
+
elif not isinstance(accept, Iterable):
|
|
249
|
+
accept = accept,
|
|
250
|
+
|
|
251
|
+
if fuzzy:
|
|
252
|
+
bestValues = (
|
|
253
|
+
section[bestMatch]
|
|
254
|
+
for section in (self[_] for _ in self.sections())
|
|
255
|
+
if (bestMatch := best_match(key, section.keys(), cutoff=0.9))
|
|
256
|
+
and section.name not in ignoreSection
|
|
257
|
+
)
|
|
258
|
+
matches = (
|
|
259
|
+
scoredMatch
|
|
260
|
+
for bestValueFromSection in bestValues
|
|
261
|
+
if (
|
|
262
|
+
scoredMatch := scored_get_close_matches(
|
|
263
|
+
bestValueFromSection, accept, n=1, cutoff=fuzzy_threshold
|
|
264
|
+
)
|
|
265
|
+
)
|
|
266
|
+
and bestValueFromSection not in ignore
|
|
267
|
+
and (guard is None or guard(bestValueFromSection))
|
|
268
|
+
)
|
|
269
|
+
matches = [i for j in matches for i in j]
|
|
270
|
+
if matches:
|
|
271
|
+
match = matches[0].value
|
|
272
|
+
if "wasMapping" in locals() and match in wasMapping:
|
|
273
|
+
return wasMapping[match]
|
|
274
|
+
return match
|
|
275
|
+
else:
|
|
276
|
+
return default
|
|
277
|
+
return next(
|
|
278
|
+
(
|
|
279
|
+
value
|
|
280
|
+
for section in (self[_] for _ in self.sections())
|
|
281
|
+
if key in section
|
|
282
|
+
and (value := section[key]) not in ignore
|
|
283
|
+
and (accept is None or value in accept)
|
|
284
|
+
and (guard is None or guard(value))
|
|
285
|
+
),
|
|
286
|
+
default,
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
config = Config()
|
|
291
|
+
|
|
292
|
+
# search = config.search('locale', fuzzy=True, default=locale.getlocale()[0], accept=locale.locale_alias)
|
|
293
|
+
try:
|
|
294
|
+
locale.setlocale(locale.LC_ALL, '')
|
|
295
|
+
except locale.Error:
|
|
296
|
+
# LANG names a locale the host doesn't have. Stay on the C locale rather than fail the import.
|
|
297
|
+
log.debug('The locale set in the environment is not installed, using the C locale')
|
|
298
|
+
|
|
299
|
+
try:
|
|
300
|
+
# The C and POSIX locales report no thousands separator at all, and those
|
|
301
|
+
# characters are interpolated into FormatSpec.number's character classes,
|
|
302
|
+
# where an empty value would silently change what the regex matches.
|
|
303
|
+
RADIX_CHAR = locale.nl_langinfo(locale.RADIXCHAR) or '.'
|
|
304
|
+
GROUPING_CHAR = locale.nl_langinfo(locale.THOUSEP) or ','
|
|
305
|
+
except AttributeError:
|
|
306
|
+
RADIX_CHAR = '.'
|
|
307
|
+
GROUPING_CHAR = ','
|
|
308
|
+
|
|
309
|
+
# Optional config overrides, resolved ONCE here rather than consulted while
|
|
310
|
+
# rendering. These characters are a property of the locale - they change when
|
|
311
|
+
# someone moves country, not between values - so paying for a lookup on every
|
|
312
|
+
# formatted number would buy nothing. Set them in [UnitDefaults] to override
|
|
313
|
+
# what the locale reports.
|
|
314
|
+
if config.has_section('UnitDefaults'):
|
|
315
|
+
if _grouping := config['UnitDefaults'].get('grouping_character', None):
|
|
316
|
+
GROUPING_CHAR = _grouping
|
|
317
|
+
if _radix := config['UnitDefaults'].get('radix_character', None):
|
|
318
|
+
RADIX_CHAR = _radix
|
unitcorn/config/si.toml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[Location]
|
|
2
|
+
timezone = "America/New_York"
|
|
3
|
+
lat = 37.1
|
|
4
|
+
lon = -76.6
|
|
5
|
+
|
|
6
|
+
[LocalUnits]
|
|
7
|
+
wind = "m/s"
|
|
8
|
+
temperature = "c"
|
|
9
|
+
precipitationRate = "mm/*"
|
|
10
|
+
precipitation = "mm"
|
|
11
|
+
pressure = "mmHg"
|
|
12
|
+
density = "kg/m"
|
|
13
|
+
area = "m²"
|
|
14
|
+
energy = "kWh"
|
|
15
|
+
power = "kW"
|
|
16
|
+
|
|
17
|
+
[UnitDefaults]
|
|
18
|
+
precision = 1
|
|
19
|
+
digit_budget = 3
|
|
20
|
+
unit = ""
|
|
21
|
+
suffix = ""
|
|
22
|
+
unit_symbol = ""
|
|
23
|
+
unit_spacer = true
|
|
24
|
+
title = ""
|
|
25
|
+
exp = 1
|
|
26
|
+
slide = true
|
|
27
|
+
show_unit = true
|
|
28
|
+
shorten = true
|
|
29
|
+
k_separator = false
|
|
30
|
+
combine_unit_and_suffix = false
|
|
31
|
+
# key is unset
|
|
32
|
+
# size_hint is unset
|
|
33
|
+
trailing_zeros = "off"
|
|
34
|
+
missing = "⋯"
|
|
35
|
+
|
|
36
|
+
[UnitProperties]
|
|
37
|
+
Tiny = { precision = 3, digit_budget = 4 }
|
|
38
|
+
Small = { precision = 2, digit_budget = 4 }
|
|
39
|
+
Medium = { precision = 1, digit_budget = 3 }
|
|
40
|
+
Large = { precision = 1, digit_budget = 3 }
|
|
41
|
+
Huge = { precision = 2, digit_budget = 3 }
|
|
42
|
+
mmHg = { precision = 2, digit_budget = 5, trailing_zeros = "precision" }
|
|
43
|
+
voltage = { precision = 2, digit_budget = 3, unit_spacer = false }
|
|
44
|
+
temperature = { precision = 0, digit_budget = 3, unit_spacer = false, shorten = false, k_separator = true, unit_symbol = "°" }
|
|
45
|
+
kelvin = { unit_symbol = "" }
|
|
46
|
+
direction = { cardinal = true, degrees = false, size_hint = "WWE" }
|
|
47
|
+
strikes = { precision = 2, digit_budget = 5 }
|
|
48
|
+
illuminance = { digit_budget = 4, shorten = true }
|
|
49
|
+
precipitationRate = { precision = 2 }
|
|
50
|
+
precipitation = { precision = 2 }
|
|
51
|
+
humidity = { precision = 0, digit_budget = 2 }
|
|
52
|
+
ton = { unit = "ton" }
|
|
53
|
+
time = { unit_spacer = false }
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# A unitcorn config file. Copy it, fill it in, and load it with
|
|
2
|
+
# `uc.config.read('units.toml')` or by pointing UNITCORN_CONFIG_PATH at it.
|
|
3
|
+
# An older .ini config still loads; `python -m unitcorn.config file.ini`
|
|
4
|
+
# prints it as TOML.
|
|
5
|
+
|
|
6
|
+
[Location]
|
|
7
|
+
# timezone = "America/New_York"
|
|
8
|
+
# lat = 37.1
|
|
9
|
+
# lon = -76.6
|
|
10
|
+
|
|
11
|
+
[LocalUnits]
|
|
12
|
+
# The unit each kind of measurement is shown in.
|
|
13
|
+
#
|
|
14
|
+
# Mass: milligram (mg), gram (g), kilogram (kg), ounce (oz), pound (lbs)
|
|
15
|
+
# Length: miles (mi), inches (in), meters (m), kilometers (km)
|
|
16
|
+
# Time: millisecond (ms), second (s), minute (min), hour (hr), day (d)
|
|
17
|
+
# A rate separates its units with '/': wind = "m/s"
|
|
18
|
+
|
|
19
|
+
# wind = "" # length / time
|
|
20
|
+
# temperature = "" # fahrenheit (f), celsius (c), kelvin (K)
|
|
21
|
+
# precipitation = "" # length
|
|
22
|
+
# precipitationRate = "" # length / time; * keeps the time unit of the value, or hour
|
|
23
|
+
# pressure = "" # bar, hPa, millibar (mb), inHg, mmHg
|
|
24
|
+
# density = "" # mass / length
|
|
25
|
+
# area = "" # m², km², ha, ft², in², mi², ac
|
|
26
|
+
# energy = "" # J, kJ, MJ, Wh, kWh, MWh, cal, BTU
|
|
27
|
+
# power = "" # W, kW, MW, hp
|
|
28
|
+
|
|
29
|
+
[UnitDefaults]
|
|
30
|
+
# The defaults every unit starts from. A property is written without its
|
|
31
|
+
# leading '_'. A key left out is unset; "" sets it to empty.
|
|
32
|
+
#
|
|
33
|
+
# precision: The number of digits allowed to be displayed past the decimal
|
|
34
|
+
# but will not exceed max
|
|
35
|
+
# Example number: 3.14159m
|
|
36
|
+
# 0: 3m 1: 3.1m 2: 3.14m 3: 3.141m
|
|
37
|
+
#
|
|
38
|
+
# max: The total number of digits that can be displayed while still showing
|
|
39
|
+
# the decimal. If shorten is True, numbers would be reduced by factors
|
|
40
|
+
# of 10^3
|
|
41
|
+
# Example number: 415.25mm
|
|
42
|
+
# 2: 0.4k mm 3: 415mm 4: 415.3mm 5: 415.25mm
|
|
43
|
+
#
|
|
44
|
+
# unit: Override built in unit string
|
|
45
|
+
#
|
|
46
|
+
# suffix: Override built in suffix string. Currently only used for shortening numbers
|
|
47
|
+
#
|
|
48
|
+
# unit_symbol: Override built in unit_symbol. Currently only used for ° with degrees
|
|
49
|
+
#
|
|
50
|
+
# title: Title to be used by other display programs
|
|
51
|
+
#
|
|
52
|
+
# exp: Override exponent. I can't imagine why this would be used
|
|
53
|
+
#
|
|
54
|
+
# show_unit: Show unit
|
|
55
|
+
# True: 5km False: 5
|
|
56
|
+
#
|
|
57
|
+
# leading_zero: Display zero before values less than 1
|
|
58
|
+
# True: 0.1in False: .1in auto (default): decides per value
|
|
59
|
+
# The zero costs a digit of `max`, and that digit is sometimes
|
|
60
|
+
# the difference between showing a value and showing nothing.
|
|
61
|
+
# `auto` drops it ONLY when keeping it would render the value
|
|
62
|
+
# as zero AND dropping it actually rescues a digit:
|
|
63
|
+
# 0.5 digit_budget=2 -> 0.5 (already meaningful, keep)
|
|
64
|
+
# 0.01 digit_budget=2 -> .01 (keeping gives 0.0, drop rescues it)
|
|
65
|
+
# 0.01 digit_budget=3 -> 0.01 (fits with the zero, keep)
|
|
66
|
+
# See docs/formatting.md - the rule is subtler than it looks
|
|
67
|
+
# and two plausible simplifications of it are both wrong.
|
|
68
|
+
#
|
|
69
|
+
#trailing_zeros: Pad decimals to a stable width instead of the value's own
|
|
70
|
+
# content. By default `precision` is derived per value from how
|
|
71
|
+
# many decimals that value actually has, so 29.92 shows '29.9'
|
|
72
|
+
# but 30.0 shows '30' - a live readout changes width as it
|
|
73
|
+
# crosses a whole number. Set this where the value is glanced
|
|
74
|
+
# at rather than read:
|
|
75
|
+
# off (default) the derived, variable width
|
|
76
|
+
# precision pad to the configured precision -> 30.00
|
|
77
|
+
# fill pad to whatever the budget allows -> 30.000
|
|
78
|
+
# <int> exactly that many decimal places
|
|
79
|
+
# Always capped by digit_budget, so padding can never push a
|
|
80
|
+
# value over its budget. True is an alias for 'precision'.
|
|
81
|
+
#
|
|
82
|
+
# grouping_character / radix_character:
|
|
83
|
+
# The thousands separator and the decimal point. Both default to
|
|
84
|
+
# whatever the system locale reports, and are resolved once at
|
|
85
|
+
# config load - not per value - so overriding here is the only
|
|
86
|
+
# place they can be customized.
|
|
87
|
+
# grouping_character = . radix_character = , -> 1.234,56
|
|
88
|
+
#
|
|
89
|
+
# true_zero: Keep an exact zero bare ('0') while trailing_zeros pads
|
|
90
|
+
# everything else. Default True. A bare '0' means the value is
|
|
91
|
+
# actually zero; '0.0' means not zero but rounds to it at this
|
|
92
|
+
# width. Set False where a fixed column width matters more -
|
|
93
|
+
# precipitation, wind, strikes. No effect without trailing_zeros.
|
|
94
|
+
#
|
|
95
|
+
# missing: What a value with no reading (NaN, or None from a source) shows.
|
|
96
|
+
# Default ⋯. Override per unit in [UnitProperties]:
|
|
97
|
+
# humidity = { missing = "--" }
|
|
98
|
+
#
|
|
99
|
+
# unit_spacer: Determines if there is a space between measurements and their units
|
|
100
|
+
# True: 90° f False: 90°f
|
|
101
|
+
#
|
|
102
|
+
# k_separator: True: 1,000ft False: 1000ft
|
|
103
|
+
#
|
|
104
|
+
# shorten: Shortens values to fit within the max display amount
|
|
105
|
+
# True: 1k s False: 1000s
|
|
106
|
+
#
|
|
107
|
+
# slide: Scale units for the appropriate values | Not yet implemented
|
|
108
|
+
# True: 1km False: 1000m
|
|
109
|
+
#
|
|
110
|
+
# cardinal: Show degrees as cardinal direction | shorten decides full vs abbreviated name
|
|
111
|
+
# True: 180° False: S
|
|
112
|
+
#
|
|
113
|
+
# key: Key to be used for other programs
|
|
114
|
+
#
|
|
115
|
+
# size_hint: Override generated size hint string. Useful for when you know the
|
|
116
|
+
# expected max string length.
|
|
117
|
+
#
|
|
118
|
+
|
|
119
|
+
precision = 1
|
|
120
|
+
digit_budget = 3
|
|
121
|
+
unit = ""
|
|
122
|
+
suffix = ""
|
|
123
|
+
unit_symbol = ""
|
|
124
|
+
unit_spacer = true
|
|
125
|
+
title = ""
|
|
126
|
+
exp = 1
|
|
127
|
+
slide = false
|
|
128
|
+
show_unit = true
|
|
129
|
+
shorten = false
|
|
130
|
+
trailing_zeros = "off"
|
|
131
|
+
true_zero = true
|
|
132
|
+
missing = "⋯"
|
|
133
|
+
|
|
134
|
+
[UnitProperties]
|
|
135
|
+
# Per unit or unit type, by lowercase name, type or symbol, as an inline table
|
|
136
|
+
# of the same properties. Values can't contain ',' or '='.
|
|
137
|
+
Tiny = { precision = 3, digit_budget = 4 }
|
|
138
|
+
Small = { precision = 2, digit_budget = 4 }
|
|
139
|
+
Medium = { precision = 1, digit_budget = 3 }
|
|
140
|
+
Large = { precision = 1, digit_budget = 3 }
|
|
141
|
+
Huge = { precision = 2, digit_budget = 3 }
|
|
142
|
+
mmHg = { precision = 2, digit_budget = 5 }
|
|
143
|
+
voltage = { precision = 2, digit_budget = 3, unit_spacer = false }
|
|
144
|
+
temperature = { precision = 1, digit_budget = 3, unit_spacer = false, shorten = false, k_separator = true }
|
|
145
|
+
direction = { cardinal = true, degrees = false }
|
|
146
|
+
strikes = { precision = 2, digit_budget = 5 }
|
unitcorn/config/us.toml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[Location]
|
|
2
|
+
timezone = "America/New_York"
|
|
3
|
+
lat = 37.1
|
|
4
|
+
lon = -76.6
|
|
5
|
+
locale = "en_US"
|
|
6
|
+
|
|
7
|
+
[LocalUnits]
|
|
8
|
+
wind = "mi/hr"
|
|
9
|
+
temperature = "f"
|
|
10
|
+
precipitationRate = "inch/*"
|
|
11
|
+
precipitation = "inch"
|
|
12
|
+
pressure = "inHg"
|
|
13
|
+
density = "lbs/ft"
|
|
14
|
+
area = "ft²"
|
|
15
|
+
energy = "kWh"
|
|
16
|
+
power = "kW"
|
|
17
|
+
|
|
18
|
+
[UnitDefaults]
|
|
19
|
+
precision = 1
|
|
20
|
+
digit_budget = 3
|
|
21
|
+
unit = ""
|
|
22
|
+
suffix = ""
|
|
23
|
+
unit_symbol = ""
|
|
24
|
+
unit_spacer = true
|
|
25
|
+
title = ""
|
|
26
|
+
exp = 1
|
|
27
|
+
slide = false
|
|
28
|
+
show_unit = true
|
|
29
|
+
shorten = false
|
|
30
|
+
k_separator = false
|
|
31
|
+
# key is unset
|
|
32
|
+
# size_hint is unset
|
|
33
|
+
trailing_zeros = "off"
|
|
34
|
+
missing = "⋯"
|
|
35
|
+
grouping_char = true
|
|
36
|
+
|
|
37
|
+
[UnitProperties]
|
|
38
|
+
Tiny = { precision = 3, digit_budget = 4 }
|
|
39
|
+
Small = { precision = 2, digit_budget = 4 }
|
|
40
|
+
Medium = { precision = 1, digit_budget = 3 }
|
|
41
|
+
Large = { precision = 1, digit_budget = 3 }
|
|
42
|
+
Huge = { precision = 2, digit_budget = 3 }
|
|
43
|
+
inHg = { precision = 2, digit_budget = 4, trailing_zeros = "precision" }
|
|
44
|
+
voltage = { precision = 2, digit_budget = 3, unit_spacer = false }
|
|
45
|
+
temperature = { precision = 0, digit_budget = 3, unit_spacer = false, shorten = false, show_unit = false }
|
|
46
|
+
direction = { cardinal = true, degrees = false, size_hint = "WWE" }
|
|
47
|
+
strikes = { precision = 0, digit_budget = 5 }
|
|
48
|
+
illuminance = { digit_budget = 4, shorten = true }
|
|
49
|
+
precipitationRate = { precision = 2 }
|
|
50
|
+
precipitation = { precision = 2 }
|
|
51
|
+
humidity = { precision = 0, digit_budget = 2 }
|
|
52
|
+
tonne = { unit = "tonne" }
|
|
53
|
+
time = { unit_spacer = false }
|