From e19510b3d47aff41509798c9168833b813e8fd05 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Sun, 29 Sep 2019 16:00:37 +0300 Subject: [PATCH] Move function which calculates range factor to eos --- eos/calc.py | 33 +++++++++++++++++++ graphs/calc.py | 15 --------- .../data/fitDamageStats/calc/application.py | 3 +- graphs/data/fitDamageStats/calc/projected.py | 3 +- graphs/data/fitEwarStats/getter.py | 3 +- graphs/data/fitRemoteReps/calc.py | 3 +- 6 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 eos/calc.py diff --git a/eos/calc.py b/eos/calc.py new file mode 100644 index 000000000..7896f65d4 --- /dev/null +++ b/eos/calc.py @@ -0,0 +1,33 @@ +# ============================================================================= +# Copyright (C) 2019 Ryan Holmes +# +# This file is part of pyfa. +# +# pyfa is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# pyfa is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with pyfa. If not, see . +# ============================================================================= + + +def calculateRangeFactor(srcOptimalRange, srcFalloffRange, distance, restrictedRange=True): + """Range strength/chance factor, applicable to guns, ewar, RRs, etc.""" + if distance is None: + return 1 + if srcFalloffRange > 0: + # Most modules cannot be activated when at 3x falloff range, with few exceptions like guns + if restrictedRange and distance > srcOptimalRange + 3 * srcFalloffRange: + return 0 + return 0.5 ** ((max(0, distance - srcOptimalRange) / srcFalloffRange) ** 2) + elif distance <= srcOptimalRange: + return 1 + else: + return 0 diff --git a/graphs/calc.py b/graphs/calc.py index 82d4a2bc1..27f40ce1b 100644 --- a/graphs/calc.py +++ b/graphs/calc.py @@ -23,21 +23,6 @@ import math from service.settings import GraphSettings -def calculateRangeFactor(srcOptimalRange, srcFalloffRange, distance, restrictedRange=True): - """Range strength/chance factor, applicable to guns, ewar, RRs, etc.""" - if distance is None: - return 1 - if srcFalloffRange > 0: - # Most modules cannot be activated when at 3x falloff range, with few exceptions like guns - if restrictedRange and distance > srcOptimalRange + 3 * srcFalloffRange: - return 0 - return 0.5 ** ((max(0, distance - srcOptimalRange) / srcFalloffRange) ** 2) - elif distance <= srcOptimalRange: - return 1 - else: - return 0 - - # Just copy-paste penalization chain calculation code (with some modifications, # as multipliers arrive in different form) in here to not make actual attribute # calculations slower than they already are due to extra function calls diff --git a/graphs/data/fitDamageStats/calc/application.py b/graphs/data/fitDamageStats/calc/application.py index daa91d0e9..dbb0cda2f 100644 --- a/graphs/data/fitDamageStats/calc/application.py +++ b/graphs/data/fitDamageStats/calc/application.py @@ -21,9 +21,10 @@ import math from functools import lru_cache +from eos.calc import calculateRangeFactor from eos.const import FittingHardpoint from eos.utils.float import floatUnerr -from graphs.calc import calculateRangeFactor, checkLockRange, checkDroneControlRange +from graphs.calc import checkLockRange, checkDroneControlRange from service.attribute import Attribute from service.const import GraphDpsDroneMode from service.settings import GraphSettings diff --git a/graphs/data/fitDamageStats/calc/projected.py b/graphs/data/fitDamageStats/calc/projected.py index a38ebd36d..aa3bbd3a1 100644 --- a/graphs/data/fitDamageStats/calc/projected.py +++ b/graphs/data/fitDamageStats/calc/projected.py @@ -20,8 +20,9 @@ import math +from eos.calc import calculateRangeFactor from eos.utils.float import floatUnerr -from graphs.calc import calculateRangeFactor, checkLockRange, checkDroneControlRange +from graphs.calc import checkLockRange, checkDroneControlRange from service.const import GraphDpsDroneMode from service.settings import GraphSettings diff --git a/graphs/data/fitEwarStats/getter.py b/graphs/data/fitEwarStats/getter.py index b5cd89331..c1121d656 100644 --- a/graphs/data/fitEwarStats/getter.py +++ b/graphs/data/fitEwarStats/getter.py @@ -20,7 +20,8 @@ import math -from graphs.calc import calculateMultiplier, calculateRangeFactor, checkLockRange, checkDroneControlRange +from eos.calc import calculateRangeFactor +from graphs.calc import calculateMultiplier, checkLockRange, checkDroneControlRange from graphs.data.base import SmoothPointGetter diff --git a/graphs/data/fitRemoteReps/calc.py b/graphs/data/fitRemoteReps/calc.py index f0177855d..73e84105e 100644 --- a/graphs/data/fitRemoteReps/calc.py +++ b/graphs/data/fitRemoteReps/calc.py @@ -18,8 +18,9 @@ # ============================================================================= +from eos.calc import calculateRangeFactor from eos.utils.float import floatUnerr -from graphs.calc import calculateRangeFactor, checkLockRange, checkDroneControlRange +from graphs.calc import checkLockRange, checkDroneControlRange def getApplicationPerKey(src, distance):