remove limit of 1000 Yotta-Joule in EnergyLink (#689)

This commit is contained in:
Fabian Dill 2022-06-21 20:50:40 +02:00 committed by GitHub
parent d112cc585f
commit 80ff5a18b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 6 deletions

View File

@ -12,6 +12,7 @@ import io
import collections
import importlib
import logging
import decimal
if typing.TYPE_CHECKING:
from tkinter import Tk
@ -494,17 +495,25 @@ class VersionException(Exception):
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
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
while value > power:
value = decimal.Decimal(value)
while value >= power:
value /= power
n += 1
if type(value) == int:
return f"{value} {power_labels[n]}"
else:
return f"{value:0.3f} {power_labels[n]}"
return f"{value.quantize(decimal.Decimal('1.00'))} {chaining_prefix(n, power_labels)}"
def get_fuzzy_ratio(word1: str, word2: str) -> float: