diff --git a/gui/builtinGraphs/fitMobility.py b/gui/builtinGraphs/fitMobility.py deleted file mode 100644 index b48e65af1..000000000 --- a/gui/builtinGraphs/fitMobility.py +++ /dev/null @@ -1,78 +0,0 @@ -# ============================================================================= -# Copyright (C) 2010 Diego Duclos -# -# 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 . -# ============================================================================= - - -import math - -from .base import FitGraph, XDef, YDef, Input - - -class FitMobilityVsTimeGraph(FitGraph): - - # UI stuff - internalName = 'mobilityGraph' - name = 'Mobility' - xDefs = [ - XDef(handle='time', unit='s', label='Time', mainInput=('time', 's'))] - yDefs = [ - YDef(handle='speed', unit='m/s', label='Speed'), - YDef(handle='distance', unit='km', label='Distance')] - inputs = [ - Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=10, defaultRange=(0, 30))] - srcExtraCols = ('Speed', 'Agility') - - # Calculation stuff - _denormalizers = { - ('distance', 'km'): lambda v, fit, tgt: v / 1000} - - def _time2speedFull(self, mainParam, miscParams, fit, tgt): - xs = [] - ys = [] - maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity') - mass = fit.ship.getModifiedItemAttr('mass') - agility = fit.ship.getModifiedItemAttr('agility') - for time in self._iterLinear(mainParam[1]): - # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae - speed = maxSpeed * (1 - math.exp((-time * 1000000) / (agility * mass))) - xs.append(time) - ys.append(speed) - return xs, ys - - def _time2distanceFull(self, mainParam, miscParams, fit, tgt): - xs = [] - ys = [] - maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity') - mass = fit.ship.getModifiedItemAttr('mass') - agility = fit.ship.getModifiedItemAttr('agility') - for time in self._iterLinear(mainParam[1]): - # Definite integral of: - # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae - distance_t = maxSpeed * time + (maxSpeed * agility * mass * math.exp((-time * 1000000) / (agility * mass)) / 1000000) - distance_0 = maxSpeed * 0 + (maxSpeed * agility * mass * math.exp((-0 * 1000000) / (agility * mass)) / 1000000) - distance = distance_t - distance_0 - xs.append(time) - ys.append(distance) - return xs, ys - - _getters = { - ('time', 'speed'): _time2speedFull, - ('time', 'distance'): _time2distanceFull} - - -FitMobilityVsTimeGraph.register() diff --git a/gui/builtinGraphs/fitMobility/__init__.py b/gui/builtinGraphs/fitMobility/__init__.py new file mode 100644 index 000000000..ca7b9a995 --- /dev/null +++ b/gui/builtinGraphs/fitMobility/__init__.py @@ -0,0 +1 @@ +import gui.builtinGraphs.fitMobility.graph # noqa: E402,F401 diff --git a/gui/builtinGraphs/fitMobility/getter.py b/gui/builtinGraphs/fitMobility/getter.py new file mode 100644 index 000000000..123769b49 --- /dev/null +++ b/gui/builtinGraphs/fitMobility/getter.py @@ -0,0 +1,60 @@ +# ============================================================================= +# Copyright (C) 2010 Diego Duclos +# +# 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 . +# ============================================================================= + + +import math + +from gui.builtinGraphs.base import SmoothPointGetter + + +class Time2SpeedGetter(SmoothPointGetter): + + def _getCommonData(self, miscParams, fit, tgt): + return { + 'maxSpeed': fit.ship.getModifiedItemAttr('maxVelocity'), + 'mass': fit.ship.getModifiedItemAttr('mass'), + 'agility': fit.ship.getModifiedItemAttr('agility')} + + def _calculatePoint(self, x, miscParams, fit, tgt, commonData): + maxSpeed = commonData['maxSpeed'] + mass = commonData['mass'] + agility = commonData['agility'] + # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae + y = maxSpeed * (1 - math.exp((-x * 1000000) / (agility * mass))) + return y + + +class Time2DistanceGetter(SmoothPointGetter): + + def _getCommonData(self, miscParams, fit, tgt): + return { + 'maxSpeed': fit.ship.getModifiedItemAttr('maxVelocity'), + 'mass': fit.ship.getModifiedItemAttr('mass'), + 'agility': fit.ship.getModifiedItemAttr('agility')} + + def _calculatePoint(self, x, miscParams, fit, tgt, commonData): + maxSpeed = commonData['maxSpeed'] + mass = commonData['mass'] + agility = commonData['agility'] + # Definite integral of: + # https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae + distance_t = maxSpeed * x + (maxSpeed * agility * mass * math.exp((-x * 1000000) / (agility * mass)) / 1000000) + distance_0 = maxSpeed * 0 + (maxSpeed * agility * mass * math.exp((-0 * 1000000) / (agility * mass)) / 1000000) + y = distance_t - distance_0 + return y diff --git a/gui/builtinGraphs/fitMobility/graph.py b/gui/builtinGraphs/fitMobility/graph.py new file mode 100644 index 000000000..b37b7c8d9 --- /dev/null +++ b/gui/builtinGraphs/fitMobility/graph.py @@ -0,0 +1,48 @@ +# ============================================================================= +# Copyright (C) 2010 Diego Duclos +# +# 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 . +# ============================================================================= + + +from gui.builtinGraphs.base import FitGraph, XDef, YDef, Input +from .getter import Time2SpeedGetter, Time2DistanceGetter + + +class FitMobilityVsTimeGraph(FitGraph): + + # UI stuff + internalName = 'mobilityGraph' + name = 'Mobility' + xDefs = [ + XDef(handle='time', unit='s', label='Time', mainInput=('time', 's'))] + yDefs = [ + YDef(handle='speed', unit='m/s', label='Speed'), + YDef(handle='distance', unit='km', label='Distance')] + inputs = [ + Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=10, defaultRange=(0, 30))] + srcExtraCols = ('Speed', 'Agility') + + # Calculation stuff + _denormalizers = { + ('distance', 'km'): lambda v, fit, tgt: v / 1000} + + _getters = { + ('time', 'speed'): Time2SpeedGetter, + ('time', 'distance'): Time2DistanceGetter} + + +FitMobilityVsTimeGraph.register()