Skip to content

Commit

Permalink
Merge branch 'EosCodeCleanup-V2' of https://github.com/Ebag333/Pyfa i…
Browse files Browse the repository at this point in the history
…nto Ebag333-EosCodeCleanup-V2

Conflicts:
	eos/effects/mininginfomultiplier.py
  • Loading branch information
blitzmann committed Nov 20, 2016
2 parents 1192a06 + ad76104 commit 2281fae
Show file tree
Hide file tree
Showing 2,032 changed files with 7,915 additions and 2,620 deletions.
1 change: 1 addition & 0 deletions eos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version = "0.2.3"
tag = "git"


def test():
import tests.runTests
import unittest
Expand Down
53 changes: 24 additions & 29 deletions eos/capSim.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import heapq
from math import sqrt, exp
import time

from math import sqrt, exp

DAY = 24 * 60 * 60 * 1000

def lcm(a,b):
n = a*b

def lcm(a, b):
n = a * b
while b:
a, b = b, a % b
return n / a
Expand Down Expand Up @@ -40,20 +40,19 @@ def __init__(self):
# relevant decimal digits of capacitor for LCM period optimization
self.stability_precision = 1


def scale_activation(self, duration, capNeed):
for res in self.scale_resolutions:
mod = duration % res
if mod:
if mod > res/2.0:
mod = res-mod
if mod > res / 2.0:
mod = res - mod
else:
mod = -mod

if abs(mod) <= duration/100.0:
if abs(mod) <= duration / 100.0:
# only adjust if the adjustment is less than 1%
duration += mod
capNeed += float(mod)/duration * capNeed
capNeed += float(mod) / duration * capNeed
break

return duration, capNeed
Expand Down Expand Up @@ -91,12 +90,12 @@ def reset(self):
for (duration, capNeed, clipSize, disableStagger), amount in mods.iteritems():
if self.stagger and not disableStagger:
if clipSize == 0:
duration = int(duration/amount)
duration = int(duration / amount)
else:
stagger_amount = (duration*clipSize+10000)/(amount*clipSize)
stagger_amount = (duration * clipSize + 10000) / (amount * clipSize)
for i in range(1, amount):
heapq.heappush(self.state,
[i*stagger_amount, duration,
[i * stagger_amount, duration,
capNeed, 0, clipSize])
else:
capNeed *= amount
Expand All @@ -109,13 +108,11 @@ def reset(self):

heapq.heappush(self.state, [0, duration, capNeed, 0, clipSize])


if disable_period:
self.period = self.t_max
else:
self.period = period


def run(self):
"""Run the simulation"""

Expand All @@ -135,13 +132,13 @@ def run(self):
capCapacity = self.capacitorCapacity
tau = self.capacitorRecharge / 5.0

cap_wrap = capCapacity # cap value at last period
cap_lowest = capCapacity # lowest cap value encountered
cap_lowest_pre = capCapacity # lowest cap value before activations
cap = capCapacity # current cap value
t_wrap = self.period # point in time of next period
cap_wrap = capCapacity # cap value at last period
cap_lowest = capCapacity # lowest cap value encountered
cap_lowest_pre = capCapacity # lowest cap value before activations
cap = capCapacity # current cap value
t_wrap = self.period # point in time of next period

t_now = t_last = 0
t_last = 0
t_max = self.t_max

while 1:
Expand All @@ -150,7 +147,7 @@ def run(self):
if t_now >= t_max:
break

cap = ((1.0+(sqrt(cap/capCapacity)-1.0)*exp((t_last-t_now)/tau))**2)*capCapacity
cap = ((1.0 + (sqrt(cap / capCapacity) - 1.0) * exp((t_last - t_now) / tau)) ** 2) * capCapacity

if t_now != t_last:
if cap < cap_lowest_pre:
Expand Down Expand Up @@ -182,7 +179,7 @@ def run(self):
if clipSize:
if shot % clipSize == 0:
shot = 0
t_now += 10000 # include reload time
t_now += 10000 # include reload time
activation[0] = t_now
activation[3] = shot

Expand All @@ -195,19 +192,17 @@ def run(self):

# calculate EVE's stability value
try:
avgDrain = reduce(float.__add__, map(lambda x: x[2]/x[1], self.state), 0.0)
self.cap_stable_eve = 0.25 * (1.0 + sqrt(-(2.0 * avgDrain * tau - capCapacity)/capCapacity)) ** 2
avgDrain = reduce(float.__add__, map(lambda x: x[2] / x[1], self.state), 0.0)
self.cap_stable_eve = 0.25 * (1.0 + sqrt(-(2.0 * avgDrain * tau - capCapacity) / capCapacity)) ** 2
except ValueError:
self.cap_stable_eve = 0.0


if cap > 0.0:
# capacitor low/high water marks
self.cap_stable_low = cap_lowest
self.cap_stable_high = cap_lowest_pre
else:
self.cap_stable_low =\
self.cap_stable_high = 0.0

self.cap_stable_low = \
self.cap_stable_high = 0.0

self.runtime = time.time()-start
self.runtime = time.time() - start
10 changes: 6 additions & 4 deletions eos/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from os.path import realpath, join, dirname, abspath
import sys
from os.path import realpath, join, dirname, abspath

debug = False
gamedataCache = True
saveddataCache = True
gamedata_connectionstring = 'sqlite:///' + unicode(realpath(join(dirname(abspath(__file__)), "..", "eve.db")), sys.getfilesystemencoding())
saveddata_connectionstring = 'sqlite:///' + unicode(realpath(join(dirname(abspath(__file__)), "..", "saveddata", "saveddata.db")), sys.getfilesystemencoding())
gamedata_connectionstring = 'sqlite:///' + unicode(realpath(join(dirname(abspath(__file__)), "..", "eve.db")),
sys.getfilesystemencoding())
saveddata_connectionstring = 'sqlite:///' + unicode(
realpath(join(dirname(abspath(__file__)), "..", "saveddata", "saveddata.db")), sys.getfilesystemencoding())

#Autodetect path, only change if the autodetection bugs out.
# Autodetect path, only change if the autodetection bugs out.
path = dirname(unicode(__file__, sys.getfilesystemencoding()))
25 changes: 14 additions & 11 deletions eos/db/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of eos.
Expand All @@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with eos. If not, see <http://www.gnu.org/licenses/>.
#===============================================================================
# ===============================================================================

import threading

Expand All @@ -24,17 +24,20 @@
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import pool

from eos import config

import migration
from eos import config


class ReadOnlyException(Exception):
pass


gamedata_connectionstring = config.gamedata_connectionstring
if callable(gamedata_connectionstring):
gamedata_engine = create_engine("sqlite://", creator=gamedata_connectionstring, echo = config.debug)
gamedata_engine = create_engine("sqlite://", creator=gamedata_connectionstring, echo=config.debug)
else:
gamedata_engine = create_engine(gamedata_connectionstring, echo = config.debug)
gamedata_engine = create_engine(gamedata_connectionstring, echo=config.debug)

gamedata_meta = MetaData()
gamedata_meta.bind = gamedata_engine
Expand All @@ -44,8 +47,8 @@ class ReadOnlyException(Exception):
# game db because we haven't reached gamedata_meta.create_all()
try:
config.gamedata_version = gamedata_session.execute(
"SELECT `field_value` FROM `metadata` WHERE `field_name` LIKE 'client_build'"
).fetchone()[0]
"SELECT `field_value` FROM `metadata` WHERE `field_name` LIKE 'client_build'"
).fetchone()[0]
except:
config.gamedata_version = None

Expand All @@ -63,19 +66,19 @@ class ReadOnlyException(Exception):
# Lock controlling any changes introduced to session
sd_lock = threading.Lock()

#Import all the definitions for all our database stuff
# Import all the definitions for all our database stuff
from eos.db.gamedata import *
from eos.db.saveddata import *

#Import queries
# Import queries
from eos.db.gamedata.queries import *
from eos.db.saveddata.queries import *

#If using in memory saveddata, you'll want to reflect it so the data structure is good.
# If using in memory saveddata, you'll want to reflect it so the data structure is good.
if config.saveddata_connectionstring == "sqlite:///:memory:":
saveddata_meta.create_all()


def rollback():
with sd_lock:
saveddata_session.rollback()

30 changes: 16 additions & 14 deletions eos/db/gamedata/attribute.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of eos.
Expand All @@ -15,20 +15,22 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with eos. If not, see <http://www.gnu.org/licenses/>.
#===============================================================================
# ===============================================================================

from sqlalchemy import Table, Column, Integer, Float, Unicode, ForeignKey, String, Boolean
from sqlalchemy.orm import relation, mapper, synonym, deferred
from sqlalchemy.ext.associationproxy import association_proxy
from eos.types import Attribute, Icon, AttributeInfo, Unit
from sqlalchemy.orm import relation, mapper, synonym, deferred

from eos.db import gamedata_meta
from eos.types import Attribute, Icon, AttributeInfo, Unit

typeattributes_table = Table("dgmtypeattribs", gamedata_meta,
Column("value", Float),
Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True, index=True),
Column("attributeID", ForeignKey("dgmattribs.attributeID"), primary_key=True))
Column("value", Float),
Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True, index=True),
Column("attributeID", ForeignKey("dgmattribs.attributeID"), primary_key=True))

attributes_table = Table("dgmattribs", gamedata_meta,
Column("attributeID", Integer, primary_key = True),
Column("attributeID", Integer, primary_key=True),
Column("attributeName", String),
Column("defaultValue", Float),
Column("maxAttributeID", Integer, ForeignKey("dgmattribs.attributeID")),
Expand All @@ -40,14 +42,14 @@
Column("unitID", Integer, ForeignKey("dgmunits.unitID")))

mapper(Attribute, typeattributes_table,
properties = {"info": relation(AttributeInfo, lazy=False)})
properties={"info": relation(AttributeInfo, lazy=False)})

mapper(AttributeInfo, attributes_table,
properties = {"icon" : relation(Icon),
"unit": relation(Unit),
"ID": synonym("attributeID"),
"name": synonym("attributeName"),
"description" : deferred(attributes_table.c.description)})
properties={"icon": relation(Icon),
"unit": relation(Unit),
"ID": synonym("attributeID"),
"name": synonym("attributeName"),
"description": deferred(attributes_table.c.description)})

Attribute.ID = association_proxy("info", "attributeID")
Attribute.name = association_proxy("info", "attributeName")
Expand Down
14 changes: 7 additions & 7 deletions eos/db/gamedata/category.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of eos.
Expand All @@ -15,7 +15,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with eos. If not, see <http://www.gnu.org/licenses/>.
#===============================================================================
# ===============================================================================

from sqlalchemy import Column, String, Integer, ForeignKey, Boolean, Table
from sqlalchemy.orm import relation, mapper, synonym, deferred
Expand All @@ -24,14 +24,14 @@
from eos.types import Category, Icon

categories_table = Table("invcategories", gamedata_meta,
Column("categoryID", Integer, primary_key = True),
Column("categoryID", Integer, primary_key=True),
Column("categoryName", String),
Column("description", String),
Column("published", Boolean),
Column("iconID", Integer, ForeignKey("icons.iconID")))

mapper(Category, categories_table,
properties = {"icon" : relation(Icon),
"ID" : synonym("categoryID"),
"name" : synonym("categoryName"),
"description" : deferred(categories_table.c.description)})
properties={"icon": relation(Icon),
"ID": synonym("categoryID"),
"name": synonym("categoryName"),
"description": deferred(categories_table.c.description)})
20 changes: 10 additions & 10 deletions eos/db/gamedata/effect.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#===============================================================================
# ===============================================================================
# Copyright (C) 2010 Diego Duclos
#
# This file is part of eos.
Expand All @@ -15,35 +15,35 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with eos. If not, see <http://www.gnu.org/licenses/>.
#===============================================================================
# ===============================================================================

from sqlalchemy import Column, String, Integer, Boolean, Table, ForeignKey
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import mapper, synonym, relation, deferred
from eos.types import Effect, EffectInfo

from eos.db import gamedata_meta
from eos.types import Effect, EffectInfo

typeeffects_table = Table("dgmtypeeffects", gamedata_meta,
Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True, index=True),
Column("effectID", Integer, ForeignKey("dgmeffects.effectID"), primary_key=True))

effects_table = Table("dgmeffects", gamedata_meta,
Column("effectID", Integer, primary_key = True),
Column("effectID", Integer, primary_key=True),
Column("effectName", String),
Column("description", String),
Column("published", Boolean),
Column("isAssistance", Boolean),
Column("isOffensive", Boolean))


mapper(EffectInfo, effects_table,
properties = {"ID" : synonym("effectID"),
"name" : synonym("effectName"),
"description" : deferred(effects_table.c.description)})
properties={"ID": synonym("effectID"),
"name": synonym("effectName"),
"description": deferred(effects_table.c.description)})

mapper(Effect, typeeffects_table,
properties = {"ID": synonym("effectID"),
"info": relation(EffectInfo, lazy=False)})
properties={"ID": synonym("effectID"),
"info": relation(EffectInfo, lazy=False)})

Effect.name = association_proxy("info", "name")
Effect.description = association_proxy("info", "description")
Expand Down
Loading

0 comments on commit 2281fae

Please sign in to comment.