Rework graph interfaces again

This commit is contained in:
DarkPhoenix
2019-05-17 17:48:20 +03:00
parent 512f48ebdd
commit fb5eb220fd
12 changed files with 89 additions and 183 deletions

View File

@@ -47,5 +47,19 @@ class Graph(metaclass=ABCMeta):
yield current
current += step
def clearCache(self, fitID):
self.cache.clear()
def clearCache(self, fitID=None):
if fitID is None:
self.cache.clear()
elif fitID in self.cache:
del self.cache[fitID]
class SmoothGraph(Graph, metaclass=ABCMeta):
def getPlotPoints(self, fit, extraData, xRange, xAmount):
xs = []
ys = []
for x in self._xIter(xRange, xAmount):
xs.append(x)
ys.append(self.getYForX(fit, extraData, x))
return xs, ys

View File

@@ -1,23 +1,11 @@
import math
from eos.graph import Graph
from eos.graph import SmoothGraph
class FitCapAmountVsTimeGraph(Graph):
class FitCapAmountVsTimeGraph(SmoothGraph):
def getPlotPoints(self, fit, extraData, xRange, xAmount):
xs = []
ys = []
for x in self._xIter(xRange, xAmount):
xs.append(x)
ys.append(self.calc(fit, x))
return xs, {'capAmount': ys}
def getYForX(self, fit, extraData, x):
return {'capAmount': self.calc(fit, x)}
@staticmethod
def calc(fit, time):
def getYForX(self, fit, extraData, time):
if time < 0:
return 0
maxCap = fit.ship.getModifiedItemAttr('capacitorCapacity')

View File

@@ -1,23 +1,11 @@
import math
from eos.graph import Graph
from eos.graph import SmoothGraph
class FitCapRegenVsCapPercGraph(Graph):
class FitCapRegenVsCapPercGraph(SmoothGraph):
def getPlotPoints(self, fit, extraData, xRange, xAmount):
xs = []
ys = []
for x in self._xIter(xRange, xAmount):
xs.append(x)
ys.append(self.calc(fit, x))
return xs, {'capRegen': ys}
def getYForX(self, fit, extraData, x):
return {'capRegen': self.calc(fit, x)}
@staticmethod
def calc(fit, perc):
def getYForX(self, fit, extraData, perc):
maxCap = fit.ship.getModifiedItemAttr('capacitorCapacity')
regenTime = fit.ship.getModifiedItemAttr('rechargeRate') / 1000
currentCap = maxCap * perc / 100

View File

@@ -0,0 +1,17 @@
import math
from eos.graph import SmoothGraph
class FitDistanceVsTimeGraph(SmoothGraph):
def getYForX(self, fit, extraData, time):
maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity')
mass = fit.ship.getModifiedItemAttr('mass')
agility = fit.ship.getModifiedItemAttr('agility')
# 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
return distance

View File

@@ -1,40 +0,0 @@
import math
from eos.graph import Graph
class FitMobilityVsTimeGraph(Graph):
def getPlotPoints(self, fit, extraData, xRange, xAmount):
xs = []
ysSpeed = []
ysDistance = []
for x in self._xIter(xRange, xAmount):
xs.append(x)
ysSpeed.append(self.calcSpeed(fit, x))
ysDistance.append(self.calcDistance(fit, x))
return xs, {'speed': ysSpeed, 'distance': ysDistance}
def getYForX(self, fit, extraData, x):
return {'speed': self.calcSpeed(fit, x), 'distance': self.calcDistance(fit, x)}
@staticmethod
def calcSpeed(fit, time):
maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity')
mass = fit.ship.getModifiedItemAttr('mass')
agility = fit.ship.getModifiedItemAttr('agility')
# https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae
speed = maxSpeed * (1 - math.exp((-time * 1000000) / (agility * mass)))
return speed
@staticmethod
def calcDistance(fit, time):
maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity')
mass = fit.ship.getModifiedItemAttr('mass')
agility = fit.ship.getModifiedItemAttr('agility')
# 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
return distance

View File

@@ -0,0 +1,14 @@
import math
from eos.graph import SmoothGraph
class FitSpeedVsTimeGraph(SmoothGraph):
def getYForX(self, fit, extraData, time):
maxSpeed = fit.ship.getModifiedItemAttr('maxVelocity')
mass = fit.ship.getModifiedItemAttr('mass')
agility = fit.ship.getModifiedItemAttr('agility')
# https://wiki.eveuniversity.org/Acceleration#Mathematics_and_formulae
speed = maxSpeed * (1 - math.exp((-time * 1000000) / (agility * mass)))
return speed