From 9c7ad95f6e2212f07c97994b1d1f5cd8511538a5 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Fri, 2 Aug 2019 15:40:53 +0300 Subject: [PATCH] Add float error workarounds --- eos/utils/stats.py | 15 +++++++++------ .../fitDamageStats/calc/application.py | 4 ++++ .../fitDamageStats/calc/projected.py | 7 +++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/eos/utils/stats.py b/eos/utils/stats.py index 4b97ea2d9..46e6adfc0 100644 --- a/eos/utils/stats.py +++ b/eos/utils/stats.py @@ -18,6 +18,7 @@ # =============================================================================== +from eos.utils.float import floatUnerr from utils.repr import makeReprStr @@ -42,12 +43,14 @@ class DmgTypes: def __eq__(self, other): if not isinstance(other, DmgTypes): return NotImplemented - return all(( - self.em == other.em, - self.thermal == other.thermal, - self.kinetic == other.kinetic, - self.explosive == other.explosive, - self.total == other.total)) + # Round for comparison's sake because often damage profiles are + # generated from data which includes float errors + return ( + floatUnerr(self.em) == floatUnerr(other.em) and + floatUnerr(self.thermal) == floatUnerr(other.thermal) and + floatUnerr(self.kinetic) == floatUnerr(other.kinetic) and + floatUnerr(self.explosive) == floatUnerr(other.explosive) and + floatUnerr(self.total) == floatUnerr(other.total)) def __bool__(self): return any(( diff --git a/gui/builtinGraphs/fitDamageStats/calc/application.py b/gui/builtinGraphs/fitDamageStats/calc/application.py index 227097d1c..e3029d54a 100644 --- a/gui/builtinGraphs/fitDamageStats/calc/application.py +++ b/gui/builtinGraphs/fitDamageStats/calc/application.py @@ -23,6 +23,7 @@ from functools import lru_cache from eos.const import FittingHardpoint from eos.saveddata.fit import Fit +from eos.utils.float import floatUnerr from gui.builtinGraphs.fitDamageStats.helper import getTgtRadius from service.const import GraphDpsDroneMode from service.settings import GraphSettings @@ -100,6 +101,9 @@ def getApplicationPerKey(fit, tgt, atkSpeed, atkAngle, distance, tgtSpeed, tgtAn distance=distance, tgtSpeed=tgtSpeed, tgtSigRadius=tgtSigRadius) + # Ensure consistent results - round off a little to avoid float errors + for k, v in applicationMap.items(): + applicationMap[k] = floatUnerr(v) return applicationMap diff --git a/gui/builtinGraphs/fitDamageStats/calc/projected.py b/gui/builtinGraphs/fitDamageStats/calc/projected.py index 8ca99d7e3..cb62c0c0a 100644 --- a/gui/builtinGraphs/fitDamageStats/calc/projected.py +++ b/gui/builtinGraphs/fitDamageStats/calc/projected.py @@ -21,6 +21,7 @@ import math from eos.saveddata.fit import Fit +from eos.utils.float import floatUnerr from gui.builtinGraphs.fitDamageStats.helper import getTgtMaxVelocity, getTgtSigRadius from service.const import GraphDpsDroneMode from service.settings import GraphSettings @@ -88,7 +89,8 @@ def getWebbedSpeed(fit, tgt, currentUnwebbedSpeed, webMods, webDrones, webFighte mobileWebs.remove(mwData) maxWebbedSpeed = getTgtMaxVelocity(tgt, extraMultipliers=appliedMultipliers) currentWebbedSpeed = maxWebbedSpeed * speedRatio - return currentWebbedSpeed + # Ensure consistent results - round off a little to avoid float errors + return floatUnerr(currentWebbedSpeed) def getTpMult(fit, tgt, tgtSpeed, tpMods, tpDrones, tpFighters, distance): @@ -132,4 +134,5 @@ def getTpMult(fit, tgt, tgtSpeed, tpMods, tpDrones, tpFighters, distance): if tpedSig == math.inf and untpedSig == math.inf: return 1 mult = tpedSig / untpedSig - return mult + # Ensure consistent results - round off a little to avoid float errors + return floatUnerr(mult)