Skip to content

Commit

Permalink
Round booster side-effect context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFenX committed Apr 16, 2020
1 parent 5db97ea commit fe93db1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
8 changes: 5 additions & 3 deletions eos/saveddata/boosterSideEffect.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

from sqlalchemy.orm import reconstructor

from eos.utils.round import roundToPrec


pyfalog = Logger(__name__)


Expand Down Expand Up @@ -56,9 +59,8 @@ def effect(self):
@property
def name(self):
return "{0}% {1}".format(
self.booster.getModifiedItemAttr(self.attr),
self.__effect.getattr('displayName') or self.__effect.name,
)
roundToPrec(self.booster.getModifiedItemAttr(self.attr), 5),
self.__effect.getattr('displayName') or self.__effect.name)

@property
def attr(self):
Expand Down
27 changes: 27 additions & 0 deletions eos/utils/round.py
Original file line number Diff line number Diff line change
@@ -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)
28 changes: 2 additions & 26 deletions gui/utils/numberFormatter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import math

from eos.utils.round import roundToPrec, roundDec


def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=False, unitName=None):
"""
Expand Down Expand Up @@ -97,29 +99,3 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
else:
result = "{}{} {}{}".format(sign, mantissa, suffix, unitName)
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)

0 comments on commit fe93db1

Please sign in to comment.