remove limit of 1000 Yotta-Joule in EnergyLink (#689)
This commit is contained in:
parent
d112cc585f
commit
80ff5a18b1
21
Utils.py
21
Utils.py
|
@ -12,6 +12,7 @@ import io
|
||||||
import collections
|
import collections
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
|
import decimal
|
||||||
|
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from tkinter import Tk
|
from tkinter import Tk
|
||||||
|
@ -494,17 +495,25 @@ class VersionException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def chaining_prefix(index: int, labels: typing.Tuple[str]) -> str:
|
||||||
|
text = ""
|
||||||
|
max_label = len(labels) - 1
|
||||||
|
while index > max_label:
|
||||||
|
text += labels[-1]
|
||||||
|
index -= max_label
|
||||||
|
return labels[index] + text
|
||||||
|
|
||||||
|
|
||||||
# noinspection PyPep8Naming
|
# noinspection PyPep8Naming
|
||||||
def format_SI_prefix(value, power=1000, power_labels=('', 'k', 'M', 'G', 'T', "P", "E", "Z", "Y")) -> str:
|
def format_SI_prefix(value, power=1000, power_labels=('', 'k', 'M', 'G', 'T', "P", "E", "Z", "Y")) -> str:
|
||||||
|
"""Formats a value into a value + metric/si prefix. More info at https://en.wikipedia.org/wiki/Metric_prefix"""
|
||||||
n = 0
|
n = 0
|
||||||
|
value = decimal.Decimal(value)
|
||||||
while value > power:
|
while value >= power:
|
||||||
value /= power
|
value /= power
|
||||||
n += 1
|
n += 1
|
||||||
if type(value) == int:
|
|
||||||
return f"{value} {power_labels[n]}"
|
return f"{value.quantize(decimal.Decimal('1.00'))} {chaining_prefix(n, power_labels)}"
|
||||||
else:
|
|
||||||
return f"{value:0.3f} {power_labels[n]}"
|
|
||||||
|
|
||||||
|
|
||||||
def get_fuzzy_ratio(word1: str, word2: str) -> float:
|
def get_fuzzy_ratio(word1: str, word2: str) -> float:
|
||||||
|
|
Loading…
Reference in New Issue