Round booster side-effect context menu
This commit is contained in:
@@ -21,6 +21,9 @@ from logbook import Logger
|
|||||||
|
|
||||||
from sqlalchemy.orm import reconstructor
|
from sqlalchemy.orm import reconstructor
|
||||||
|
|
||||||
|
from eos.utils.round import roundToPrec
|
||||||
|
|
||||||
|
|
||||||
pyfalog = Logger(__name__)
|
pyfalog = Logger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@@ -56,9 +59,8 @@ class BoosterSideEffect:
|
|||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return "{0}% {1}".format(
|
return "{0}% {1}".format(
|
||||||
self.booster.getModifiedItemAttr(self.attr),
|
roundToPrec(self.booster.getModifiedItemAttr(self.attr), 5),
|
||||||
self.__effect.getattr('displayName') or self.__effect.name,
|
self.__effect.getattr('displayName') or self.__effect.name)
|
||||||
)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def attr(self):
|
def attr(self):
|
||||||
|
|||||||
27
eos/utils/round.py
Normal file
27
eos/utils/round.py
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import math
|
||||||
|
|
||||||
|
|
||||||
|
def roundToPrec(val, prec, nsValue=None):
|
||||||
|
"""
|
||||||
|
nsValue: custom value which should be used to determine normalization shift
|
||||||
|
"""
|
||||||
|
# We're not rounding integers anyway
|
||||||
|
# Also make sure that we do not ask to calculate logarithm of zero
|
||||||
|
if int(val) == val:
|
||||||
|
return int(val)
|
||||||
|
roundFactor = int(prec - math.floor(math.log10(abs(val if nsValue is None else nsValue))) - 1)
|
||||||
|
# But we don't want to round integers
|
||||||
|
if roundFactor < 0:
|
||||||
|
roundFactor = 0
|
||||||
|
# Do actual rounding
|
||||||
|
val = round(val, roundFactor)
|
||||||
|
# Make sure numbers with .0 part designating float don't get through
|
||||||
|
if int(val) == val:
|
||||||
|
val = int(val)
|
||||||
|
return val
|
||||||
|
|
||||||
|
|
||||||
|
def roundDec(val, prec):
|
||||||
|
if int(val) == val:
|
||||||
|
return int(val)
|
||||||
|
return round(val, prec)
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
|
from eos.utils.round import roundToPrec, roundDec
|
||||||
|
|
||||||
|
|
||||||
def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=False, unitName=None):
|
def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=False, unitName=None):
|
||||||
"""
|
"""
|
||||||
@@ -97,29 +99,3 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
|
|||||||
else:
|
else:
|
||||||
result = "{}{} {}{}".format(sign, mantissa, suffix, unitName)
|
result = "{}{} {}{}".format(sign, mantissa, suffix, unitName)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def roundToPrec(val, prec, nsValue=None):
|
|
||||||
"""
|
|
||||||
nsValue: custom value which should be used to determine normalization shift
|
|
||||||
"""
|
|
||||||
# We're not rounding integers anyway
|
|
||||||
# Also make sure that we do not ask to calculate logarithm of zero
|
|
||||||
if int(val) == val:
|
|
||||||
return int(val)
|
|
||||||
roundFactor = int(prec - math.floor(math.log10(abs(val if nsValue is None else nsValue))) - 1)
|
|
||||||
# But we don't want to round integers
|
|
||||||
if roundFactor < 0:
|
|
||||||
roundFactor = 0
|
|
||||||
# Do actual rounding
|
|
||||||
val = round(val, roundFactor)
|
|
||||||
# Make sure numbers with .0 part designating float don't get through
|
|
||||||
if int(val) == val:
|
|
||||||
val = int(val)
|
|
||||||
return val
|
|
||||||
|
|
||||||
|
|
||||||
def roundDec(val, prec):
|
|
||||||
if int(val) == val:
|
|
||||||
return int(val)
|
|
||||||
return round(val, prec)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user