Rework mobility graph to use new getters

This commit is contained in:
DarkPhoenix
2019-08-02 10:02:42 +03:00
parent 5f97734881
commit c6de92592c
4 changed files with 109 additions and 78 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
# =============================================================================
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()

View File

@@ -0,0 +1 @@
import gui.builtinGraphs.fitMobility.graph # noqa: E402,F401

View File

@@ -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 <http://www.gnu.org/licenses/>.
# =============================================================================
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

View File

@@ -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 <http://www.gnu.org/licenses/>.
# =============================================================================
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()