Files
pyfa/gui/builtinGraphs/fitMobility.py
2019-06-28 18:31:39 +03:00

91 lines
3.2 KiB
Python

# =============================================================================
# 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):
name = 'Mobility'
def __init__(self):
super().__init__()
# UI stuff
@property
def xDefs(self):
return [XDef(handle='time', unit='s', label='Time', mainInput=('time', 's'))]
@property
def yDefs(self):
return [
YDef(handle='speed', unit='m/s', label='Speed'),
YDef(handle='distance', unit='km', label='Distance')]
@property
def inputs(self):
return [Input(handle='time', unit='s', label='Time', iconID=1392, defaultValue=10, defaultRange=(0, 30), mainOnly=False)]
@property
def xDef(self):
return XDef(inputDefault='0-80', inputLabel='Time (seconds)', inputIconID=1392, axisLabel='Time, s')
# Calculation stuff
_denormalizers = {
('distance', 'km'): lambda v, fit, tgt: v / 1000}
def _time2speed(self, mainInput, miscInputs, fit, tgt):
xs = []
ys = []
maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity')
mass = fit.ship.getModifiedItemAttr('mass')
agility = fit.ship.getModifiedItemAttr('agility')
for time in self._iterLinear(mainInput[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 _time2distance(self, mainInput, miscInputs, fit, tgt):
xs = []
ys = []
maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity')
mass = fit.ship.getModifiedItemAttr('mass')
agility = fit.ship.getModifiedItemAttr('agility')
for time in self._iterLinear(mainInput[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'): _time2speed,
('time', 'distance'): _time2distance}
FitMobilityVsTimeGraph.register()