Skip to content

Commit

Permalink
Merge pull request pyfa-org#83 from Pyfa-fit/catchup_master
Browse files Browse the repository at this point in the history
Catchup: Merge pyfa-org master into development
  • Loading branch information
Ebag333 authored May 12, 2017
2 parents 90adf5a + 4105352 commit 18c7bb9
Show file tree
Hide file tree
Showing 203 changed files with 5,989 additions and 717 deletions.
1 change: 1 addition & 0 deletions eos/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"useStaticAdaptiveArmorHardener": False,
"strictFitting" : True,
"fireAtPercentCapacitor" : 25,
"strictSkillLevels" : True,
}

# Autodetect path, only change if the autodetection bugs out.
Expand Down
20 changes: 6 additions & 14 deletions eos/db/gamedata/effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
# ===============================================================================

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 sqlalchemy.orm import mapper, synonym, deferred

from eos.db import gamedata_meta
from eos.gamedata import Effect, EffectInfo
from eos.gamedata import Effect, ItemEffect

typeeffects_table = Table("dgmtypeeffects", gamedata_meta,
Column("typeID", Integer, ForeignKey("invtypes.typeID"), primary_key=True, index=True),
Expand All @@ -34,21 +33,14 @@
Column("description", String),
Column("published", Boolean),
Column("isAssistance", Boolean),
Column("isOffensive", Boolean))
Column("isOffensive", Boolean),
Column("resistanceID", Integer))

mapper(EffectInfo, effects_table,
mapper(Effect, effects_table,
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)
})

Effect.name = association_proxy("info", "name")
Effect.description = association_proxy("info", "description")
Effect.published = association_proxy("info", "published")
mapper(ItemEffect, typeeffects_table)
3 changes: 2 additions & 1 deletion eos/db/gamedata/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import relation, mapper, synonym, deferred
from sqlalchemy.orm.collections import attribute_mapped_collection
from eos.db.gamedata.effect import typeeffects_table

from eos.db import gamedata_meta
from eos.gamedata import Attribute, Effect, Group, Icon, Item, MetaType, Traits
Expand All @@ -47,7 +48,7 @@
"group" : relation(Group, backref="items"),
"icon" : relation(Icon),
"_Item__attributes": relation(Attribute, collection_class=attribute_mapped_collection('name')),
"effects" : relation(Effect, collection_class=attribute_mapped_collection('name')),
"effects": relation(Effect, secondary=typeeffects_table, collection_class=attribute_mapped_collection('name')),
"metaGroup" : relation(MetaType,
primaryjoin=metatypes_table.c.typeID == items_table.c.typeID,
uselist=False),
Expand Down
72 changes: 69 additions & 3 deletions eos/db/gamedata/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# along with eos. If not, see <http://www.gnu.org/licenses/>.
# ===============================================================================

from sqlalchemy.orm import join, exc
from sqlalchemy.orm import join, exc, aliased
from sqlalchemy.sql import and_, or_, select

import eos.config
Expand All @@ -27,12 +27,11 @@
from eos.db.util import processEager, processWhere
from eos.gamedata import AlphaClone, Attribute, Category, Group, Item, MarketGroup, MetaGroup, AttributeInfo, MetaData

cache = {}
configVal = getattr(eos.config, "gamedataCache", None)
if configVal is True:
def cachedQuery(amount, *keywords):
def deco(function):
cache = {}

def checkAndReturn(*args, **kwargs):
useCache = kwargs.pop("useCache", True)
cacheKey = []
Expand Down Expand Up @@ -99,6 +98,35 @@ def getItem(lookfor, eager=None):
return item


@cachedQuery(1, "lookfor")
def getItems(lookfor, eager=None):
"""
Gets a list of items. Does a bit of cache hackery to get working properly -- cache
is usually based on function calls with the parameters, needed to extract data directly.
Works well enough. Not currently used, but it's here for possible future inclusion
"""

toGet = []
results = []

for _id in lookfor:
if (_id, None) in cache:
results.append(cache.get((_id, None)))
else:
toGet.append(_id)

if len(toGet) > 0:
# Get items that aren't currently cached, and store them in the cache
items = gamedata_session.query(Item).filter(Item.ID.in_(toGet)).all()
for item in items:
cache[(item.ID, None)] = item
results += items

# sort the results based on the original indexing
results.sort(key=lambda x: lookfor.index(x.ID))
return results


@cachedQuery(1, "lookfor")
def getAlphaClone(lookfor, eager=None):
if isinstance(lookfor, int):
Expand Down Expand Up @@ -259,6 +287,22 @@ def searchItems(nameLike, where=None, join=None, eager=None, result_limit=150):
return items


@cachedQuery(3, "where", "nameLike", "join")
def searchSkills(nameLike, where=None, eager=None):
if not isinstance(nameLike, basestring):
raise TypeError("Need string as argument")

items = gamedata_session.query(Item).options(*processEager(eager)).join(Item.group, Group.category)
for token in nameLike.split(' '):
token_safe = u"%{0}%".format(sqlizeString(token))
if where is not None:
items = items.filter(and_(Item.name.like(token_safe, escape="\\"), Category.ID == 16, where))
else:
items = items.filter(and_(Item.name.like(token_safe, escape="\\"), Category.ID == 16))
items = items.limit(100).all()
return items


@cachedQuery(2, "where", "itemids")
def getVariations(itemids, groupIDs=None, where=None, eager=None):
for itemid in itemids:
Expand Down Expand Up @@ -325,3 +369,25 @@ def directAttributeRequest(itemIDs, attrIDs):

result = gamedata_session.execute(q).fetchall()
return result


def getRequiredFor(itemID, attrMapping):
Attribute1 = aliased(Attribute)
Attribute2 = aliased(Attribute)

skillToLevelClauses = []

for attrSkill, attrLevel in attrMapping.iteritems():
skillToLevelClauses.append(and_(Attribute1.attributeID == attrSkill, Attribute2.attributeID == attrLevel))

queryOr = or_(*skillToLevelClauses)

q = select((Attribute2.typeID, Attribute2.value),
and_(Attribute1.value == itemID, queryOr),
from_obj=[
join(Attribute1, Attribute2, Attribute1.typeID == Attribute2.typeID)
])

result = gamedata_session.execute(q).fetchall()

return result
2 changes: 2 additions & 0 deletions eos/db/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
upgrade20,
upgrade21,
upgrade22,
upgrade23,
upgrade24,
)

pyfalog = Logger(__name__)
Expand Down
13 changes: 13 additions & 0 deletions eos/db/migrations/upgrade23.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Migration 23
- Adds a sec status field to the character table
"""
import sqlalchemy


def upgrade(saveddata_engine):
try:
saveddata_engine.execute("SELECT secStatus FROM characters LIMIT 1")
except sqlalchemy.exc.DatabaseError:
saveddata_engine.execute("ALTER TABLE characters ADD COLUMN secStatus FLOAT;")
14 changes: 14 additions & 0 deletions eos/db/migrations/upgrade24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Migration 24
- Adds a boolean value to fit to signify if fit should ignore restrictions
"""
import sqlalchemy


def upgrade(saveddata_engine):
try:
saveddata_engine.execute("SELECT ignoreRestrictions FROM fits LIMIT 1")
except sqlalchemy.exc.DatabaseError:
saveddata_engine.execute("ALTER TABLE fits ADD COLUMN ignoreRestrictions BOOLEAN")
saveddata_engine.execute("UPDATE fits SET ignoreRestrictions = 0")
15 changes: 10 additions & 5 deletions eos/db/saveddata/cargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
# ===============================================================================

from sqlalchemy import Table, Column, Integer, ForeignKey, DateTime
from sqlalchemy.orm import mapper
import sqlalchemy.sql.functions as func
from sqlalchemy.orm import mapper, relation
import datetime

from eos.db import saveddata_meta
from eos.saveddata.cargo import Cargo
from eos.saveddata.fit import Fit

cargo_table = Table("cargo", saveddata_meta,
Column("ID", Integer, primary_key=True),
Column("fitID", Integer, ForeignKey("fits.ID"), nullable=False, index=True),
Column("itemID", Integer, nullable=False),
Column("amount", Integer, nullable=False),
Column("created", DateTime, nullable=True, default=func.now()),
Column("modified", DateTime, nullable=True, onupdate=func.now()),
Column("created", DateTime, nullable=True, default=datetime.datetime.now),
Column("modified", DateTime, nullable=True, onupdate=datetime.datetime.now),
)

mapper(Cargo, cargo_table)
mapper(Cargo, cargo_table,
properties={
"owner": relation(Fit)
}
)
10 changes: 6 additions & 4 deletions eos/db/saveddata/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# along with eos. If not, see <http://www.gnu.org/licenses/>.
# ===============================================================================

from sqlalchemy import Table, Column, Integer, ForeignKey, String, DateTime
from sqlalchemy import Table, Column, Integer, ForeignKey, String, DateTime, Float
from sqlalchemy.orm import relation, mapper
import sqlalchemy.sql.functions as func
import datetime

from eos.db import saveddata_meta
from eos.db.saveddata.implant import charImplants_table
Expand All @@ -38,13 +38,15 @@
Column("defaultLevel", Integer, nullable=True),
Column("alphaCloneID", Integer, nullable=True),
Column("ownerID", ForeignKey("users.ID"), nullable=True),
Column("created", DateTime, nullable=True, default=func.now()),
Column("modified", DateTime, nullable=True, onupdate=func.now()))
Column("secStatus", Float, nullable=True, default=0.0),
Column("created", DateTime, nullable=True, default=datetime.datetime.now),
Column("modified", DateTime, nullable=True, onupdate=datetime.datetime.now))

mapper(Character, characters_table,
properties={
"_Character__alphaCloneID": characters_table.c.alphaCloneID,
"savedName" : characters_table.c.name,
"_Character__secStatus": characters_table.c.secStatus,
"_Character__owner" : relation(
User,
backref="characters"),
Expand Down
4 changes: 2 additions & 2 deletions eos/db/saveddata/crest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from sqlalchemy import Table, Column, Integer, String, DateTime
from sqlalchemy.orm import mapper
import sqlalchemy.sql.functions as func
import datetime

from eos.db import saveddata_meta
from eos.saveddata.crestchar import CrestChar
Expand All @@ -29,6 +29,6 @@
Column("name", String, nullable=False, unique=True),
Column("refresh_token", String, nullable=False),
# These records aren't updated. Instead, they are dropped and created, hence we don't have a modified field
Column("created", DateTime, nullable=True, default=func.now()))
Column("created", DateTime, nullable=True, default=datetime.datetime.now))

mapper(CrestChar, crest_table)
6 changes: 3 additions & 3 deletions eos/db/saveddata/damagePattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from sqlalchemy import Table, Column, Integer, ForeignKey, String, DateTime
from sqlalchemy.orm import mapper
import sqlalchemy.sql.functions as func
import datetime

from eos.db import saveddata_meta
from eos.saveddata.damagePattern import DamagePattern
Expand All @@ -32,8 +32,8 @@
Column("kineticAmount", Integer),
Column("explosiveAmount", Integer),
Column("ownerID", ForeignKey("users.ID"), nullable=True),
Column("created", DateTime, nullable=True, default=func.now()),
Column("modified", DateTime, nullable=True, onupdate=func.now())
Column("created", DateTime, nullable=True, default=datetime.datetime.now),
Column("modified", DateTime, nullable=True, onupdate=datetime.datetime.now)
)

mapper(DamagePattern, damagePatterns_table)
15 changes: 10 additions & 5 deletions eos/db/saveddata/drone.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
# ===============================================================================

from sqlalchemy import Table, Column, Integer, ForeignKey, Boolean, DateTime
from sqlalchemy.orm import mapper
import sqlalchemy.sql.functions as func
from sqlalchemy.orm import mapper, relation
import datetime

from eos.db import saveddata_meta
from eos.saveddata.drone import Drone
from eos.saveddata.fit import Fit

drones_table = Table("drones", saveddata_meta,
Column("groupID", Integer, primary_key=True),
Expand All @@ -31,8 +32,12 @@
Column("amount", Integer, nullable=False),
Column("amountActive", Integer, nullable=False),
Column("projected", Boolean, default=False),
Column("created", DateTime, nullable=True, default=func.now()),
Column("modified", DateTime, nullable=True, onupdate=func.now())
Column("created", DateTime, nullable=True, default=datetime.datetime.now),
Column("modified", DateTime, nullable=True, onupdate=datetime.datetime.now)
)

mapper(Drone, drones_table)
mapper(Drone, drones_table,
properties={
"owner": relation(Fit)
}
)
6 changes: 3 additions & 3 deletions eos/db/saveddata/fighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from sqlalchemy import Table, Column, Integer, ForeignKey, Boolean, DateTime
from sqlalchemy.orm import mapper, relation
import sqlalchemy.sql.functions as func
import datetime

from eos.db import saveddata_meta
from eos.saveddata.fighterAbility import FighterAbility
Expand All @@ -33,8 +33,8 @@
Column("active", Boolean, nullable=True),
Column("amount", Integer, nullable=False),
Column("projected", Boolean, default=False),
Column("created", DateTime, nullable=True, default=func.now()),
Column("modified", DateTime, nullable=True, onupdate=func.now())
Column("created", DateTime, nullable=True, default=datetime.datetime.now),
Column("modified", DateTime, nullable=True, onupdate=datetime.datetime.now)
)

fighter_abilities_table = Table("fightersAbilities", saveddata_meta,
Expand Down
Loading

0 comments on commit 18c7bb9

Please sign in to comment.